Skip to content

Commit 8e42f2b

Browse files
committed
fixed PHPStan errors
1 parent b613d62 commit 8e42f2b

4 files changed

Lines changed: 15 additions & 11 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"require-dev": {
2222
"nette/tester": "^2.6",
2323
"tracy/tracy": "^2.8",
24-
"phpstan/phpstan-nette": "^2.0@stable"
24+
"phpstan/phpstan": "^2.0@stable"
2525
},
2626
"autoload": {
2727
"classmap": ["src/"],

phpstan.neon

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
parameters:
22
level: 8
3-
checkMissingIterableValueType: false
4-
errorFormat: raw
53

64
paths:
75
- src
86

9-
includes:
10-
- vendor/phpstan/phpstan-nette/extension.neon
7+
checkMissingCallableSignature: true
8+
9+
ignoreErrors:
10+
- # Runtime type validation that all $shape items are Schema instances
11+
identifier: expr.resultUnused
12+
path: src/Schema/Elements/Structure.php

src/Schema/Expect.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ public static function from(object $object, array $items = []): Structure
7272
: $ro->getProperties();
7373

7474
foreach ($props as $prop) {
75-
$item = &$items[$prop->getName()];
76-
if (!$item) {
75+
$name = $prop->getName();
76+
if (!isset($items[$name])) {
7777
$type = Helpers::getPropertyType($prop) ?? 'mixed';
7878
$item = new Type($type);
7979
if ($prop instanceof \ReflectionProperty ? $prop->isInitialized($object) : $prop->isOptional()) {
@@ -88,6 +88,7 @@ public static function from(object $object, array $items = []): Structure
8888
} else {
8989
$item->required();
9090
}
91+
$items[$name] = $item;
9192
}
9293
}
9394

@@ -100,7 +101,8 @@ public static function from(object $object, array $items = []): Structure
100101
*/
101102
public static function array(?array $shape = []): Structure|Type
102103
{
103-
return Nette\Utils\Arrays::first($shape ?? []) instanceof Schema
104+
$shape ??= [];
105+
return Nette\Utils\Arrays::first($shape) instanceof Schema
104106
? (new Structure($shape))->castTo('array')
105107
: (new Type('array'))->default($shape);
106108
}

src/Schema/Processor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
namespace Nette\Schema;
1111

12-
use Nette;
13-
1412

1513
/**
1614
* Schema validator.
@@ -93,6 +91,8 @@ private function createContext(): void
9391
{
9492
$this->context = new Context;
9593
$this->context->skipDefaults = $this->skipDefaults;
96-
Nette\Utils\Arrays::invoke($this->onNewContext, $this->context);
94+
foreach ($this->onNewContext as $cb) {
95+
$cb($this->context);
96+
}
9797
}
9898
}

0 commit comments

Comments
 (0)