Skip to content

Commit 383c7a0

Browse files
committed
improved phpDoc
1 parent 3ef3bd7 commit 383c7a0

9 files changed

Lines changed: 29 additions & 17 deletions

File tree

src/Schema/Context.php

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

19-
/** @var string[] */
19+
/** @var list<int|string> */
2020
public array $path = [];
2121

2222
public bool $isKey = false;
2323

24-
/** @var Message[] */
24+
/** @var list<Message> */
2525
public array $errors = [];
2626

27-
/** @var Message[] */
27+
/** @var list<Message> */
2828
public array $warnings = [];
2929

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

3333

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

4041

42+
/** @param array<string, mixed> $variables */
4143
public function addWarning(string $message, string $code, array $variables = []): Message
4244
{
4345
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
@@ -20,6 +20,7 @@ final class AnyOf implements Schema
2020
{
2121
use Base;
2222

23+
/** @var mixed[] */
2324
private array $set;
2425

2526

src/Schema/Elements/Base.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function required(bool $state = true): self
4545
}
4646

4747

48+
/** @param callable(mixed): mixed $handler */
4849
public function before(callable $handler): self
4950
{
5051
$this->before = $handler(...);
@@ -58,13 +59,15 @@ public function castTo(string $type): self
5859
}
5960

6061

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

6769

70+
/** @param callable(mixed): bool $handler */
6871
public function assert(callable $handler, ?string $description = null): self
6972
{
7073
$expected = $description ?: (is_string($handler) ? "$handler()" : '#' . count($this->transforms));
@@ -146,7 +149,10 @@ private function doValidate(mixed $value, string $expected, Context $context): b
146149
}
147150

148151

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

src/Schema/Elements/Structure.php

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

3333

34-
/**
35-
* @param Schema[] $shape
36-
*/
34+
/** @param Schema[] $shape */
3735
public function __construct(array $shape)
3836
{
3937
(function (Schema ...$items) {})(...array_values($shape));
@@ -77,13 +75,15 @@ public function skipDefaults(bool $state = true): self
7775
}
7876

7977

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

8685

86+
/** @return Schema[] */
8787
public function getShape(): array
8888
{
8989
return $this->items;
@@ -167,6 +167,7 @@ public function complete(mixed $value, Context $context): mixed
167167
}
168168

169169

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

src/Schema/Elements/Type.php

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

191191

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

src/Schema/Expect.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
*/
3333
final class Expect
3434
{
35+
/** @param array<mixed> $args */
3536
public static function __callStatic(string $name, array $args): Type
3637
{
3738
$type = new Type($name);
@@ -55,15 +56,14 @@ public static function anyOf(mixed ...$set): AnyOf
5556
}
5657

5758

58-
/**
59-
* @param Schema[] $shape
60-
*/
59+
/** @param Schema[] $shape */
6160
public static function structure(array $shape): Structure
6261
{
6362
return new Structure($shape);
6463
}
6564

6665

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

src/Schema/Helpers.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public static function validateType(mixed $value, string $expected, Context $con
121121
}
122122

123123

124+
/** @param array{?float, ?float} $range */
124125
public static function validateRange(mixed $value, array $range, Context $context, string $types = ''): void
125126
{
126127
if (is_array($value) || is_string($value)) {
@@ -147,6 +148,7 @@ public static function validateRange(mixed $value, array $range, Context $contex
147148
}
148149

149150

151+
/** @param array{?float, ?float} $range */
150152
public static function isInRange(mixed $value, array $range): bool
151153
{
152154
return ($range[0] === null || $value >= $range[0])
@@ -166,6 +168,7 @@ public static function validatePattern(string $value, string $pattern, Context $
166168
}
167169

168170

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

src/Schema/Processor.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
final class Processor
1919
{
20+
/** @var list<\Closure(Context): void> */
2021
public array $onNewContext = [];
2122
private Context $context;
2223
private bool $skipDefaults = false;
@@ -45,6 +46,7 @@ public function process(Schema $schema, mixed $data): mixed
4546

4647
/**
4748
* Normalizes and validates and merges multiple data. Result is a clean completed data.
49+
* @param array<mixed> $dataset
4850
* @throws ValidationException
4951
*/
5052
public function processMultiple(Schema $schema, array $dataset): mixed

src/Schema/ValidationException.php

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

3333

34-
/**
35-
* @return string[]
36-
*/
34+
/** @return list<string> */
3735
public function getMessages(): array
3836
{
3937
$res = [];
@@ -45,9 +43,7 @@ public function getMessages(): array
4543
}
4644

4745

48-
/**
49-
* @return Message[]
50-
*/
46+
/** @return list<Message> */
5147
public function getMessageObjects(): array
5248
{
5349
return $this->messages;

0 commit comments

Comments
 (0)