Skip to content

Update phpstan and add missing types #272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 6 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
parameters:
level: 5
level: 6
treatPhpDocTypesAsCertain: false
paths:
- src
ignoreErrors:
-
identifier: missingType.iterableValue
-
identifier: missingType.generics
18 changes: 5 additions & 13 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/Definition/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/Definition/DefinitionAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/Definition/DefinitionAggregateInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/Definition/DefinitionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
4 changes: 2 additions & 2 deletions src/DefinitionContainerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Inflector/Inflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Inflector/InflectorAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/Inflector/InflectorAggregateInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion src/Inflector/InflectorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion src/ReflectionContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down