Skip to content

Commit 98d4292

Browse files
committed
refactor: set phpstan level to max
1 parent 833c021 commit 98d4292

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+436
-362
lines changed

.php-cs-fixer.dist.php

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
->enable('ordered_imports')
3131
->enable('ordered_interfaces')
3232
->enable('phpdoc_line_span')
33+
->enable('PedroTroller/line_break_between_method_arguments', ['max-length' => 80])
3334
->disable('method_chaining_indentation')
3435
->disable('no_break_comment')
3536
->disable('no_superfluous_phpdoc_tags')

phpstan-baseline.neon

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Method Knp\\\\DictionaryBundle\\\\Dictionary\\\\Factory\\\\Value\\:\\:create\\(\\) should return Knp\\\\DictionaryBundle\\\\Dictionary\\<int\\|string, mixed\\> but returns Knp\\\\DictionaryBundle\\\\Dictionary\\\\Simple\\<int, mixed\\>\\.$#"
5+
count: 1
6+
path: src/Knp/DictionaryBundle/Dictionary/Factory/Value.php
7+
8+
-
9+
message: "#^Parameter \\#1 \\$array of function array_flip expects array\\<int\\|string\\>, array\\<int, mixed\\> given\\.$#"
10+
count: 1
11+
path: src/Knp/DictionaryBundle/Form/Type/DictionaryType.php

phpstan.neon.dist

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
includes:
2+
- phpstan-baseline.neon
3+
14
parameters:
2-
level: 8
5+
level: max
36
paths:
47
- src
58
- spec/PHPSpec

rector.php

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Rector\Config\RectorConfig;
66
use Rector\Core\ValueObject\PhpVersion;
77
use Rector\Set\ValueObject\LevelSetList;
8+
use Rector\Set\ValueObject\SetList;
89

910
return static function (RectorConfig $rectorConfig): void {
1011
$rectorConfig
@@ -25,6 +26,8 @@
2526
->sets(
2627
[
2728
LevelSetList::UP_TO_PHP_80,
29+
SetList::CODE_QUALITY,
30+
SetList::DEAD_CODE,
2831
]
2932
)
3033
;

spec/Knp/DictionaryBundle/DependencyInjection/Compiler/DictionaryBuildingPassSpec.php

+9-6
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ function it_is_initializable()
2020
$this->shouldHaveType(DictionaryBuildingPass::class);
2121
}
2222

