Skip to content

Commit 91a17cd

Browse files
committed
improved phpDoc
1 parent 4e56941 commit 91a17cd

6 files changed

Lines changed: 18 additions & 5 deletions

File tree

src/Schema/Context.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public function addError(string $message, string $code, array $variables = []):
4141
}
4242

4343

44+
/**
45+
* @param string[] $variables
46+
*/
4447
public function addWarning(string $message, string $code, array $variables = []): Message
4548
{
4649
return $this->warnings[] = new Message($message, $code, $this->path, $variables);

src/Schema/Elements/Base.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ trait Base
2323
private bool $required = false;
2424
private mixed $default = null;
2525

26-
/** @var ?callable */
27-
private $before;
26+
/** @var ?\Closure(mixed): mixed */
27+
private ?\Closure $before = null;
2828

29-
/** @var callable[] */
29+
/** @var array<\Closure(mixed, Context): mixed> */
3030
private array $transforms = [];
3131
private ?string $deprecated = null;
3232

@@ -45,9 +45,10 @@ public function required(bool $state = true): self
4545
}
4646

4747

48+
/** @param callable(mixed): mixed $handler */
4849
public function before(callable $handler): self
4950
{
50-
$this->before = $handler;
51+
$this->before = $handler(...);
5152
return $this;
5253
}
5354

@@ -58,16 +59,19 @@ public function castTo(string $type): self
5859
}
5960

6061

62+
/** @param callable(mixed, Context): mixed $handler */
6163
public function transform(callable $handler): self
6264
{
63-
$this->transforms[] = $handler;
65+
$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));
74+
$handler = $handler(...);
7175
return $this->transform(function ($value, Context $context) use ($handler, $description, $expected) {
7276
if ($handler($value)) {
7377
return $value;

src/Schema/Elements/Structure.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public function skipDefaults(bool $state = true): self
7777
}
7878

7979

80+
/** @param Schema[]|self $shape */
8081
public function extend(array|self $shape): self
8182
{
8283
$shape = $shape instanceof self ? $shape->items : $shape;

src/Schema/Expect.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public static function structure(array $shape): Structure
6464
}
6565

6666

67+
/** @param array<string, Schema> $items */
6768
public static function from(object $object, array $items = []): Structure
6869
{
6970
$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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
final class Processor
1919
{
20+
/** @var array<callable(Context): void> */
2021
public array $onNewContext = [];
2122
private Context $context;
2223
private bool $skipDefaults = false;

0 commit comments

Comments
 (0)