Skip to content
Merged
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
560 changes: 0 additions & 560 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions src/Altair/Container/Builder/ArgumentsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ class ArgumentsBuilder implements BuilderInterface
public function __construct(protected Container $container) {}

/**
* @param ReflectionParameter[]|null $reflectionParameters
*
* @throws InjectionException
* @throws ReflectionException
* @return list<mixed>
*/
public function build(
ReflectionFunctionAbstract $reflectionFunction,
Expand Down Expand Up @@ -127,12 +130,10 @@ protected function buildArgumentFromReflectionParameter(ReflectionParameter $ref
}

/**
* @param $callableOrMethodString
*
* @throws InjectionException
* @return mixed
*/
protected function buildArgumentFromDelegate(string $name, $callableOrMethodString)
protected function buildArgumentFromDelegate(string $name, mixed $callableOrMethodString)
{
if ($this->container->getExecutableBuilder()->isExecutable($callableOrMethodString) === false) {
throw new InjectionException(\sprintf("Unable to create argument '%s' from delegate.", $name));
Expand All @@ -144,6 +145,8 @@ protected function buildArgumentFromDelegate(string $name, $callableOrMethodStri
}

/**
* @param array{0: string, 1: array<string, mixed>|Definition} $definition
*
* @throws InjectionException
* @throws ReflectionException
* @return mixed|object|null
Expand Down
21 changes: 12 additions & 9 deletions src/Altair/Container/Builder/ExecutableBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Closure;
use Override;
use ReflectionException;
use ReflectionFunctionAbstract;

class ExecutableBuilder implements ExecutableBuilderInterface
{
Expand All @@ -40,7 +41,7 @@ public function build(mixed $callableOrMethodString): Executable
* @inheritDoc
*/
#[Override]
public function isExecutable($executable): bool
public function isExecutable(mixed $executable): bool
{
return \is_callable($executable)
|| (\is_string($executable) && method_exists($executable, '__invoke'))
Expand All @@ -50,11 +51,10 @@ public function isExecutable($executable): bool
}

/**
* @param $callableOrMethodString
*
* @throws InjectionException
* @return array{0: ReflectionFunctionAbstract, 1: object|null}
*/
protected function buildExecutableStructure($callableOrMethodString): array
protected function buildExecutableStructure(mixed $callableOrMethodString): array
{
try {
if (\is_string($callableOrMethodString)) {
Expand Down Expand Up @@ -83,6 +83,7 @@ protected function buildExecutableStructure($callableOrMethodString): array

/**
* @throws InjectionException
* @return array{0: ReflectionFunctionAbstract, 1: object|null}
*/
protected function buildExecutableStructureFromString(string $executableString): array
{
Expand All @@ -104,18 +105,17 @@ protected function buildExecutableStructureFromString(string $executableString):
}

/**
* @param $class
* @param $method
* @throws InjectionException
* @return array{0: ReflectionFunctionAbstract, 1: object|null}
*/
protected function buildExecutableStructureFromClassMethodCallable($class, $method): array
protected function buildExecutableStructureFromClassMethodCallable(string $class, string $method): array
{
$relativeStaticMethodStartPos = strpos((string) $method, 'parent::');
$relativeStaticMethodStartPos = strpos($method, 'parent::');

if ($relativeStaticMethodStartPos === 0) {
$childReflection = $this->container->getReflector()->getClass($class);
$class = $childReflection->getParentClass()->name;
$method = substr((string) $method, 8);
$method = substr($method, 8);
}

[$className] = $this->container->getAliases()->resolve($class);
Expand All @@ -135,7 +135,10 @@ protected function buildExecutableStructureFromClassMethodCallable($class, $meth
}

/**
* @param array{0: object|string, 1: string} $executableArray
*
* @throws InjectionException
* @return array{0: ReflectionFunctionAbstract, 1: object|null}
*/
protected function buildExecutableStructureFromArray(array $executableArray): array
{
Expand Down
4 changes: 2 additions & 2 deletions src/Altair/Container/Cache/ArrayCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class ArrayCache implements ReflectionCacheInterface
{
/**
* @var array
* @var array<string, mixed>
*/
protected $cache = [];

Expand All @@ -35,7 +35,7 @@ public function get(string $key)
* @inheritDoc
*/
#[Override]
public function put(string $key, $data): ReflectionCacheInterface
public function put(string $key, mixed $data): ReflectionCacheInterface
{
$this->cache[$key] = $data;

Expand Down
2 changes: 1 addition & 1 deletion src/Altair/Container/Cache/FileCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function get(string $key)
* @inheritDoc
*/
#[Override]
public function put(string $key, $data): ReflectionCacheInterface
public function put(string $key, mixed $data): ReflectionCacheInterface
{
$value = var_export($data, true);
// HHVM fails at __set_state, so just use object cast for now
Expand Down
3 changes: 3 additions & 0 deletions src/Altair/Container/Collection/AliasesCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public function define(string $original, string $alias, SharesCollection $shares
return $this->put($original, $alias);
}

/**
* @return array{0: string, 1: string}
*/
public function resolve(string $name): array
{
$normalizedName = $this->normalizeName($name);
Expand Down
6 changes: 1 addition & 5 deletions src/Altair/Container/Collection/SharesCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ public function shareClass(string $name, AliasesCollection $aliasesCollection):
return $this->put($normalizedName, $this[$normalizedName] ?? null);
}

/**
* @param $instance
*
*/
public function shareInstance($instance, AliasesCollection $aliasesCollection): MapInterface
public function shareInstance(object $instance, AliasesCollection $aliasesCollection): MapInterface
{
$normalizedName = $this->normalizeName($instance::class);
if (isset($aliasesCollection[$normalizedName])) {
Expand Down
20 changes: 5 additions & 15 deletions src/Altair/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Container implements ContainerInterface
protected DelegatesCollection $delegates;

/**
* @var array
* @var array<string, int>
*/
protected $making = [];

Expand Down Expand Up @@ -293,11 +293,10 @@ public function make(string $name, ?Definition $definition = null)
/**
* Invoke the specified callable or class::method string, provisioning dependencies along the way
*
* @param $callableOrMethodString
* @throws InjectionException
* @throws ReflectionException
*/
public function execute($callableOrMethodString, ?Definition $definition = null): mixed
public function execute(mixed $callableOrMethodString, ?Definition $definition = null): mixed
{
$executable = $this->executableBuilder->build($callableOrMethodString);
$definition ??= new Definition([]);
Expand Down Expand Up @@ -346,10 +345,7 @@ public function getPrepares(): PreparesCollection
return $this->prepares;
}

/**
* @param $name
*/
public function isset($name): bool
public function isset(string $name): bool
{
$name = $this->normalizeName($name);

Expand All @@ -369,13 +365,10 @@ public function getArgumentsBuilder(): ArgumentsBuilder
}

/**
* @param $object
* @param $normalizedClass
*
* @throws InjectionException
* @return mixed
*/
protected function prepareInstance($object, $normalizedClass)
protected function prepareInstance(mixed $object, string $normalizedClass)
{
if (isset($this->prepares[$normalizedClass])) {
$callableOrMethodString = $this->prepares->get($normalizedClass);
Expand Down Expand Up @@ -416,13 +409,10 @@ protected function prepareInstance($object, $normalizedClass)
}

/**
* @param $className
* @param $normalizedClass
*
* @throws InjectionException
* @return mixed|object
*/
protected function provisionInstance(string $className, $normalizedClass, Definition $definition)
protected function provisionInstance(string $className, string $normalizedClass, Definition $definition)
{
try {
$constructor = $this->reflector->getConstructor($className);
Expand Down
2 changes: 1 addition & 1 deletion src/Altair/Container/Contracts/ReflectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface ReflectionInterface
/**
* Retrieves ReflectionClass instances, caching them for future retrieval
*
*
* @return ReflectionClass<object>
*/
public function getClass(string $class): ReflectionClass;

Expand Down
36 changes: 11 additions & 25 deletions src/Altair/Container/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class Definition

/**
* Definition constructor.
*
* @param array<int|string, mixed> $arguments
*/
public function __construct(protected array $arguments) {}

Expand All @@ -31,36 +33,27 @@ public function replace(Definition $definition): self
return new self(array_replace($definition->getArguments(), $this->arguments));
}

/**
* @return array<int|string, mixed>
*/
public function getArguments(): array
{
return $this->arguments;
}

/**
* @param $value
*
*/
public function add(string $key, $value): Definition
public function add(string $key, mixed $value): Definition
{
$this->arguments[$key] = $value;

return $this;
}

/**
* @param $value
*
*/
public function addRaw(string $key, $value): Definition
public function addRaw(string $key, mixed $value): Definition
{
return $this->add(self::RAW_PREFIX . $key, $value);
}

/**
* @param $value
*
*/
public function addDelegate(string $key, $value): Definition
public function addDelegate(string $key, mixed $value): Definition
{
return $this->add(self::DELEGATE_PREFIX . $key, $value);
}
Expand All @@ -70,10 +63,7 @@ public function hasIndex(int $position): bool
return isset($this->arguments[$position]) || \array_key_exists($position, $this->arguments);
}

/**
* @param $name
*/
public function has($name): bool
public function has(string $name): bool
{
return isset($this->arguments[$name]) || \array_key_exists($name, $this->arguments);
}
Expand Down Expand Up @@ -103,21 +93,17 @@ public function hasClassDefinition(string $name): bool
}

/**
* @param $position
*
* @return mixed
*/
public function getIndexed($position)
public function getIndexed(int $position)
{
return $this->arguments[$position];
}

/**
* @param $name
*
* @return mixed
*/
public function get($name)
public function get(string $name)
{
if (!\array_key_exists($name, $this->arguments) && !isset($this->arguments[$name])) {
throw new OutOfBoundsException(\sprintf("'%s' not found in definition.", $name));
Expand Down
4 changes: 2 additions & 2 deletions src/Altair/Container/Executable.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct(ReflectionFunctionAbstract $reflectionFunction, $obj
/**
* @return mixed
*/
public function __invoke(...$args)
public function __invoke(mixed ...$args)
{
$reflection = $this->callableReflection;
if ($reflection instanceof ReflectionMethod) {
Expand Down Expand Up @@ -88,7 +88,7 @@ protected function setMethodCallable(ReflectionMethod $reflection, mixed $object

/**
* @param ReflectionFunction|ReflectionFunctionAbstract $reflection
*
* @param array<int, mixed> $args
*/
protected function invokeClosure(ReflectionFunction $reflection, array $args): mixed
{
Expand Down
5 changes: 3 additions & 2 deletions src/Altair/Container/Reflection/CachedReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function __construct(?ReflectionInterface $reflector = null, ?ReflectionC
* @inheritDoc
*
* @throws ReflectionException
* @return ReflectionClass<object>
*/
#[Override]
public function getClass(string $class): ReflectionClass
Expand Down Expand Up @@ -142,7 +143,7 @@ public function getParameterTypeHint(ReflectionFunctionAbstract $function, Refle
* @throws ReflectionException
*/
#[Override]
public function getFunction($name): ReflectionFunction
public function getFunction(mixed $name): ReflectionFunction
{
$key = \is_string($name)
? ReflectionCacheInterface::FUNCTIONS_KEY_PREFIX . strtolower($name)
Expand All @@ -164,7 +165,7 @@ public function getFunction($name): ReflectionFunction
* @throws ReflectionException
*/
#[Override]
public function getMethod($classNameOrInstance, string $methodName): ReflectionMethod
public function getMethod(mixed $classNameOrInstance, string $methodName): ReflectionMethod
{
$className = \is_string($classNameOrInstance)
? $classNameOrInstance
Expand Down
7 changes: 5 additions & 2 deletions src/Altair/Container/Reflection/StandardReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class StandardReflection implements ReflectionInterface
/**
* @inheritDoc
* @throws ReflectionException
* @return ReflectionClass<object>
*/
#[Override]
public function getClass(string $class): ReflectionClass
Expand Down Expand Up @@ -78,13 +79,15 @@ public function getParameterTypeHint(ReflectionFunctionAbstract $function, Refle
* @throws ReflectionException
*/
#[Override]
public function getFunction($name): ReflectionFunction
public function getFunction(mixed $name): ReflectionFunction
{
return new ReflectionFunction($name);
}

/**
* @inheritDoc
*
* @return ReflectionParameter[]|null
*/
public function getFunctionParameters(ReflectionFunction $reflectionFunction): ?array
{
Expand All @@ -96,7 +99,7 @@ public function getFunctionParameters(ReflectionFunction $reflectionFunction): ?
* @throws ReflectionException
*/
#[Override]
public function getMethod($classNameOrInstance, string $methodName): ReflectionMethod
public function getMethod(mixed $classNameOrInstance, string $methodName): ReflectionMethod
{
$className = \is_string($classNameOrInstance)
? $classNameOrInstance
Expand Down
Loading
Loading