23-
function it_builds_a_value_as_key_dictionary_from_the_config(ContainerBuilder $container)
24-
{
23+
function it_builds_a_value_as_key_dictionary_from_the_config(
24+
ContainerBuilder $container
25+
) {
2526
$config = [
2627
'dictionaries' => [
2728
'dico1' => [
@@ -66,8 +67,9 @@ function it_builds_a_value_as_key_dictionary_from_the_config(ContainerBuilder $c
6667
$this->process($container);
6768
}
6869

69-
function it_builds_a_value_dictionary_from_the_config(ContainerBuilder $container)
70-
{
70+
function it_builds_a_value_dictionary_from_the_config(
71+
ContainerBuilder $container
72+
) {
7173
$config = [
7274
'dictionaries' => [
7375
'dico1' => [
@@ -109,8 +111,9 @@ function it_builds_a_value_dictionary_from_the_config(ContainerBuilder $containe
109111
$this->process($container);
110112
}
111113

112-
function it_builds_a_key_value_dictionary_from_the_config(ContainerBuilder $container)
113-
{
114+
function it_builds_a_key_value_dictionary_from_the_config(
115+
ContainerBuilder $container
116+
) {
114117
$config = [
115118
'dictionaries' => [
116119
'dico1' => [

spec/Knp/DictionaryBundle/Dictionary/CollectionSpec.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
final class CollectionSpec extends ObjectBehavior
1616
{
17-
function let(Dictionary $dictionary, Dictionary $dictionary2)
17+
function let(Dictionary $dictionary1, Dictionary $dictionary2)
1818
{
19-
$this->beConstructedWith($dictionary, $dictionary2);
20-
$dictionary->getName()->willReturn('foo');
19+
$this->beConstructedWith($dictionary1, $dictionary2);
20+
$dictionary1->getName()->willReturn('foo');
2121
$dictionary2->getName()->willReturn('dictionary');
2222
}
2323

@@ -49,13 +49,13 @@ function it_should_entry_if_it_exists()
4949

5050
function it_counts_entries()
5151
{
52-
$this->count()->shouldReturn(2);
52+
$this->shouldHaveCount(2);
5353
}
5454

55-
function it_is_a_list_ob_dictionaries($dictionary, $dictionary2)
55+
function it_is_a_list_of_dictionaries($dictionary1, $dictionary2)
5656
{
57-
$this->getIterator()->getArrayCopy()->shouldReturn([
58-
'foo' => $dictionary,
57+
$this->shouldYieldLike([
58+
'foo' => $dictionary1,
5959
'dictionary' => $dictionary2,
6060
]);
6161
}

spec/Knp/DictionaryBundle/Dictionary/CombinedSpec.php

+31-99
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,38 @@
44

55
namespace spec\Knp\DictionaryBundle\Dictionary;
66

7-
use ArrayIterator;
87
use Knp\DictionaryBundle\Dictionary;
98
use Knp\DictionaryBundle\Dictionary\Combined;
109
use PhpSpec\ObjectBehavior;
1110

1211
final class CombinedSpec extends ObjectBehavior
1312
{
14-
function let(Dictionary $dictionary1, Dictionary $dictionary2, Dictionary $dictionary3)
13+
use DictionaryBehavior;
14+
15+
function let()
1516
{
1617
$this->beConstructedWith(
1718
'combined_dictionary',
18-
$dictionary1,
19-
$dictionary2,
20-
$dictionary3
19+
new Dictionary\Simple(
20+
'dictionary1',
21+
[
22+
'foo' => 1,
23+
'bar' => 2,
24+
]
25+
),
26+
new Dictionary\Simple(
27+
'dictionary2',
28+
[
29+
'bar' => 3,
30+
'baz' => 4,
31+
]
32+
),
33+
new Dictionary\Simple(
34+
'dictionary3',
35+
[
36+
'baz' => 5,
37+
]
38+
),
2139
);
2240
}
2341

@@ -26,103 +44,17 @@ function it_is_initializable()
2644
$this->shouldHaveType(Combined::class);
2745
}
2846

29-
function it_is_a_dictionary()
30-
{
31-
$this->shouldImplement(Dictionary::class);
32-
}
33-
34-
function it_access_to_value_like_an_array($dictionary1, $dictionary2, $dictionary3)
47+
protected function getExpectedResult(): array
3548
{
36-
$dictionary1->getIterator()->willReturn(new ArrayIterator(['foo1' => 'foo10']));
37-
38-
$dictionary2->getIterator()->willReturn(new ArrayIterator(['bar1' => 'bar10']));
39-
40-
$dictionary3->getIterator()->willReturn(new ArrayIterator(['baz1' => 'baz10']));
41-
42-
$this['foo1']->shouldBe('foo10');
43-
$this['bar1']->shouldBe('bar10');
44-
$this['baz1']->shouldBe('baz10');
45-
}
46-
47-
function it_getvalues_should_return_dictionaries_values($dictionary1, $dictionary2, $dictionary3)
48-
{
49-
$dictionary1->getIterator()->willReturn(new ArrayIterator([
50-
'foo1' => 'foo10',
51-
'foo2' => 'foo20',
52-
]));
53-
54-
$dictionary2->getIterator()->willReturn(new ArrayIterator([
55-
'bar1' => 'bar10',
56-
'bar2' => 'bar20',
57-
]));
58-
59-
$dictionary3->getIterator()->willReturn(new ArrayIterator([
60-
'foo1' => 'baz10',
61-
'bar2' => 'baz20',
62-
]));
63-
64-
$this->getKeys()->shouldReturn([
65-
'foo1',
66-
'foo2',
67-
'bar1',
68-
'bar2',
69-
]);
70-
$this->getValues()->shouldReturn([
71-
'foo1' => 'baz10',
72-
'foo2' => 'foo20',
73-
'bar1' => 'bar10',
74-
'bar2' => 'baz20',
75-
]);
76-
}
77-
78-
function it_can_iterate_over_dictionaries($dictionary1, $dictionary2, $dictionary3)
79-
{
80-
$dictionary1->getIterator()->willReturn(new ArrayIterator([
81-
'foo1' => 'foo10',
82-
'foo2' => 'foo20',
83-
]));
84-
85-
$dictionary2->getIterator()->willReturn(new ArrayIterator([
86-
'bar1' => 'bar10',
87-
'bar2' => 'bar20',
88-
]));
89-
90-
$dictionary3->getIterator()->willReturn(new ArrayIterator([
91-
'foo2' => 'baz20',
92-
'bar2' => 'baz20',
93-
]));
94-
95-
$this->shouldIterateLike([
96-
'foo1' => 'foo10',
97-
'foo2' => 'baz20',
98-
'bar1' => 'bar10',
99-
'bar2' => 'baz20',
100-
]);
101-
}
102-
103-
function it_sums_the_count_of_elements($dictionary1, $dictionary2, $dictionary3)
104-
{
105-
$dictionary1->getIterator()->willReturn(new ArrayIterator([
106-
'foo1' => 'foo10',
107-
]));
108-
109-
$dictionary2->getIterator()->willReturn(new ArrayIterator([
110-
'bar1' => 'bar10',
111-
'bar2' => 'bar20',
112-
]));
113-
114-
$dictionary3->getIterator()->willReturn(new ArrayIterator([
115-
'baz1' => 'baz10',
116-
'baz2' => 'baz20',
117-
'baz3' => 'baz30',
118-
'baz4' => 'baz40',
119-
]));
120-
121-
$this->count()->shouldReturn(7);
49+
return [
50+
'foo' => 1,
51+
'bar' => 3,
52+
'baz' => 5,
53+
];
12254
}
12355

124-
function its_getname_should_return_dictionary_name()
56+
protected function getExpectedName(): string
12557
{
126-
$this->getName()->shouldReturn('combined_dictionary');
58+
return 'combined_dictionary';
12759
}
12860
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace spec\Knp\DictionaryBundle\Dictionary;
6+
7+
use Knp\DictionaryBundle\Dictionary;
8+
9+
trait DictionaryBehavior
10+
{
11+
public function it_is_a_dictionary(): void
12+
{
13+
$this
14+
->shouldImplement(Dictionary::class)
15+
;
16+
}
17+
18+
public function it_access_to_value_like_an_array(): void
19+
{
20+
foreach ($this->getExpectedResult() as $key => $value) {
21+
$this[$key]->shouldBe($value);
22+
}
23+
}
24+
25+
public function it_provides_keys(): void
26+
{
27+
$this
28+
->getKeys()
29+
->shouldReturn(array_keys($this->getExpectedResult()))
30+
;
31+
}
32+
33+
public function it_provides_values(): void
34+
{
35+
$this
36+
->getValues()
37+
->shouldReturn(array_values($this->getExpectedResult()))
38+
;
39+
}
40+
41+
public function it_provides_combination_of_keys_and_values(): void
42+
{
43+
$this
44+
->shouldYieldLike($this->getExpectedResult())
45+
;
46+
}
47+
48+
public function it_is_countable(): void
49+
{
50+
$this
51+
->shouldHaveCount(\count($this->getExpectedResult()))
52+
;
53+
}
54+
55+
public function it_has_a_name(): void
56+
{
57+
$this
58+
->getName()
59+
->shouldReturn($this->getExpectedName())
60+
;
61+
}
62+
63+
abstract protected function getExpectedResult(): array;
64+
65+
abstract protected function getExpectedName(): string;
66+
}

spec/Knp/DictionaryBundle/Dictionary/Factory/AggregateSpec.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ function it_is_a_factory()
2222
$this->shouldHaveType(Factory::class);
2323
}
2424

25-
function it_supports_if_one_factory_supports(Factory $factory1, Factory $factory2, Factory $factory3)
26-
{
25+
function it_supports_if_one_factory_supports(
26+
Factory $factory1,
27+
Factory $factory2,
28+
Factory $factory3
29+
) {
2730
$this->addFactory($factory1);
2831
$this->addFactory($factory2);
2932

spec/Knp/DictionaryBundle/Dictionary/Factory/CombinedSpec.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ function it_supports_specific_config()
3333
$this->supports(['type' => 'combined'])->shouldReturn(true);
3434
}
3535

36-
function it_creates_a_dictionary(Dictionary $dictionary1, Dictionary $dictionary2, Dictionary $dictionary3)
37-
{
36+
function it_creates_a_dictionary(
37+
Dictionary $dictionary1,
38+
Dictionary $dictionary2,
39+
Dictionary $dictionary3
40+
) {
3841
$dictionary1->getIterator()->willReturn(new ArrayIterator(['foo1' => 'foo10', 'foo2' => 'foo20']));
3942
$dictionary1->getName()->willReturn('dictionary1');
4043

spec/Knp/DictionaryBundle/Dictionary/Factory/ExtendedSpec.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ function it_supports_specific_config()
3333
$this->supports(['extends' => 'my_dictionary'])->shouldReturn(true);
3434
}
3535

36-
function it_creates_a_dictionary($factory, Dictionary $initialDictionary, Dictionary $extendsDictionary)
37-
{
36+
function it_creates_a_dictionary(
37+
$factory,
38+
Dictionary $initialDictionary,
39+
Dictionary $extendsDictionary
40+
) {
3841
$initialDictionary->getName()->willReturn('initial_dictionary');
3942
$initialDictionary->getIterator()->willReturn(new ArrayIterator(['foo1', 'foo2']));
4043

spec/Knp/DictionaryBundle/Dictionary/InvokableSpec.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ function it_access_to_value_like_an_array()
101101
$this['baz']->shouldReturn(2);
102102
}
103103

104-
function it_throws_an_exception_if_callable_returns_somthing_else_than_an_array_or_an_array_access($nothing)
105-
{
104+
function it_throws_an_exception_if_callable_returns_somthing_else_than_an_array_or_an_array_access(
105+
$nothing
106+
) {
106107
$this->beConstructedWith('foo', function (): void {
107108
});
108109

0 commit comments

Comments
 (0)