Skip to content

Commit 0e28ec0

Browse files
🐛 Fix and reorganize tests
1 parent e56dc85 commit 0e28ec0

File tree

4 files changed

+120
-79
lines changed

4 files changed

+120
-79
lines changed

SymfonyCustom/Sniffs/NamingConventions/ValidTypeHintSniff.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ private function getValidTypes(string $content): string
161161
$validType = $this->getValidGenericType($matches['genericName'], $matches['genericContent']);
162162
} elseif (isset($matches['object']) && '' !== $matches['object']) {
163163
$validType = $this->getValidObjectType($matches['objectContent']);
164+
} elseif (isset($matches['array']) && '' !== $matches['array']) {
165+
$validType = $this->getValidTypes(substr($matches['array'], 0, -2)).'[]';
164166
} else {
165167
$validType = $this->getValidType($matches['type']);
166168
}
@@ -215,6 +217,8 @@ private function orderTypes(array $types): array
215217
* @param string $genericContent
216218
*
217219
* @return string
220+
*
221+
* @throws DeepExitException
218222
*/
219223
private function getValidGenericType(string $genericName, string $genericContent): string
220224
{
@@ -234,6 +238,8 @@ private function getValidGenericType(string $genericName, string $genericContent
234238
* @param string $objectContent
235239
*
236240
* @return string
241+
*
242+
* @throws DeepExitException
237243
*/
238244
private function getValidObjectType(string $objectContent): string
239245
{
@@ -263,10 +269,6 @@ private function getValidObjectType(string $objectContent): string
263269
*/
264270
private function getValidType(string $typeName): string
265271
{
266-
if ('[]' === substr($typeName, -2)) {
267-
return $this->getValidType(substr($typeName, 0, -2)).'[]';
268-
}
269-
270272
$lowerType = strtolower($typeName);
271273
switch ($lowerType) {
272274
case 'bool':

SymfonyCustom/Tests/NamingConventions/ValidTypeHintUnitTest.inc

Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,72 @@
22

33
// Only PHPDoc comments are checked
44
/* @var boolean $a */
5+
/** @var boolean $a */
56

67
/**
8+
* Check simple type
9+
*
710
* @param boolean $a
8-
* @param Boolean $a
911
* @param integer $b
10-
* @param double $c
11-
* @param real $c
12-
*
13-
* @return boolean
14-
* @return Boolean
15-
* @return integer
16-
* @return double
17-
* @return real
12+
* @param double $c
13+
* @param real $c
1814
*/
1915

20-
/** @var boolean $a */
21-
/** @var Boolean $a */
22-
/** @var integer $b */
23-
/** @var double $c */
24-
/** @var real $c */
25-
26-
/** @method integer|string */
27-
/** @method array<integer,boolean>|integer[]|array<integer> truc */
28-
/** @method array<integer, boolean|null>|integer[]|array<array<integer>> truc */
16+
/**
17+
* Don't care about case
18+
*
19+
* @return BoOlEAn $a
20+
* @return boolean $a
21+
*/
2922

3023
/**
31-
* @return null|int
32-
* @return string[]|null|int[]
33-
* @return Foo<integer|null|string, boolean|null|string>|null|int[]
24+
* Works with different tags
25+
*
26+
* @method integer someFunction()
27+
* @property integer $integer
28+
* @property-read integer $integer
29+
* @property-write integer $integer
30+
* @throws integer
3431
*/
3532

36-
/** @method array < integer , null | boolean > | integer [ ] | array < array < integer > > truc */
37-
/** @method Generator<integer, string, string, boolean> truc */
38-
/** @method Generator<array<integer>, array<integer>, array<integer>, array<integer>> truc */
39-
/** @method array { integer: integer, boolean?: boolean } truc */
40-
/** @param class-string|class-string<Client>|integer truc */
33+
/**
34+
* Union et intersection types
35+
*
36+
* @param integer|(string|boolean)
37+
* @param integer&string|boolean This syntax is not valid
38+
* @param (integer&string)|boolean
39+
* @param (integer|((string|boolean)))
40+
*/
4141

4242
/**
43+
* Array, generic and object types
44+
*
45+
* @param array<integer,boolean>|integer[]|array<integer> foo
46+
* @param Generator<integer, string, string, boolean> bar
47+
* @param Generator<array<integer>, array<integer>, array<integer>, array<integer>> baz
48+
* @param array<integer[][][]>[]|boolean
4349
* @param array{0: integer, 1?: integer}
4450
* @param array{integer, integer}
4551
* @param array{foo: integer, bar: string}
4652
*/
4753

4854
/**
49-
* @param (integer|string)|bool
50-
* @param (integer&string)|bool
51-
* @param integer&string|bool
55+
* Class-string
56+
*
57+
* @param class-string|class-string<Client>|integer
58+
*/
59+
60+
/**
61+
* Handle space (Last one is a comment, correctly not replaced)
62+
*
63+
* @param array < integer , integer | boolean > | integer [ ] | array < array < integer > > integer
64+
* @param array { integer: integer, boolean?: boolean } integer
65+
*/
66+
67+
/**
68+
* null type should be the last one
69+
*
70+
* @param null|int
71+
* @param string[]|null|int[]
72+
* @param Foo<integer|null|string, boolean|null|string>|null|int[]
5273
*/

SymfonyCustom/Tests/NamingConventions/ValidTypeHintUnitTest.inc.fixed

Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,72 @@
22

33
// Only PHPDoc comments are checked
44
/* @var boolean $a */
5+
/** @var bool $a */
56

67
/**
7-
* @param bool $a
8+
* Check simple type
9+
*
810
* @param bool $a
911
* @param int $b
10-
* @param float $c
11-
* @param float $c
12-
*
13-
* @return bool
14-
* @return bool
15-
* @return int
16-
* @return float
17-
* @return float
12+
* @param float $c
13+
* @param float $c
1814
*/
1915

20-
/** @var bool $a */
21-
/** @var bool $a */
22-
/** @var int $b */
23-
/** @var float $c */
24-
/** @var float $c */
25-
26-
/** @method int|string */
27-
/** @method array<int, bool>|int[]|array<int> truc */
28-
/** @method array<int, bool|null>|int[]|array<array<int>> truc */
16+
/**
17+
* Don't care about case
18+
*
19+
* @return bool $a
20+
* @return bool $a
21+
*/
2922

3023
/**
31-
* @return int|null
32-
* @return string[]|int[]|null
33-
* @return Foo<int|string|null, bool|string|null>|int[]|null
24+
* Works with different tags
25+
*
26+
* @method int someFunction()
27+
* @property int $integer
28+
* @property-read int $integer
29+
* @property-write int $integer
30+
* @throws int
3431
*/
3532

36-
/** @method array<int, bool|null>|int[]|array<array<int>> truc */
37-
/** @method Generator<int, string, string, bool> truc */
38-
/** @method Generator<array<int>, array<int>, array<int>, array<int>> truc */
39-
/** @method array{integer: int, boolean?: bool} truc */
40-
/** @param class-string|class-string<Client>|int truc */
33+
/**
34+
* Union et intersection types
35+
*
36+
* @param int|(string|bool)
37+
* @param integer&string|boolean This syntax is not valid
38+
* @param (int&string)|bool
39+
* @param (int|((string|bool)))
40+
*/
4141

4242
/**
43+
* Array, generic and object types
44+
*
45+
* @param array<int, bool>|int[]|array<int> foo
46+
* @param Generator<int, string, string, bool> bar
47+
* @param Generator<array<int>, array<int>, array<int>, array<int>> baz
48+
* @param array<int[][][]>[]|bool
4349
* @param array{0: int, 1?: int}
4450
* @param array{int, int}
4551
* @param array{foo: int, bar: string}
4652
*/
4753

4854
/**
49-
* @param (int|string)|bool
50-
* @param (int&string)|bool
51-
* @param integer&string|bool
55+
* Class-string
56+
*
57+
* @param class-string|class-string<Client>|int
58+
*/
59+
60+
/**
61+
* Handle space (Last one is a comment, correctly not replaced)
62+
*
63+
* @param array<int, int|bool>|int[]|array<array<int>> integer
64+
* @param array{integer: int, boolean?: bool} integer
65+
*/
66+
67+
/**
68+
* null type should be the last one
69+
*
70+
* @param int|null
71+
* @param string[]|int[]|null
72+
* @param Foo<int|string|null, bool|string|null>|int[]|null
5273
*/

SymfonyCustom/Tests/NamingConventions/ValidTypeHintUnitTest.php

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,35 @@ class ValidTypeHintUnitTest extends AbstractSniffUnitTest
1919
protected function getErrorList(): array
2020
{
2121
return [
22-
7 => 1,
23-
8 => 1,
24-
9 => 1,
22+
5 => 1,
2523
10 => 1,
2624
11 => 1,
25+
12 => 1,
2726
13 => 1,
28-
14 => 1,
29-
15 => 1,
30-
16 => 1,
31-
17 => 1,
27+
19 => 1,
3228
20 => 1,
33-
21 => 1,
34-
22 => 1,
35-
23 => 1,
36-
24 => 1,
3729
26 => 1,
3830
27 => 1,
3931
28 => 1,
40-
31 => 1,
41-
32 => 1,
42-
33 => 1,
32+
29 => 1,
33+
30 => 1,
4334
36 => 1,
4435
37 => 1,
4536
38 => 1,
4637
39 => 1,
47-
40 => 1,
48-
43 => 1,
49-
44 => 1,
5038
45 => 1,
39+
46 => 1,
40+
47 => 1,
41+
48 => 1,
5142
49 => 1,
5243
50 => 1,
5344
51 => 1,
45+
57 => 1,
46+
63 => 1,
47+
64 => 1,
48+
70 => 1,
49+
71 => 1,
50+
72 => 1,
5451
];
5552
}
5653

0 commit comments

Comments
 (0)