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 May 25, 2023
1 parent 2580ef4 commit 993cd9d
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 54 deletions.
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
8 changes: 4 additions & 4 deletions spec/PHPSpec/OneOfMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ 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))) {
if ([] !== \count($arguments) && \is_array(current($arguments))) {
$arguments = current($arguments);
}

Expand All @@ -51,12 +51,12 @@ 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))) {
if ([] !== \count($arguments) && \is_array(current($arguments))) {
$arguments = current($arguments);
}

Expand Down
7 changes: 4 additions & 3 deletions src/Knp/DictionaryBundle/Dictionary.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
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
{
Expand Down
14 changes: 7 additions & 7 deletions src/Knp/DictionaryBundle/Dictionary/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
use Traversable;

/**
* @implements ArrayAccess<string, Dictionary<mixed>>
* @implements IteratorAggregate<string, Dictionary<mixed>>
* @implements ArrayAccess<string, Dictionary<int|string, mixed>>
* @implements IteratorAggregate<string, Dictionary<int|string, mixed>>
*/
final class Collection implements ArrayAccess, Countable, IteratorAggregate
{
/**
* @var array<string, Dictionary<mixed>>
* @var array<string, Dictionary<int|string, mixed>>
*/
private array $dictionaries = [];

/**
* @param Dictionary<mixed> ...$dictionaries
* @param Dictionary<int|string, mixed> ...$dictionaries
*/
public function __construct(Dictionary ...$dictionaries)
{
Expand All @@ -35,7 +35,7 @@ public function __construct(Dictionary ...$dictionaries)
}

/**
* @param Dictionary<mixed> $dictionary
* @param Dictionary<int|string, mixed> $dictionary
*/
public function add(Dictionary $dictionary): void
{
Expand All @@ -48,8 +48,8 @@ public function offsetExists($offset): bool
}

/**
* @return Dictionary<mixed>
* {@inheritdoc}
* @return Dictionary<int|string, mixed>
* {@inheritdoc}
*
* @throws DictionaryNotFoundException
*/
Expand Down
13 changes: 7 additions & 6 deletions src/Knp/DictionaryBundle/Dictionary/Combined.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
use Knp\DictionaryBundle\Dictionary;

/**
* @template E
* @template TKey of (int|string)
* @template TValue
*
* @extends Wrapper<E>
* @extends Wrapper<TKey, TValue>
*/
final class Combined extends Wrapper
{
/**
* @param Dictionary<E> ...$dictionaries
* @param Dictionary<TKey, TValue> ...$dictionaries
*/
public function __construct(string $name, Dictionary ...$dictionaries)
{
Expand All @@ -32,10 +33,10 @@ public function __construct(string $name, Dictionary ...$dictionaries)
}

/**
* @param E[] $array1
* @param E[] $array2
* @param array<TKey, TValue> $array1
* @param array<TKey, TValue> $array2
*
* @return E[]
* @return array<TKey, TValue>
*/
private function merge(array $array1, array $array2): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Knp/DictionaryBundle/Dictionary/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface Factory
/**
* @param mixed[] $config
*
* @return Dictionary<mixed>
* @return Dictionary<int|string, mixed>
*/
public function create(string $name, array $config): Dictionary;

Expand Down
2 changes: 1 addition & 1 deletion src/Knp/DictionaryBundle/Dictionary/Factory/Combined.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function create(string $name, array $config): Dictionary
}

$dictionaries = array_map(
fn ($name): Dictionary => $this->dictionaries[$name],
fn (string $name): Dictionary => $this->dictionaries[$name],
$config['dictionaries']
);

Expand Down
2 changes: 2 additions & 0 deletions src/Knp/DictionaryBundle/Dictionary/Factory/Iterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public function __construct(private ContainerInterface $container)
/**
* {@inheritdoc}
*
* @param array{service?: string} $config
*
* @throw InvalidArgumentException if there is some problem with the config.
*/
public function create(string $name, array $config): Dictionary
Expand Down
1 change: 1 addition & 0 deletions src/Knp/DictionaryBundle/Dictionary/Factory/KeyValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function __construct(private ValueTransformer $transformer)

/**
* {@inheritdoc}
* @param array{content?: array<mixed>} $config
*
* @throw InvalidArgumentException if there is some problem with the config.
*/
Expand Down
1 change: 1 addition & 0 deletions src/Knp/DictionaryBundle/Dictionary/Factory/Value.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function __construct(private ValueTransformer $transformer)

/**
* {@inheritdoc}
* @param array{content?: array<mixed>} $config
*
* @throw InvalidArgumentException Not able to create a dictionary with the given name
*/
Expand Down
18 changes: 9 additions & 9 deletions src/Knp/DictionaryBundle/Dictionary/Invokable.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,31 @@
use InvalidArgumentException;
use Knp\DictionaryBundle\Dictionary;
use ReturnTypeWillChange;
use Traversable;

/**
* @template E
* @template TKey of (int|string)
* @template TValue
*
* @implements Dictionary<E>
* @implements Dictionary<TKey, TValue>
*/
final class Invokable implements Dictionary
{
private bool $invoked = false;

/**
* @var array<mixed, mixed>
* @var array<TKey, TValue>
*/
private array $values = [];

/**
* @var callable
* @var callable(): array<TKey, TValue>
*/
private $callable;

/**
* @param mixed[] $callableArgs
* @param callable(): array<TKey, TValue> $callable
*/
public function __construct(private string $name, callable $callable, private array $callableArgs = [])
{
Expand Down Expand Up @@ -84,14 +87,11 @@ public function offsetUnset($offset): void
unset($this->values[$offset]);
}

/**
* @return ArrayIterator<int|string, mixed>
*/
public function getIterator(): ArrayIterator
public function getIterator(): Traversable
{
$this->invoke();

return new ArrayIterator($this->values);
yield from $this->values;
}

public function count(): int
Expand Down
7 changes: 4 additions & 3 deletions src/Knp/DictionaryBundle/Dictionary/Iterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
use Traversable;

/**
* @template E
* @template TKey of (int|string)
* @template TValue
*
* @extends Wrapper<E>
* @extends Wrapper<TKey, TValue>
*/
final class Iterator extends Wrapper
{
/**
* @param Traversable<mixed, E> $iterator
* @param Traversable<TKey, TValue> $iterator
*/
public function __construct(string $name, Traversable $iterator)
{
Expand Down
7 changes: 4 additions & 3 deletions src/Knp/DictionaryBundle/Dictionary/Simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
use Knp\DictionaryBundle\Dictionary;

/**
* @template E
* @template TKey of (int|string)
* @template TValue
*
* @implements Dictionary<E>
* @implements Dictionary<TKey, TValue>
*/
final class Simple implements Dictionary
{
/**
* @param array<mixed, E> $values
* @param array<TKey, TValue> $values
*/
public function __construct(private string $name, private array $values)
{
Expand Down
15 changes: 7 additions & 8 deletions src/Knp/DictionaryBundle/Dictionary/Traceable.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@

use Knp\DictionaryBundle\DataCollector\DictionaryDataCollector;
use Knp\DictionaryBundle\Dictionary;
use Traversable;

/**
* @template E of mixed
* @template TKey of (int|string)
* @template TValue
*
* @implements Dictionary<E>
* @implements Dictionary<TKey, TValue>
*/
final class Traceable implements Dictionary
{
/**
* @param Dictionary<E> $dictionary
* @param Dictionary<TKey, TValue> $dictionary
*/
public function __construct(private Dictionary $dictionary, private DictionaryDataCollector $collector)
{
Expand Down Expand Up @@ -68,14 +70,11 @@ public function offsetUnset(mixed $offset): void
$this->markAsUsed();
}

/**
* @return Dictionary<E>
*/
public function getIterator(): Dictionary
public function getIterator(): Traversable
{
$this->markAsUsed();

return $this->dictionary;
yield from $this->dictionary;
}

public function count(): int
Expand Down
15 changes: 7 additions & 8 deletions src/Knp/DictionaryBundle/Dictionary/Wrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
namespace Knp\DictionaryBundle\Dictionary;

use Knp\DictionaryBundle\Dictionary;
use Traversable;

/**
* @template E
* @template TKey of (int|string)
* @template TValue
*
* @implements Dictionary<E>
* @implements Dictionary<TKey, TValue>
*/
abstract class Wrapper implements Dictionary
{
/**
* @param Dictionary<E> $wrapped
* @param Dictionary<TKey, TValue> $wrapped
*/
public function __construct(private Dictionary $wrapped)
{
Expand Down Expand Up @@ -60,11 +62,8 @@ public function count(): int
return $this->wrapped->count();
}

/**
* @return Dictionary<E>
*/
public function getIterator(): Dictionary
public function getIterator(): Traversable
{
return $this->wrapped;
yield from $this->wrapped;
}
}
3 changes: 3 additions & 0 deletions src/Knp/DictionaryBundle/ValueTransformer/Constant.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public function supports(mixed $value): bool
return \array_key_exists($matches['constant'], $constants);
}

/**
* @param string $value
*/
public function transform(mixed $value)
{
if (null === $matches = $this->extract($value)) {
Expand Down

0 comments on commit 993cd9d

Please sign in to comment.