Skip to content

Commit 7518c14

Browse files
#234: Fixed PHPStan issues
1 parent c059854 commit 7518c14

13 files changed

+57
-39
lines changed

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
"symfony/validator": "6.0.*"
1515
},
1616
"require-dev": {
17-
"phpstan/phpstan": "^1.11",
17+
"phpstan/phpstan": "^1.11",
18+
"phpstan/phpstan-phpunit": "^1.4",
19+
"phpstan/phpstan-symfony": "^1.4",
1820
"phpunit/phpunit": "^9.5",
1921
"rector/rector": "^1.1"
2022
},

phpstan.neon

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
includes:
2+
- 'vendor/phpstan/phpstan-phpunit/extension.neon'
3+
- 'vendor/phpstan/phpstan-symfony/extension.neon'
4+
15
parameters:
2-
level: 1
6+
level: 8
7+
38
paths:
4-
- src
5-
- tests
9+
- 'src'
10+
- 'tests'

rector.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@
1616
SymfonySetList::SYMFONY_60,
1717
])
1818
->withImportNames(
19-
importDocBlockNames: false,
2019
importShortClasses: false,
2120
);

src/Bsn.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
use Symfony\Component\Validator\Constraint;
2626

2727
/**
28-
* BSN constraint.
29-
*
3028
* @Annotation
3129
*
3230
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})

src/BsnValidator.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@
4646
class BsnValidator extends ConstraintValidator
4747
{
4848
/**
49-
* Checks if the value is valid.
50-
*
51-
* @throws \Symfony\Component\Validator\Exception\UnexpectedTypeException
49+
* @throws UnexpectedTypeException
5250
*/
5351
public function validate(mixed $value, Constraint $constraint): void
5452
{
@@ -67,7 +65,7 @@ public function validate(mixed $value, Constraint $constraint): void
6765
$value = (string) $value;
6866

6967
if ('000000000' !== $value && preg_match('/^\d{9}$/', $value)) {
70-
[$a, $b, $c, $d, $e, $f, $g, $h, $i] = str_split($value);
68+
[$a, $b, $c, $d, $e, $f, $g, $h, $i] = array_map('intval', str_split($value));
7169

7270
$sum = (9 * $a) + (8 * $b) + (7 * $c) + (6 * $d) + (5 * $e) + (4 * $f) + (3 * $g) + (2 * $h) + (-1 * $i);
7371

src/Collection.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
2828

2929
/**
30-
* Collection constraint.
31-
*
3230
* @Annotation
3331
*
3432
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
@@ -39,12 +37,9 @@
3937
*/
4038
class Collection extends Constraint
4139
{
42-
/** @var \Symfony\Component\Validator\Constraint[] */
40+
/** @var Constraint[] */
4341
public array $constraints;
4442

45-
/**
46-
* Constructor.
47-
*/
4843
public function __construct(mixed $options = null)
4944
{
5045
parent::__construct($options);
@@ -68,17 +63,11 @@ public function __construct(mixed $options = null)
6863
}
6964
}
7065

71-
/**
72-
* Returns the name of the default option.
73-
*/
7466
public function getDefaultOption(): string
7567
{
7668
return 'constraints';
7769
}
7870

79-
/**
80-
* Returns the name of the required options.
81-
*/
8271
public function getRequiredOptions(): array
8372
{
8473
return ['constraints'];

src/CollectionValidator.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,14 @@
2727
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
2828

2929
/**
30-
* Collection validator.
31-
*
3230
* @author Raymond Schouten
3331
*
3432
* @since 2.3
3533
*/
3634
class CollectionValidator extends ConstraintValidator
3735
{
3836
/**
39-
* Checks if the value is valid.
40-
*
41-
* @throws \Symfony\Component\Validator\Exception\UnexpectedTypeException
37+
* @throws UnexpectedTypeException
4238
*/
4339
public function validate(mixed $value, Constraint $constraint): void
4440
{

src/Json.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
use Symfony\Component\Validator\Constraint;
2626

2727
/**
28-
* JSON constraint.
29-
*
3028
* @Annotation
3129
*
3230
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})

src/JsonValidator.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,14 @@
2525
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
2626

2727
/**
28-
* JSON validator.
29-
*
3028
* @author Raymond Schouten
3129
*
3230
* @since 2.3
3331
*/
3432
class JsonValidator extends ConstraintValidator
3533
{
3634
/**
37-
* Checks if the value is valid.
38-
*
39-
* @throws \Symfony\Component\Validator\Exception\UnexpectedTypeException
35+
* @throws UnexpectedTypeException
4036
*/
4137
public function validate(mixed $value, Constraint $constraint): void
4238
{
@@ -52,7 +48,7 @@ public function validate(mixed $value, Constraint $constraint): void
5248
throw new UnexpectedTypeException($value, 'string');
5349
}
5450

55-
if (json_decode($value) || json_last_error() === JSON_ERROR_NONE) {
51+
if (json_decode((string) $value) || json_last_error() === JSON_ERROR_NONE) {
5652
return;
5753
}
5854

tests/BsnValidatorTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected function createValidator(): BsnValidator
4242
/**
4343
* @dataProvider providerValidBsn
4444
*/
45-
public function testValidate(mixed $value): void
45+
public function testValidate(string|\Stringable $value): void
4646
{
4747
$this->validator->validate($value, new Bsn());
4848

@@ -87,7 +87,7 @@ public function testValidateNoScalar(mixed $value): void
8787
/**
8888
* @dataProvider providerInvalidBsn
8989
*/
90-
public function testValidateViolation(mixed $value): void
90+
public function testValidateViolation(string|\Stringable $value): void
9191
{
9292
$constraint = new Bsn();
9393

@@ -98,6 +98,9 @@ public function testValidateViolation(mixed $value): void
9898
->assertRaised();
9999
}
100100

101+
/**
102+
* @return array<string, array{string|\Stringable}>
103+
*/
101104
public function providerValidBsn(): array
102105
{
103106
return [
@@ -107,6 +110,9 @@ public function providerValidBsn(): array
107110
];
108111
}
109112

113+
/**
114+
* @return array<string, array{mixed}>
115+
*/
110116
public function providerNoScalar(): array
111117
{
112118
return [
@@ -117,6 +123,9 @@ public function providerNoScalar(): array
117123
];
118124
}
119125

126+
/**
127+
* @return array<string, array{string|\Stringable}>
128+
*/
120129
public function providerInvalidBsn(): array
121130
{
122131
return [

0 commit comments

Comments
 (0)