diff --git a/src/Handler/ContainerHandler.php b/src/Handler/ContainerHandler.php index 849e300..e750deb 100644 --- a/src/Handler/ContainerHandler.php +++ b/src/Handler/ContainerHandler.php @@ -35,10 +35,7 @@ class ContainerHandler implements AfterMethodCallAnalysisInterface, AfterClassLi 'Symfony\Bundle\FrameworkBundle\Test\TestContainer', ]; - /** - * @var ContainerMeta|null - */ - private static $containerMeta; + private static ?ContainerMeta $containerMeta = null; /** * @var array collection of cower-cased class names that are present in the container @@ -114,7 +111,7 @@ public static function afterMethodCallAnalysis(AfterMethodCallAnalysisEvent $eve } else { try { $serviceId = \constant($className.'::'.$idArgument->name->name); - } catch (\Exception $e) { + } catch (\Exception) { return; } } @@ -133,7 +130,7 @@ public static function afterMethodCallAnalysis(AfterMethodCallAnalysisEvent $eve } $class = $service->getClass(); - if ($class) { + if (null !== $class) { $codebase->classlikes->addFullyQualifiedClassName($class); $event->setReturnTypeCandidate(new Union([new TNamedObject($class)])); } @@ -152,7 +149,7 @@ public static function afterMethodCallAnalysis(AfterMethodCallAnalysisEvent $eve ); } } - } catch (ServiceNotFoundException $e) { + } catch (ServiceNotFoundException) { IssueBuffer::accepts( new ServiceNotFound($serviceId, new CodeLocation($statements_source, $firstArg->value)), $statements_source->getSuppressedIssues() @@ -160,7 +157,7 @@ public static function afterMethodCallAnalysis(AfterMethodCallAnalysisEvent $eve } } - public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event) + public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event): void { $codebase = $event->getCodebase(); $statements_source = $event->getStatementsSource(); @@ -221,7 +218,7 @@ function ($c) use ($methodName) { private static function followsParameterNamingConvention(string $name): bool { - if (0 === strpos($name, 'env(')) { + if (str_starts_with($name, 'env(')) { return true; } diff --git a/src/Symfony/ContainerMeta.php b/src/Symfony/ContainerMeta.php index e055ac8..e7d86bb 100644 --- a/src/Symfony/ContainerMeta.php +++ b/src/Symfony/ContainerMeta.php @@ -19,22 +19,19 @@ class ContainerMeta /** * @var array */ - private $classNames = []; + private array $classNames = []; /** * @var array */ - private $classLocators = []; + private array $classLocators = []; /** * @var array> */ - private $serviceLocators = []; + private array $serviceLocators = []; - /** - * @var ContainerBuilder - */ - private $container; + private ContainerBuilder $container; public function __construct(array $containerXmlPaths) { @@ -67,10 +64,7 @@ public function get(string $id, ?string $contextClass = null): Definition return $definition; } - /** - * @return mixed|null - */ - public function getParameter(string $key) + public function getParameter(string $key): mixed { return $this->container->getParameter($key); } @@ -111,7 +105,7 @@ private function init(array $containerXmlPaths): void $this->classLocators[$this->container->getDefinition($id)->getClass() ?? $id] = (string) $reference; } elseif ($definition->hasTag('container.service_locator')) { continue; - } elseif ($className = $definition->getClass()) { + } elseif (null !== $className = $definition->getClass()) { $this->classNames[] = $className; } } @@ -138,10 +132,10 @@ private function addServiceLocator(string $key, string $id, Reference $reference try { $definition = $this->getDefinition((string) $reference); $className = $definition->getClass(); - if ($className) { + if (null !== $className) { $this->classNames[] = $className; } - } catch (ServiceNotFoundException $e) { + } catch (ServiceNotFoundException) { } } @@ -155,7 +149,7 @@ private function getDefinition(string $id): Definition } catch (ServiceNotFoundException $serviceNotFoundException) { try { $alias = $this->container->getAlias($id); - } catch (InvalidArgumentException $e) { + } catch (InvalidArgumentException) { throw $serviceNotFoundException; }