Skip to content

Commit 35f7186

Browse files
committed
Install stable latest phpstan. Be strict about input values
1 parent 1c161c3 commit 35f7186

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"require-dev": {
2626
"phpunit/phpunit": "^8.4.1",
2727
"mouf/picotainer": "^1.1",
28-
"phpstan/phpstan": "^0.12.99",
28+
"phpstan/phpstan": "^1.8.2",
2929
"php-coveralls/php-coveralls": "^2.1.0",
3030
"symfony/translation": "^4",
3131
"doctrine/coding-standard": "^9.0"

src/Annotations/Assertion.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
use Symfony\Component\Validator\Constraint;
99
use TheCodingMachine\GraphQLite\Annotations\ParameterAnnotationInterface;
1010

11+
use function assert;
1112
use function is_array;
13+
use function is_string;
1214
use function ltrim;
1315

1416
/**
@@ -41,8 +43,22 @@ public function __construct(array $values)
4143
throw new BadMethodCallException('The @Assert annotation must be passed one or many constraints. For instance: "@Assert(for="$email", constraint=@Email)"');
4244
}
4345

44-
$this->for = ltrim($values['for'], '$');
45-
$this->constraint = is_array($values['constraint']) ? $values['constraint'] : [$values['constraint']];
46+
assert(is_string($values['for']));
47+
$for = ltrim($values['for'], '$');
48+
49+
$constraints = [];
50+
if (is_array($values['constraint'])) {
51+
foreach ($values['constraint'] as $constraint) {
52+
assert($constraint instanceof Constraint);
53+
$constraints[] = $constraint;
54+
}
55+
} else {
56+
assert($values['constraint'] instanceof Constraint);
57+
$constraints = [$values['constraint']];
58+
}
59+
60+
$this->for = $for;
61+
$this->constraint = $constraints;
4662
}
4763

4864
public function getTarget(): string

0 commit comments

Comments
 (0)