Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ad1a431

Browse files
committedMay 25, 2023
refactor: set phpstan level to max
1 parent e751ede commit ad1a431

15 files changed

+60
-54
lines changed
 

‎phpstan.neon.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
level: 8
2+
level: max
33
paths:
44
- src
55
- spec/PHPSpec

‎spec/PHPSpec/OneOfMatcher.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ protected function matches($subject, array $arguments): bool
3232
}
3333

3434
/**
35-
* @param mixed $subject
35+
* @param string $subject
3636
* @param mixed[] $arguments
3737
*/
3838
protected function getFailureException(string $name, $subject, array $arguments): FailureException
3939
{
40-
if (1 === \count($arguments) && \is_array(current($arguments))) {
40+
if ([] !== \count($arguments) && \is_array(current($arguments))) {
4141
$arguments = current($arguments);
4242
}
4343

@@ -51,12 +51,12 @@ protected function getFailureException(string $name, $subject, array $arguments)
5151
}
5252

5353
/**
54-
* @param mixed $subject
54+
* @param string $subject
5555
* @param mixed[] $arguments
5656
*/
5757
protected function getNegativeFailureException(string $name, $subject, array $arguments): FailureException
5858
{
59-
if (1 === \count($arguments) && \is_array(current($arguments))) {
59+
if ([] !== \count($arguments) && \is_array(current($arguments))) {
6060
$arguments = current($arguments);
6161
}
6262

‎src/Knp/DictionaryBundle/Dictionary.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
use IteratorAggregate;
1010

1111
/**
12-
* @template E
12+
* @template TKey of (int|string)
13+
* @template TValue
1314
*
14-
* @extends IteratorAggregate<mixed, E>
15-
* @extends ArrayAccess<mixed, E>
15+
* @extends IteratorAggregate<TKey, TValue>
16+
* @extends ArrayAccess<TKey, TValue>
1617
*/
1718
interface Dictionary extends ArrayAccess, Countable, IteratorAggregate
1819
{

‎src/Knp/DictionaryBundle/Dictionary/Collection.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414
use Traversable;
1515

1616
/**
17-
* @implements ArrayAccess<string, Dictionary<mixed>>
18-
* @implements IteratorAggregate<string, Dictionary<mixed>>
17+
* @implements ArrayAccess<string, Dictionary<int|string, mixed>>
18+
* @implements IteratorAggregate<string, Dictionary<int|string, mixed>>
1919
*/
2020
final class Collection implements ArrayAccess, Countable, IteratorAggregate
2121
{
2222
/**
23-
* @var array<string, Dictionary<mixed>>
23+
* @var array<string, Dictionary<int|string, mixed>>
2424
*/
2525
private array $dictionaries = [];
2626

2727
/**
28-
* @param Dictionary<mixed> ...$dictionaries
28+
* @param Dictionary<int|string, mixed> ...$dictionaries
2929
*/
3030
public function __construct(Dictionary ...$dictionaries)
3131
{
@@ -35,7 +35,7 @@ public function __construct(Dictionary ...$dictionaries)
3535
}
3636

3737
/**
38-
* @param Dictionary<mixed> $dictionary
38+
* @param Dictionary<int|string, mixed> $dictionary
3939
*/
4040
public function add(Dictionary $dictionary): void
4141
{
@@ -48,8 +48,8 @@ public function offsetExists($offset): bool
4848
}
4949

5050
/**
51-
* @return Dictionary<mixed>
52-
* {@inheritdoc}
51+
* @return Dictionary<int|string, mixed>
52+
* {@inheritdoc}
5353
*
5454
* @throws DictionaryNotFoundException
5555
*/

‎src/Knp/DictionaryBundle/Dictionary/Combined.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
use Knp\DictionaryBundle\Dictionary;
88

99
/**
10-
* @template E
10+
* @template TKey of (int|string)
11+
* @template TValue
1112
*
12-
* @extends Wrapper<E>
13+
* @extends Wrapper<TKey, TValue>
1314
*/
1415
final class Combined extends Wrapper
1516
{
1617
/**
17-
* @param Dictionary<E> ...$dictionaries
18+
* @param Dictionary<TKey, TValue> ...$dictionaries
1819
*/
1920
public function __construct(string $name, Dictionary ...$dictionaries)
2021
{
@@ -32,10 +33,10 @@ public function __construct(string $name, Dictionary ...$dictionaries)
3233
}
3334

3435
/**
35-
* @param E[] $array1
36-
* @param E[] $array2
36+
* @param array<TKey, TValue> $array1
37+
* @param array<TKey, TValue> $array2
3738
*
38-
* @return E[]
39+
* @return array<TKey, TValue>
3940
*/
4041
private function merge(array $array1, array $array2): array
4142
{

‎src/Knp/DictionaryBundle/Dictionary/Factory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface Factory
1111
/**
1212
* @param mixed[] $config
1313
*
14-
* @return Dictionary<mixed>
14+
* @return Dictionary<int|string, mixed>
1515
*/
1616
public function create(string $name, array $config): Dictionary;
1717

‎src/Knp/DictionaryBundle/Dictionary/Factory/Combined.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function create(string $name, array $config): Dictionary
3030
}
3131

3232
$dictionaries = array_map(
33-
fn ($name): Dictionary => $this->dictionaries[$name],
33+
fn (string $name): Dictionary => $this->dictionaries[$name],
3434
$config['dictionaries']
3535
);
3636

‎src/Knp/DictionaryBundle/Dictionary/Factory/Iterator.php

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ public function __construct(private ContainerInterface $container)
1919
/**
2020
* {@inheritdoc}
2121
*
22+
* @param array{service?: string} $config
23+
*
2224
* @throw InvalidArgumentException if there is some problem with the config.
2325
*/
2426
public function create(string $name, array $config): Dictionary

‎src/Knp/DictionaryBundle/Dictionary/Factory/KeyValue.php

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public function __construct(private ValueTransformer $transformer)
1818

1919
/**
2020
* {@inheritdoc}
21+
* @param array{content?: array<mixed>} $config
2122
*
2223
* @throw InvalidArgumentException if there is some problem with the config.
2324
*/

‎src/Knp/DictionaryBundle/Dictionary/Factory/Value.php

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public function __construct(private ValueTransformer $transformer)
1818

1919
/**
2020
* {@inheritdoc}
21+
* @param array{content?: array<mixed>} $config
2122
*
2223
* @throw InvalidArgumentException Not able to create a dictionary with the given name
2324
*/

‎src/Knp/DictionaryBundle/Dictionary/Invokable.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,31 @@
88
use InvalidArgumentException;
99
use Knp\DictionaryBundle\Dictionary;
1010
use ReturnTypeWillChange;
11+
use Traversable;
1112

1213
/**
13-
* @template E
14+
* @template TKey of (int|string)
15+
* @template TValue
1416
*
15-
* @implements Dictionary<E>
17+
* @implements Dictionary<TKey, TValue>
1618
*/
1719
final class Invokable implements Dictionary
1820
{
1921
private bool $invoked = false;
2022

2123
/**
22-
* @var array<mixed, mixed>
24+
* @var array<TKey, TValue>
2325
*/
2426
private array $values = [];
2527

2628
/**
27-
* @var callable
29+
* @var callable(): array<TKey, TValue>
2830
*/
2931
private $callable;
3032

3133
/**
3234
* @param mixed[] $callableArgs
35+
* @param callable(): array<TKey, TValue> $callable
3336
*/
3437
public function __construct(private string $name, callable $callable, private array $callableArgs = [])
3538
{
@@ -84,14 +87,11 @@ public function offsetUnset($offset): void
8487
unset($this->values[$offset]);
8588
}
8689

87-
/**
88-
* @return ArrayIterator<int|string, mixed>
89-
*/
90-
public function getIterator(): ArrayIterator
90+
public function getIterator(): Traversable
9191
{
9292
$this->invoke();
9393

94-
return new ArrayIterator($this->values);
94+
yield from $this->values;
9595
}
9696

9797
public function count(): int

‎src/Knp/DictionaryBundle/Dictionary/Iterator.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
use Traversable;
88

99
/**
10-
* @template E
10+
* @template TKey of (int|string)
11+
* @template TValue
1112
*
12-
* @extends Wrapper<E>
13+
* @extends Wrapper<TKey, TValue>
1314
*/
1415
final class Iterator extends Wrapper
1516
{
1617
/**
17-
* @param Traversable<mixed, E> $iterator
18+
* @param Traversable<TKey, TValue> $iterator
1819
*/
1920
public function __construct(string $name, Traversable $iterator)
2021
{

‎src/Knp/DictionaryBundle/Dictionary/Simple.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
use ReturnTypeWillChange;
1010

1111
/**
12-
* @template E
12+
* @template TKey of (int|string)
13+
* @template TValue
1314
*
14-
* @implements Dictionary<E>
15+
* @implements Dictionary<TKey, TValue>
1516
*/
1617
final class Simple implements Dictionary
1718
{
1819
/**
19-
* @param array<mixed, E> $values
20+
* @param array<TKey, TValue> $values
2021
*/
2122
public function __construct(private string $name, private array $values)
2223
{

‎src/Knp/DictionaryBundle/Dictionary/Traceable.php

+7-8
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@
77
use Knp\DictionaryBundle\DataCollector\DictionaryDataCollector;
88
use Knp\DictionaryBundle\Dictionary;
99
use ReturnTypeWillChange;
10+
use Traversable;
1011

1112
/**
12-
* @template E of mixed
13+
* @template TKey of (int|string)
14+
* @template TValue
1315
*
14-
* @implements Dictionary<E>
16+
* @implements Dictionary<TKey, TValue>
1517
*/
1618
final class Traceable implements Dictionary
1719
{
1820
/**
19-
* @param Dictionary<E> $dictionary
21+
* @param Dictionary<TKey, TValue> $dictionary
2022
*/
2123
public function __construct(private Dictionary $dictionary, private DictionaryDataCollector $collector)
2224
{
@@ -70,14 +72,11 @@ public function offsetUnset($offset): void
7072
$this->markAsUsed();
7173
}
7274

73-
/**
74-
* @return Dictionary<E>
75-
*/
76-
public function getIterator(): Dictionary
75+
public function getIterator(): Traversable
7776
{
7877
$this->markAsUsed();
7978

80-
return $this->dictionary;
79+
yield from $this->dictionary;
8180
}
8281

8382
public function count(): int

‎src/Knp/DictionaryBundle/Dictionary/Wrapper.php

+7-8
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@
66

77
use Knp\DictionaryBundle\Dictionary;
88
use ReturnTypeWillChange;
9+
use Traversable;
910

1011
/**
11-
* @template E
12+
* @template TKey of (int|string)
13+
* @template TValue
1214
*
13-
* @implements Dictionary<E>
15+
* @implements Dictionary<TKey, TValue>
1416
*/
1517
abstract class Wrapper implements Dictionary
1618
{
1719
/**
18-
* @param Dictionary<E> $wrapped
20+
* @param Dictionary<TKey, TValue> $wrapped
1921
*/
2022
public function __construct(private Dictionary $wrapped)
2123
{
@@ -62,11 +64,8 @@ public function count(): int
6264
return $this->wrapped->count();
6365
}
6466

65-
/**
66-
* @return Dictionary<E>
67-
*/
68-
public function getIterator(): Dictionary
67+
public function getIterator(): Traversable
6968
{
70-
return $this->wrapped;
69+
yield from $this->wrapped;
7170
}
7271
}

0 commit comments

Comments
 (0)
Please sign in to comment.