Skip to content

Commit

Permalink
fix typings & conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
seferov committed Jun 5, 2024
1 parent d98196c commit 7564d3e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
15 changes: 6 additions & 9 deletions src/Handler/ContainerHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> collection of cower-cased class names that are present in the container
Expand Down Expand Up @@ -114,7 +111,7 @@ public static function afterMethodCallAnalysis(AfterMethodCallAnalysisEvent $eve
} else {
try {
$serviceId = \constant($className.'::'.$idArgument->name->name);
} catch (\Exception $e) {
} catch (\Exception) {
return;
}
}
Expand All @@ -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)]));
}
Expand All @@ -152,15 +149,15 @@ 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()
);
}
}

public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event)
public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event): void
{
$codebase = $event->getCodebase();
$statements_source = $event->getStatementsSource();
Expand Down Expand Up @@ -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;
}

Expand Down
24 changes: 9 additions & 15 deletions src/Symfony/ContainerMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,19 @@ class ContainerMeta
/**
* @var array<string>
*/
private $classNames = [];
private array $classNames = [];

/**
* @var array<string, string>
*/
private $classLocators = [];
private array $classLocators = [];

/**
* @var array<string, array<string, string>>
*/
private $serviceLocators = [];
private array $serviceLocators = [];

/**
* @var ContainerBuilder
*/
private $container;
private ContainerBuilder $container;

public function __construct(array $containerXmlPaths)
{
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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) {
}
}

Expand All @@ -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;
}

Expand Down

0 comments on commit 7564d3e

Please sign in to comment.