Skip to content

Commit 993cd9d

Browse files
committed
refactor: set phpstan level to max
1 parent 2580ef4 commit 993cd9d

File tree

16 files changed

+63
-54
lines changed

16 files changed

+63
-54
lines changed

phpstan.neon.dist

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 4 additions & 3 deletions
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

Lines changed: 7 additions & 7 deletions
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

Lines changed: 7 additions & 6 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 9 additions & 9 deletions
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

Lines changed: 4 additions & 3 deletions
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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
use Knp\DictionaryBundle\Dictionary;
99

1010
/**
11-
* @template E
11+
* @template TKey of (int|string)
12+
* @template TValue
1213
*
13-
* @implements Dictionary<E>
14+
* @implements Dictionary<TKey, TValue>
1415
*/
1516
final class Simple implements Dictionary
1617
{
1718
/**
18-
* @param array<mixed, E> $values
19+
* @param array<TKey, TValue> $values
1920
*/
2021
public function __construct(private string $name, private array $values)
2122
{

src/Knp/DictionaryBundle/Dictionary/Traceable.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@
66

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

1011
/**
11-
* @template E of mixed
12+
* @template TKey of (int|string)
13+
* @template TValue
1214
*
13-
* @implements Dictionary<E>
15+
* @implements Dictionary<TKey, TValue>
1416
*/
1517
final class Traceable implements Dictionary
1618
{
1719
/**
18-
* @param Dictionary<E> $dictionary
20+
* @param Dictionary<TKey, TValue> $dictionary
1921
*/
2022
public function __construct(private Dictionary $dictionary, private DictionaryDataCollector $collector)
2123
{
@@ -68,14 +70,11 @@ public function offsetUnset(mixed $offset): void
6870
$this->markAsUsed();
6971
}
7072

71-
/**
72-
* @return Dictionary<E>
73-
*/
74-
public function getIterator(): Dictionary
73+
public function getIterator(): Traversable
7574
{
7675
$this->markAsUsed();
7776

78-
return $this->dictionary;
77+
yield from $this->dictionary;
7978
}
8079

8180
public function count(): int

src/Knp/DictionaryBundle/Dictionary/Wrapper.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@
55
namespace Knp\DictionaryBundle\Dictionary;
66

77
use Knp\DictionaryBundle\Dictionary;
8+
use Traversable;
89

910
/**
10-
* @template E
11+
* @template TKey of (int|string)
12+
* @template TValue
1113
*
12-
* @implements Dictionary<E>
14+
* @implements Dictionary<TKey, TValue>
1315
*/
1416
abstract class Wrapper implements Dictionary
1517
{
1618
/**
17-
* @param Dictionary<E> $wrapped
19+
* @param Dictionary<TKey, TValue> $wrapped
1820
*/
1921
public function __construct(private Dictionary $wrapped)
2022
{
@@ -60,11 +62,8 @@ public function count(): int
6062
return $this->wrapped->count();
6163
}
6264

63-
/**
64-
* @return Dictionary<E>
65-
*/
66-
public function getIterator(): Dictionary
65+
public function getIterator(): Traversable
6766
{
68-
return $this->wrapped;
67+
yield from $this->wrapped;
6968
}
7069
}

src/Knp/DictionaryBundle/ValueTransformer/Constant.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public function supports(mixed $value): bool
3535
return \array_key_exists($matches['constant'], $constants);
3636
}
3737

38+
/**
39+
* @param string $value
40+
*/
3841
public function transform(mixed $value)
3942
{
4043
if (null === $matches = $this->extract($value)) {

0 commit comments

Comments
 (0)