for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Hgraca\MicroDI;
use Hgraca\Cache\CacheInterface;
use Hgraca\Cache\Exception\CacheItemNotFoundException;
use Hgraca\Helper\ClassHelper;
final class DependencyResolver implements DependencyResolverInterface
{
/** @var CacheInterface */
private $cache;
public function __construct(CacheInterface $cache)
$this->cache = $cache;
}
public function resolveDependencies(string $dependentClass, string $dependentMethod): array
$dependenciesKey = $this->getDependenciesKey($dependentClass, $dependentMethod);
try {
$dependencies = $this->cache->fetch($dependenciesKey);
} catch (CacheItemNotFoundException $e) {
$dependencies = ClassHelper::getParameters($dependentClass, $dependentMethod);
$this->cache->save($dependenciesKey, $dependencies);
$dependencies
array
string
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example:
function acceptsInteger($int) { } $x = '123'; // string "123" // Instead of acceptsInteger($x); // we recommend to use acceptsInteger((integer) $x);
return $dependencies;
private function getDependenciesKey(string $class, string $method = '__construct'): string
return sprintf('%s::%s', str_replace('\\', '_', $class), $method);
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: