diff --git a/composer.json b/composer.json index 3e2de60..716c962 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ "require-dev": { "nette/php-generator": "^4.1", "nikic/php-parser": "^5.0", - "phpstan/phpstan": "^1.10.61", + "phpstan/phpstan": "^2.1.11", "phpunit/phpunit": "^10.5.45|^11.5.15", "roave/security-advisories": "dev-latest", "scrutinizer/ocular": "^1.9", diff --git a/phpstan.neon b/phpstan.neon index 06d9681..ee3cd29 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,10 @@ parameters: - level: 5 + level: 6 treatPhpDocTypesAsCertain: false paths: - src + ignoreErrors: + - + identifier: missingType.iterableValue + - + identifier: missingType.generics diff --git a/src/Container.php b/src/Container.php index b5fe656..08bdec4 100644 --- a/src/Container.php +++ b/src/Container.php @@ -26,20 +26,12 @@ public function __construct( protected bool $defaultToShared = false, protected bool $defaultToOverwrite = false, ) { - if ($this->definitions instanceof ContainerAwareInterface) { - $this->definitions->setContainer($this); - } - - if ($this->providers instanceof ContainerAwareInterface) { - $this->providers->setContainer($this); - } - - if ($this->inflectors instanceof ContainerAwareInterface) { - $this->inflectors->setContainer($this); - } + $this->definitions->setContainer($this); + $this->providers->setContainer($this); + $this->inflectors->setContainer($this); } - public function add(string $id, $concrete = null, bool $overwrite = false): DefinitionInterface + public function add(string $id, mixed $concrete = null, bool $overwrite = false): DefinitionInterface { $toOverwrite = $this->defaultToOverwrite || $overwrite; $concrete = $concrete ??= $id; @@ -51,7 +43,7 @@ public function add(string $id, $concrete = null, bool $overwrite = false): Defi return $this->definitions->add($id, $concrete, $toOverwrite); } - public function addShared(string $id, $concrete = null, bool $overwrite = false): DefinitionInterface + public function addShared(string $id, mixed $concrete = null, bool $overwrite = false): DefinitionInterface { $toOverwrite = $this->defaultToOverwrite || $overwrite; $concrete = $concrete ??= $id; diff --git a/src/Definition/Definition.php b/src/Definition/Definition.php index dd61524..2fdea9f 100644 --- a/src/Definition/Definition.php +++ b/src/Definition/Definition.php @@ -83,14 +83,14 @@ public function getConcrete(): mixed return $this->concrete; } - public function setConcrete($concrete): DefinitionInterface + public function setConcrete(mixed $concrete): DefinitionInterface { $this->concrete = $concrete; $this->resolved = null; return $this; } - public function addArgument($arg): DefinitionInterface + public function addArgument(mixed $arg): DefinitionInterface { $this->arguments[] = $arg; return $this; diff --git a/src/Definition/DefinitionAggregate.php b/src/Definition/DefinitionAggregate.php index acc9b7b..76b77f2 100644 --- a/src/Definition/DefinitionAggregate.php +++ b/src/Definition/DefinitionAggregate.php @@ -19,7 +19,7 @@ public function __construct(protected array $definitions = []) }); } - public function add(string $id, $definition, bool $overwrite = false): DefinitionInterface + public function add(string $id, mixed $definition, bool $overwrite = false): DefinitionInterface { if (true === $overwrite) { $this->remove($id); @@ -34,7 +34,7 @@ public function add(string $id, $definition, bool $overwrite = false): Definitio return $definition; } - public function addShared(string $id, $definition, bool $overwrite = false): DefinitionInterface + public function addShared(string $id, mixed $definition, bool $overwrite = false): DefinitionInterface { $definition = $this->add($id, $definition, $overwrite); return $definition->setShared(true); diff --git a/src/Definition/DefinitionAggregateInterface.php b/src/Definition/DefinitionAggregateInterface.php index de06d08..22e1a49 100644 --- a/src/Definition/DefinitionAggregateInterface.php +++ b/src/Definition/DefinitionAggregateInterface.php @@ -9,8 +9,8 @@ interface DefinitionAggregateInterface extends ContainerAwareInterface, IteratorAggregate { - public function add(string $id, $definition, bool $overwrite = false): DefinitionInterface; - public function addShared(string $id, $definition, bool $overwrite = false): DefinitionInterface; + public function add(string $id, mixed $definition, bool $overwrite = false): DefinitionInterface; + public function addShared(string $id, mixed $definition, bool $overwrite = false): DefinitionInterface; public function getDefinition(string $id): DefinitionInterface; public function has(string $id): bool; public function hasTag(string $tag): bool; diff --git a/src/Definition/DefinitionInterface.php b/src/Definition/DefinitionInterface.php index bc32f04..88b7629 100644 --- a/src/Definition/DefinitionInterface.php +++ b/src/Definition/DefinitionInterface.php @@ -8,7 +8,7 @@ interface DefinitionInterface extends ContainerAwareInterface { - public function addArgument($arg): DefinitionInterface; + public function addArgument(mixed $arg): DefinitionInterface; public function addArguments(array $args): DefinitionInterface; public function addMethodCall(string $method, array $args = []): DefinitionInterface; public function addMethodCalls(array $methods = []): DefinitionInterface; @@ -20,6 +20,6 @@ public function isShared(): bool; public function resolve(): mixed; public function resolveNew(): mixed; public function setAlias(string $id): DefinitionInterface; - public function setConcrete($concrete): DefinitionInterface; + public function setConcrete(mixed $concrete): DefinitionInterface; public function setShared(bool $shared): DefinitionInterface; } diff --git a/src/DefinitionContainerInterface.php b/src/DefinitionContainerInterface.php index 9853758..fd874aa 100644 --- a/src/DefinitionContainerInterface.php +++ b/src/DefinitionContainerInterface.php @@ -11,9 +11,9 @@ interface DefinitionContainerInterface extends ContainerInterface { - public function add(string $id, $concrete = null, bool $overwrite = false): DefinitionInterface; + public function add(string $id, mixed $concrete = null, bool $overwrite = false): DefinitionInterface; public function addServiceProvider(ServiceProviderInterface $provider): self; - public function addShared(string $id, $concrete = null, bool $overwrite = false): DefinitionInterface; + public function addShared(string $id, mixed $concrete = null, bool $overwrite = false): DefinitionInterface; public function extend(string $id): DefinitionInterface; public function getNew(string $id): mixed; public function inflector(string $type, ?callable $callback = null): InflectorInterface; diff --git a/src/Inflector/Inflector.php b/src/Inflector/Inflector.php index fd7203a..6e9d6f4 100644 --- a/src/Inflector/Inflector.php +++ b/src/Inflector/Inflector.php @@ -56,7 +56,7 @@ public function invokeMethods(array $methods): InflectorInterface return $this; } - public function setProperty(string $property, $value): InflectorInterface + public function setProperty(string $property, mixed $value): InflectorInterface { $this->properties[$property] = $this->resolveArguments([$value])[0]; return $this; diff --git a/src/Inflector/InflectorAggregate.php b/src/Inflector/InflectorAggregate.php index f7f4f5f..39bbe5c 100644 --- a/src/Inflector/InflectorAggregate.php +++ b/src/Inflector/InflectorAggregate.php @@ -23,7 +23,7 @@ public function add(string $type, ?callable $callback = null): Inflector return $inflector; } - public function inflect($object) + public function inflect(mixed $object): mixed { foreach ($this as $inflector) { $type = $inflector->getType(); diff --git a/src/Inflector/InflectorAggregateInterface.php b/src/Inflector/InflectorAggregateInterface.php index c95ac17..8f6264f 100644 --- a/src/Inflector/InflectorAggregateInterface.php +++ b/src/Inflector/InflectorAggregateInterface.php @@ -10,5 +10,5 @@ interface InflectorAggregateInterface extends ContainerAwareInterface, IteratorAggregate { public function add(string $type, ?callable $callback = null): Inflector; - public function inflect(object $object); + public function inflect(mixed $object): mixed; } diff --git a/src/Inflector/InflectorInterface.php b/src/Inflector/InflectorInterface.php index ed1f766..40515ff 100644 --- a/src/Inflector/InflectorInterface.php +++ b/src/Inflector/InflectorInterface.php @@ -11,5 +11,5 @@ public function inflect(object $object): void; public function invokeMethod(string $name, array $args): InflectorInterface; public function invokeMethods(array $methods): InflectorInterface; public function setProperties(array $properties): InflectorInterface; - public function setProperty(string $property, $value): InflectorInterface; + public function setProperty(string $property, mixed $value): InflectorInterface; } diff --git a/src/ReflectionContainer.php b/src/ReflectionContainer.php index 3864ab1..3b27f59 100644 --- a/src/ReflectionContainer.php +++ b/src/ReflectionContainer.php @@ -64,7 +64,7 @@ public function has(string $id): bool return class_exists($id); } - public function call(callable $callable, array $args = []) + public function call(callable $callable, array $args = []): mixed { if (is_string($callable) && str_contains($callable, '::')) { $callable = explode('::', $callable);