Skip to content

Commit

Permalink
refactor: set phpstan level to max
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroTroller committed Jun 21, 2023
1 parent 5925fa6 commit a48cd8b
Show file tree
Hide file tree
Showing 30 changed files with 240 additions and 164 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
->enable('ordered_imports')
->enable('ordered_interfaces')
->enable('phpdoc_line_span')
->enable('PedroTroller/line_break_between_method_arguments', ['max-length' => 90])
->disable('method_chaining_indentation')
->disable('no_break_comment')
->disable('no_superfluous_phpdoc_tags')
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 8
level: max
paths:
- src
- spec/PHPSpec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ function it_is_initializable()
$this->shouldHaveType(DictionaryBuildingPass::class);
}

function it_builds_a_value_as_key_dictionary_from_the_config(ContainerBuilder $container)
{
function it_builds_a_value_as_key_dictionary_from_the_config(
ContainerBuilder $container
) {
$config = [
'dictionaries' => [
'dico1' => [
Expand Down Expand Up @@ -66,8 +67,9 @@ function it_builds_a_value_as_key_dictionary_from_the_config(ContainerBuilder $c
$this->process($container);
}

function it_builds_a_value_dictionary_from_the_config(ContainerBuilder $container)
{
function it_builds_a_value_dictionary_from_the_config(
ContainerBuilder $container
) {
$config = [
'dictionaries' => [
'dico1' => [
Expand Down Expand Up @@ -109,8 +111,9 @@ function it_builds_a_value_dictionary_from_the_config(ContainerBuilder $containe
$this->process($container);
}

function it_builds_a_key_value_dictionary_from_the_config(ContainerBuilder $container)
{
function it_builds_a_key_value_dictionary_from_the_config(
ContainerBuilder $container
) {
$config = [
'dictionaries' => [
'dico1' => [
Expand Down
35 changes: 25 additions & 10 deletions spec/Knp/DictionaryBundle/Dictionary/CombinedSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@

final class CombinedSpec extends ObjectBehavior
{
function let(Dictionary $dictionary1, Dictionary $dictionary2, Dictionary $dictionary3)
{
function let(
Dictionary $dictionary1,
Dictionary $dictionary2,
Dictionary $dictionary3
) {
$this->beConstructedWith(
'combined_dictionary',
$dictionary1,
Expand All @@ -31,8 +34,11 @@ function it_is_a_dictionary()
$this->shouldImplement(Dictionary::class);
}

function it_access_to_value_like_an_array($dictionary1, $dictionary2, $dictionary3)
{
function it_access_to_value_like_an_array(
$dictionary1,
$dictionary2,
$dictionary3
) {
$dictionary1->getIterator()->willReturn(new ArrayIterator(['foo1' => 'foo10']));

$dictionary2->getIterator()->willReturn(new ArrayIterator(['bar1' => 'bar10']));
Expand All @@ -44,8 +50,11 @@ function it_access_to_value_like_an_array($dictionary1, $dictionary2, $dictionar
$this['baz1']->shouldBe('baz10');
}

function it_getvalues_should_return_dictionaries_values($dictionary1, $dictionary2, $dictionary3)
{
function it_getvalues_should_return_dictionaries_values(
$dictionary1,
$dictionary2,
$dictionary3
) {
$dictionary1->getIterator()->willReturn(new ArrayIterator([
'foo1' => 'foo10',
'foo2' => 'foo20',
Expand Down Expand Up @@ -75,8 +84,11 @@ function it_getvalues_should_return_dictionaries_values($dictionary1, $dictionar
]);
}

function it_can_iterate_over_dictionaries($dictionary1, $dictionary2, $dictionary3)
{
function it_can_iterate_over_dictionaries(
$dictionary1,
$dictionary2,
$dictionary3
) {
$dictionary1->getIterator()->willReturn(new ArrayIterator([
'foo1' => 'foo10',
'foo2' => 'foo20',
Expand All @@ -100,8 +112,11 @@ function it_can_iterate_over_dictionaries($dictionary1, $dictionary2, $dictionar
]);
}

function it_sums_the_count_of_elements($dictionary1, $dictionary2, $dictionary3)
{
function it_sums_the_count_of_elements(
$dictionary1,
$dictionary2,
$dictionary3
) {
$dictionary1->getIterator()->willReturn(new ArrayIterator([
'foo1' => 'foo10',
]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ function it_is_a_factory()
$this->shouldHaveType(Factory::class);
}

function it_supports_if_one_factory_supports(Factory $factory1, Factory $factory2, Factory $factory3)
{
function it_supports_if_one_factory_supports(
Factory $factory1,
Factory $factory2,
Factory $factory3
) {
$this->addFactory($factory1);
$this->addFactory($factory2);

Expand Down
7 changes: 5 additions & 2 deletions spec/Knp/DictionaryBundle/Dictionary/Factory/CombinedSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ function it_supports_specific_config()
$this->supports(['type' => 'combined'])->shouldReturn(true);
}

function it_creates_a_dictionary(Dictionary $dictionary1, Dictionary $dictionary2, Dictionary $dictionary3)
{
function it_creates_a_dictionary(
Dictionary $dictionary1,
Dictionary $dictionary2,
Dictionary $dictionary3
) {
$dictionary1->getIterator()->willReturn(new ArrayIterator(['foo1' => 'foo10', 'foo2' => 'foo20']));
$dictionary1->getName()->willReturn('dictionary1');

Expand Down
7 changes: 5 additions & 2 deletions spec/Knp/DictionaryBundle/Dictionary/Factory/ExtendedSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ function it_supports_specific_config()
$this->supports(['extends' => 'my_dictionary'])->shouldReturn(true);
}

function it_creates_a_dictionary($factory, Dictionary $initialDictionary, Dictionary $extendsDictionary)
{
function it_creates_a_dictionary(
$factory,
Dictionary $initialDictionary,
Dictionary $extendsDictionary
) {
$initialDictionary->getName()->willReturn('initial_dictionary');
$initialDictionary->getIterator()->willReturn(new ArrayIterator(['foo1', 'foo2']));

Expand Down
5 changes: 3 additions & 2 deletions spec/Knp/DictionaryBundle/Dictionary/InvokableSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ function it_access_to_value_like_an_array()
$this['baz']->shouldReturn(2);
}

function it_throws_an_exception_if_callable_returns_somthing_else_than_an_array_or_an_array_access($nothing)
{
function it_throws_an_exception_if_callable_returns_somthing_else_than_an_array_or_an_array_access(
$nothing
) {
$this->beConstructedWith('foo', function (): void {
});

Expand Down
22 changes: 14 additions & 8 deletions spec/PHPSpec/OneOfMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ protected function matches($subject, array $arguments): bool
}

/**
* @param mixed $subject
* @param string $subject
* @param mixed[] $arguments
*/
protected function getFailureException(string $name, $subject, array $arguments): FailureException
{
if (1 === \count($arguments) && \is_array(current($arguments))) {
protected function getFailureException(
string $name,
$subject,
array $arguments
): FailureException {
if ([] !== \count($arguments) && \is_array(current($arguments))) {
$arguments = current($arguments);
}

Expand All @@ -51,12 +54,15 @@ protected function getFailureException(string $name, $subject, array $arguments)
}

/**
* @param mixed $subject
* @param string $subject
* @param mixed[] $arguments
*/
protected function getNegativeFailureException(string $name, $subject, array $arguments): FailureException
{
if (1 === \count($arguments) && \is_array(current($arguments))) {
protected function getNegativeFailureException(
string $name,
$subject,
array $arguments
): FailureException {
if ([] !== \count($arguments) && \is_array(current($arguments))) {
$arguments = current($arguments);
}

Expand Down
25 changes: 14 additions & 11 deletions src/Knp/DictionaryBundle/DataCollector/DictionaryDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,42 @@

namespace Knp\DictionaryBundle\DataCollector;

use Generator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
use Throwable;

/**
* @property array<array{key: int|string, value: mixed}> $data
*/
final class DictionaryDataCollector extends DataCollector
{
public function collect(Request $request, Response $response, Throwable $exception = null): void
{
public function collect(
Request $request,
Response $response,
Throwable $exception = null
): void {
}

/**
* @param array<mixed> $keys
* @param array<mixed> $values
* @param array<int|string> $keys
* @param array<mixed> $values
*/
public function addDictionary(string $name, array $keys, array $values): void
{
$this->data[$name] = array_map(
fn ($key, $value): array => ['key' => $key, 'value' => $value],
static fn ($key, $value): array => ['key' => $key, 'value' => $value],
$keys,
$values
);
}

/**
* @return Generator<string, array<mixed>>
* @return array<string, array{key: int|string, value: mixed}>
*/
public function getDictionaries(): Generator
public function getDictionaries(): array
{
foreach ($this->data as $name => $keyValuePairs) {
yield $name => $keyValuePairs;
}
return $this->data;
}

public function reset(): void
Expand Down
21 changes: 14 additions & 7 deletions src/Knp/DictionaryBundle/Dictionary.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,44 @@
use IteratorAggregate;

/**
* @template E
* @template TKey of (int|string)
* @template TValue
*
* @extends IteratorAggregate<mixed, E>
* @extends ArrayAccess<mixed, E>
* @extends IteratorAggregate<TKey, TValue>
* @extends ArrayAccess<TKey, TValue>
*/
interface Dictionary extends ArrayAccess, Countable, IteratorAggregate
{
/**
* @var string
*
* @deprecated
*/
public const VALUE = 'value';

/**
* @var string
*
* @deprecated
*/
public const VALUE_AS_KEY = 'value_as_key';

/**
* @var string
*
* @deprecated
*/
public const KEY_VALUE = 'key_value';

public function getName(): string;

/**
* @return mixed[]
* @return array<int, TKey>
*/
public function getValues(): array;
public function getKeys(): array;

/**
* @return mixed[]
* @return array<int, TValue>
*/
public function getKeys(): array;
public function getValues(): array;
}
Loading

0 comments on commit a48cd8b

Please sign in to comment.