Skip to content

Commit 63179c5

Browse files
committed
cs
1 parent 367d3c5 commit 63179c5

9 files changed

Lines changed: 27 additions & 57 deletions

File tree

src/Schema/Elements/Base.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function transform(callable $handler): self
6868
/** @param callable(mixed): bool $handler */
6969
public function assert(callable $handler, ?string $description = null): self
7070
{
71-
$expected = $description ?: (is_string($handler) ? "$handler()" : '#' . count($this->transforms));
71+
$expected = $description ?? (is_string($handler) ? "$handler()" : '#' . count($this->transforms));
7272
return $this->transform(function ($value, Context $context) use ($handler, $description, $expected) {
7373
if ($handler($value)) {
7474
return $value;

src/Schema/Elements/Structure.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Nette\Schema\Context;
1212
use Nette\Schema\Helpers;
1313
use Nette\Schema\Schema;
14-
use function array_diff_key, array_fill_keys, array_key_exists, array_keys, array_map, array_merge, array_pop, array_values, is_array, is_object;
14+
use function array_diff_key, array_fill_keys, array_key_exists, array_keys, array_map, array_merge, array_pop, array_values, is_array, is_object, strval;
1515

1616

1717
final class Structure implements Schema
@@ -173,7 +173,7 @@ private function validateItems(array &$value, Context $context): void
173173
if ($this->otherItems) {
174174
$items += array_fill_keys($extraKeys, $this->otherItems);
175175
} else {
176-
$keys = array_map('strval', array_keys($items));
176+
$keys = array_map(strval(...), array_keys($items));
177177
foreach ($extraKeys as $key) {
178178
$hint = Nette\Utils\Helpers::getSuggestion($keys, (string) $key);
179179
$context->addError(

src/Schema/Helpers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public static function getPropertyType(\ReflectionProperty|\ReflectionParameter
7474
* Returns an annotation value.
7575
* @param \ReflectionClass<object>|\ReflectionProperty $ref
7676
*/
77-
public static function parseAnnotation(\Reflector $ref, string $name): ?string
77+
public static function parseAnnotation(\ReflectionClass|\ReflectionProperty $ref, string $name): ?string
7878
{
7979
if (!Reflection::areCommentsAvailable()) {
8080
throw new Nette\InvalidStateException('You have to enable phpDoc comments in opcode cache.');
@@ -125,7 +125,7 @@ public static function validateRange(mixed $value, array $range, Context $contex
125125
if (is_array($value) || is_string($value)) {
126126
[$length, $label] = is_array($value)
127127
? [count($value), 'items']
128-
: (in_array('unicode', explode('|', $types), true)
128+
: (in_array('unicode', explode('|', $types), strict: true)
129129
? [Nette\Utils\Strings::length($value), 'characters']
130130
: [strlen($value), 'bytes']);
131131

src/Schema/Message.php

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace Nette\Schema;
99

1010
use Nette;
11-
use function implode, preg_last_error_msg, preg_replace_callback;
11+
use function implode, preg_replace_callback;
1212

1313

1414
final class Message
@@ -61,22 +61,15 @@ final class Message
6161
/** @deprecated use Message::Deprecated */
6262
public const DEPRECATED = self::Deprecated;
6363

64-
public string $message;
65-
public string $code;
6664

67-
/** @var string[] */
68-
public array $path;
69-
70-
/** @var string[] */
71-
public array $variables;
72-
73-
74-
public function __construct(string $message, string $code, array $path, array $variables = [])
75-
{
76-
$this->message = $message;
77-
$this->code = $code;
78-
$this->path = $path;
79-
$this->variables = $variables;
65+
public function __construct(
66+
public string $message,
67+
public string $code,
68+
/** @var list<int|string> */
69+
public array $path,
70+
/** @var array<string, mixed> */
71+
public array $variables = [],
72+
) {
8073
}
8174

8275

src/Schema/ValidationException.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,12 @@
1515
*/
1616
class ValidationException extends Nette\InvalidStateException
1717
{
18-
/** @var Message[] */
19-
private array $messages;
20-
21-
22-
/**
23-
* @param Message[] $messages
24-
*/
25-
public function __construct(?string $message, array $messages = [])
26-
{
27-
parent::__construct($message ?: $messages[0]->toString());
28-
$this->messages = $messages;
18+
public function __construct(
19+
?string $message,
20+
/** @var list<Message> */
21+
private array $messages = [],
22+
) {
23+
parent::__construct($message ?? $messages[0]->toString());
2924
}
3025

3126

tests/Schema/Expect.array.phpt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -308,13 +308,6 @@ test('arrayOf() & keys II.', function () {
308308
});
309309

310310

311-
testException(
312-
'arrayOf() error',
313-
fn() => Expect::arrayOf(['a' => Expect::string()]),
314-
TypeError::class,
315-
);
316-
317-
318311
test('type[]', function () {
319312
$schema = Expect::type('int[]');
320313

tests/Schema/Expect.castTo.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ test('built-in', function () {
2020
test('simple object', function () {
2121
class Foo1
2222
{
23-
public $a;
24-
public $b;
23+
public mixed $a;
24+
public mixed $b;
2525
}
2626

2727
$foo = new Foo1;
@@ -39,8 +39,8 @@ test('simple object', function () {
3939
test('object with constructor', function () {
4040
class Foo2
4141
{
42-
private $a;
43-
private $b;
42+
private int $a;
43+
private int $b;
4444

4545

4646
public function __construct(int $a, int $b)

tests/Schema/Expect.dynamic.phpt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,9 @@ require __DIR__ . '/../bootstrap.php';
1010

1111
class DynamicParameter implements Nette\Schema\DynamicParameter
1212
{
13-
/** @var string */
14-
private $value;
15-
16-
17-
public function __construct(string $value)
18-
{
19-
$this->value = $value;
13+
public function __construct(
14+
private string $value,
15+
) {
2016
}
2117
}
2218

tests/Schema/Expect.list.phpt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,3 @@ test('listOf() & scalar', function () {
9595
(new Processor)->process($schema, ['key' => 'val']);
9696
}, ['The item expects to be list, array given.']);
9797
});
98-
99-
100-
testException(
101-
'listOf() & error',
102-
fn() => Expect::listOf(['a' => Expect::string()]),
103-
TypeError::class,
104-
);

0 commit comments

Comments
 (0)