Skip to content
Permalink
Browse files

fixed bugs reported by PhpStan (#212)(#211)(#210)(#208)(#207)(#213)

  • Loading branch information...
janbarasek authored and dg committed Jul 19, 2019
1 parent fa7e070 commit 1a4780382aabcd4cc0d27d0dc7b8349342026131
@@ -21,13 +21,13 @@ class ContainerPanel implements Tracy\IBarPanel
{
use Nette\SmartObject;
/** @var int */
/** @var float|null */
public static $compilationTime;
/** @var Nette\DI\Container */
private $container;
/** @var int|null */
/** @var float|null */
private $elapsedTime;
@@ -35,7 +35,6 @@ public static function merge($left, $right)
/**
* Return true if array prevents merging and removes this information.
* @return mixed
*/
public static function takeParent(&$data): bool
{
@@ -19,7 +19,7 @@ abstract class Definition
{
use Nette\SmartObject;
/** @var string */
/** @var string|null */
private $name;
/** @var string|null class or interface name */
@@ -26,7 +26,7 @@ final class DIExtension extends Nette\DI\CompilerExtension
/** @var bool */
private $debugMode;
/** @var int */
/** @var float */
private $time;
@@ -32,12 +32,11 @@ public function getConfigSchema(): Nette\Schema\Schema
public function beforeCompile()
{
foreach ($this->getContainerBuilder()->getDefinitions() as $def) {
if (
$def->getTag(self::TAG_INJECT)
&& ($def = $def instanceof Definitions\FactoryDefinition ? $def->getResultDefinition() : $def)
&& ($def instanceof Definitions\ServiceDefinition)
) {
$this->updateDefinition($def);
if ($def->getTag(self::TAG_INJECT)) {
$def = $def instanceof Definitions\FactoryDefinition ? $def->getResultDefinition() : $def;
if ($def instanceof Definitions\ServiceDefinition) {
$this->updateDefinition($def);
}
}
}
}
@@ -142,9 +141,9 @@ public static function callInjects(DI\Container $container, $service): void
/**
* @param object|string $class
* @param DI\Resolver|DI\Container $container
* @param DI\Container|DI\ContainerBuilder|null $container
*/
private static function checkType($class, string $name, ?string $type, $container = null): void
private static function checkType($class, string $name, ?string $type, $container): void
{
$propName = Reflection::toString(new \ReflectionProperty($class, $name));
if (!$type) {
@@ -147,6 +147,7 @@ public static function prefixServiceName($config, string $namespace)
/**
* Returns an annotation value.
* @param \ReflectionFunctionAbstract|\ReflectionProperty|\ReflectionClass $ref
*/
public static function parseAnnotation(\Reflector $ref, string $name): ?string
{
@@ -84,8 +84,8 @@ public function toString(Nette\PhpGenerator\ClassType $class): string
public function generateMethod(Definitions\Definition $def): Nette\PhpGenerator\Method
{
$name = $def->getName();
try {
$name = $def->getName();
$method = new Nette\PhpGenerator\Method(Container::getMethodName($name));
$method->setVisibility('public');
$method->setReturnType($def->getType());
@@ -109,9 +109,11 @@ public function resolveEntityType(Statement $statement): ?string
}
try {
/** @var \ReflectionMethod|\ReflectionFunction $reflection */
$reflection = Nette\Utils\Callback::toReflection($entity[0] === '' ? $entity[1] : $entity);
$refClass = $reflection instanceof \ReflectionMethod ? $reflection->getDeclaringClass() : null;
} catch (\ReflectionException $e) {
$refClass = $reflection = null;
}
if (isset($e) || ($refClass && (!$reflection->isPublic()
@@ -326,16 +328,11 @@ public function normalizeReference(Reference $ref): Reference
return $this->currentService && $service === $this->currentService->getName()
? new Reference(Reference::SELF)
: $ref;
} else {
try {
$res = $this->getByType($service);
} catch (NotAllowedDuringResolvingException $e) {
return new Reference($service);
}
if (!$res) {
throw new ServiceCreationException("Reference to missing service of type $service.");
}
return $res;
}
try {
return $this->getByType($service);
} catch (NotAllowedDuringResolvingException $e) {
return new Reference($service);
}
}

0 comments on commit 1a47803

Please sign in to comment.
You can’t perform that action at this time.