Skip to content

Commit 367d3c5

Browse files
committed
improved phpDoc
1 parent 9a8a926 commit 367d3c5

9 files changed

Lines changed: 32 additions & 22 deletions

File tree

src/Schema/Context.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,30 @@ final class Context
1414
{
1515
public bool $skipDefaults = false;
1616

17-
/** @var string[] */
17+
/** @var list<int|string> */
1818
public array $path = [];
1919

2020
public bool $isKey = false;
2121

22-
/** @var Message[] */
22+
/** @var list<Message> */
2323
public array $errors = [];
2424

25-
/** @var Message[] */
25+
/** @var list<Message> */
2626
public array $warnings = [];
2727

28-
/** @var array[] */
28+
/** @var list<array{DynamicParameter, string, list<int|string>}> */
2929
public array $dynamics = [];
3030

3131

32+
/** @param array<string, mixed> $variables */
3233
public function addError(string $message, string $code, array $variables = []): Message
3334
{
3435
$variables['isKey'] = $this->isKey;
3536
return $this->errors[] = new Message($message, $code, $this->path, $variables);
3637
}
3738

3839

40+
/** @param array<string, mixed> $variables */
3941
public function addWarning(string $message, string $code, array $variables = []): Message
4042
{
4143
return $this->warnings[] = new Message($message, $code, $this->path, $variables);

src/Schema/Elements/AnyOf.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ final class AnyOf implements Schema
1818
{
1919
use Base;
2020

21+
/** @var mixed[] */
2122
private array $set;
2223

2324

src/Schema/Elements/Base.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ trait Base
2424
/** @var ?\Closure(mixed): mixed */
2525
private ?\Closure $before = null;
2626

27-
/** @var array<\Closure(mixed, Context): mixed> */
27+
/** @var list<\Closure(mixed, Context): mixed> */
2828
private array $transforms = [];
2929
private ?string $deprecated = null;
3030

@@ -43,6 +43,7 @@ public function required(bool $state = true): self
4343
}
4444

4545

46+
/** @param callable(mixed): mixed $handler */
4647
public function before(callable $handler): self
4748
{
4849
$this->before = $handler(...);
@@ -56,13 +57,15 @@ public function castTo(string $type): self
5657
}
5758

5859

60+
/** @param callable(mixed, Context): mixed $handler */
5961
public function transform(callable $handler): self
6062
{
6163
$this->transforms[] = $handler(...);
6264
return $this;
6365
}
6466

6567

68+
/** @param callable(mixed): bool $handler */
6669
public function assert(callable $handler, ?string $description = null): self
6770
{
6871
$expected = $description ?: (is_string($handler) ? "$handler()" : '#' . count($this->transforms));
@@ -144,7 +147,10 @@ private function doValidate(mixed $value, string $expected, Context $context): b
144147
}
145148

146149

147-
/** @deprecated use Nette\Schema\Validators::validateRange() */
150+
/**
151+
* @deprecated use Nette\Schema\Validators::validateRange()
152+
* @param array{?float, ?float} $range
153+
*/
148154
private static function doValidateRange(mixed $value, array $range, Context $context, string $types = ''): bool
149155
{
150156
$isOk = $context->createChecker();

src/Schema/Elements/Structure.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ final class Structure implements Schema
2929
private bool $skipDefaults = false;
3030

3131

32-
/**
33-
* @param Schema[] $shape
34-
*/
32+
/** @param Schema[] $shape */
3533
public function __construct(array $shape)
3634
{
3735
(function (Schema ...$items) {})(...array_values($shape));
@@ -75,13 +73,15 @@ public function skipDefaults(bool $state = true): self
7573
}
7674

7775

76+
/** @param Schema[]|self $shape */
7877
public function extend(array|self $shape): self
7978
{
8079
$shape = $shape instanceof self ? $shape->items : $shape;
8180
return new self(array_merge($this->items, $shape));
8281
}
8382

8483

84+
/** @return Schema[] */
8585
public function getShape(): array
8686
{
8787
return $this->items;
@@ -165,6 +165,7 @@ public function complete(mixed $value, Context $context): mixed
165165
}
166166

167167

168+
/** @param array<mixed> $value */
168169
private function validateItems(array &$value, Context $context): void
169170
{
170171
$items = $this->items;

src/Schema/Elements/Type.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ public function complete(mixed $value, Context $context): mixed
187187
}
188188

189189

190+
/** @param array<mixed> $value */
190191
private function validateItems(array &$value, Context $context): void
191192
{
192193
if (!$this->itemsValue) {

src/Schema/Expect.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
*/
3131
final class Expect
3232
{
33+
/** @param list<mixed> $args */
3334
public static function __callStatic(string $name, array $args): Type
3435
{
3536
$type = new Type($name);
@@ -53,15 +54,14 @@ public static function anyOf(mixed ...$set): AnyOf
5354
}
5455

5556

56-
/**
57-
* @param Schema[] $shape
58-
*/
57+
/** @param Schema[] $shape */
5958
public static function structure(array $shape): Structure
6059
{
6160
return new Structure($shape);
6261
}
6362

6463

64+
/** @param array<string, Schema> $items */
6565
public static function from(object $object, array $items = []): Structure
6666
{
6767
$ro = new \ReflectionObject($object);

src/Schema/Helpers.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static function getPropertyType(\ReflectionProperty|\ReflectionParameter
7272

7373
/**
7474
* Returns an annotation value.
75-
* @param \ReflectionProperty $ref
75+
* @param \ReflectionClass<object>|\ReflectionProperty $ref
7676
*/
7777
public static function parseAnnotation(\Reflector $ref, string $name): ?string
7878
{
@@ -119,6 +119,7 @@ public static function validateType(mixed $value, string $expected, Context $con
119119
}
120120

121121

122+
/** @param array{?float, ?float} $range */
122123
public static function validateRange(mixed $value, array $range, Context $context, string $types = ''): void
123124
{
124125
if (is_array($value) || is_string($value)) {
@@ -145,6 +146,7 @@ public static function validateRange(mixed $value, array $range, Context $contex
145146
}
146147

147148

149+
/** @param array{?float, ?float} $range */
148150
public static function isInRange(mixed $value, array $range): bool
149151
{
150152
return ($range[0] === null || $value >= $range[0])
@@ -164,6 +166,7 @@ public static function validatePattern(string $value, string $pattern, Context $
164166
}
165167

166168

169+
/** @return \Closure(mixed): mixed */
167170
public static function getCastStrategy(string $type): \Closure
168171
{
169172
if (Nette\Utils\Validators::isBuiltinType($type)) {

src/Schema/Processor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
final class Processor
1717
{
18+
/** @var list<\Closure(Context): void> */
1819
public array $onNewContext = [];
1920
private Context $context;
2021
private bool $skipDefaults = false;
@@ -43,6 +44,7 @@ public function process(Schema $schema, mixed $data): mixed
4344

4445
/**
4546
* Normalizes and validates and merges multiple data. Result is a clean completed data.
47+
* @param list<mixed> $dataset
4648
* @throws ValidationException
4749
*/
4850
public function processMultiple(Schema $schema, array $dataset): mixed
@@ -63,9 +65,7 @@ public function processMultiple(Schema $schema, array $dataset): mixed
6365
}
6466

6567

66-
/**
67-
* @return string[]
68-
*/
68+
/** @return list<string> */
6969
public function getWarnings(): array
7070
{
7171
$res = [];

src/Schema/ValidationException.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ public function __construct(?string $message, array $messages = [])
2929
}
3030

3131

32-
/**
33-
* @return string[]
34-
*/
32+
/** @return list<string> */
3533
public function getMessages(): array
3634
{
3735
$res = [];
@@ -43,9 +41,7 @@ public function getMessages(): array
4341
}
4442

4543

46-
/**
47-
* @return Message[]
48-
*/
44+
/** @return list<Message> */
4945
public function getMessageObjects(): array
5046
{
5147
return $this->messages;

0 commit comments

Comments
 (0)