Skip to content

Commit

Permalink
Fix static analysis errors & CS (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
seferov committed Jun 5, 2024
1 parent dd06f30 commit 257eb04
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/Handler/ConsoleHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static function afterMethodCallAnalysis(AfterMethodCallAnalysisEvent $eve
break;
case 'Symfony\Component\Console\Input\InputInterface::getargument':
$identifier = self::getNodeIdentifier($args[0]->value);
if (!$identifier) {
if (null === $identifier) {
break;
}

Expand All @@ -70,7 +70,7 @@ public static function afterMethodCallAnalysis(AfterMethodCallAnalysisEvent $eve
break;
case 'Symfony\Component\Console\Input\InputInterface::getoption':
$identifier = self::getNodeIdentifier($args[0]->value);
if (!$identifier) {
if (null === $identifier) {
break;
}

Expand Down Expand Up @@ -126,7 +126,7 @@ private static function analyseArgument(array $args, StatementsSource $statement
$normalizedParams = self::normalizeArgumentParams($args);

$identifier = self::getNodeIdentifier($normalizedParams['name']->value);
if (!$identifier) {
if (null === $identifier) {
return;
}

Expand Down Expand Up @@ -170,7 +170,7 @@ private static function analyseOption(array $args, StatementsSource $statements_
$normalizedParams = self::normalizeOptionParams($args);

$identifier = self::getNodeIdentifier($normalizedParams['name']->value);
if (!$identifier) {
if (null === $identifier) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Handler/ContainerHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static function afterMethodCallAnalysis(AfterMethodCallAnalysisEvent $eve
if ('self' === $className) {
$className = $event->getStatementsSource()->getSource()->getFQCLN();
}
if (!$idArgument->name instanceof Identifier || !$className) {
if (!$idArgument->name instanceof Identifier || null === $className) {
return;
}

Expand Down Expand Up @@ -141,7 +141,7 @@ public static function afterMethodCallAnalysis(AfterMethodCallAnalysisEvent $eve
if (!$service->isPublic()) {
/** @var class-string $kernelTestCaseClass */
$kernelTestCaseClass = 'Symfony\Bundle\FrameworkBundle\Test\KernelTestCase';
$isTestContainer = $context->parent
$isTestContainer = null !== $context->parent
&& ($kernelTestCaseClass === $context->parent
|| is_subclass_of($context->parent, $kernelTestCaseClass)
);
Expand Down
3 changes: 1 addition & 2 deletions src/Handler/HeaderBagHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use PhpParser\Node\Scalar\String_;
use Psalm\Plugin\EventHandler\Event\MethodReturnTypeProviderEvent;
use Psalm\Plugin\EventHandler\MethodReturnTypeProviderInterface;
use Psalm\Type;
use Psalm\Type\Atomic\TArray;
use Psalm\Type\Atomic\TInt;
use Psalm\Type\Atomic\TNull;
Expand All @@ -24,7 +23,7 @@ public static function getClassLikeNames(): array
];
}

public static function getMethodReturnType(MethodReturnTypeProviderEvent $event): ?Type\Union
public static function getMethodReturnType(MethodReturnTypeProviderEvent $event): ?Union
{
$fq_classlike_name = $event->getFqClasslikeName();
$method_name_lowercase = $event->getMethodNameLowercase();
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/
class Plugin implements PluginEntryPointInterface
{
public function __invoke(RegistrationInterface $api, \SimpleXMLElement $config = null): void
public function __invoke(RegistrationInterface $api, ?\SimpleXMLElement $config = null): void
{
require_once __DIR__.'/Handler/HeaderBagHandler.php';
require_once __DIR__.'/Handler/ContainerHandler.php';
Expand Down
11 changes: 5 additions & 6 deletions src/Symfony/ContainerMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public function __construct(array $containerXmlPaths)
/**
* @throws ServiceNotFoundException
*/
public function get(string $id, string $contextClass = null): Definition
public function get(string $id, ?string $contextClass = null): Definition
{
if ($contextClass && isset($this->classLocators[$contextClass]) && isset($this->serviceLocators[$this->classLocators[$contextClass]]) && isset($this->serviceLocators[$this->classLocators[$contextClass]][$id])) {
if (null !== $contextClass && isset($this->classLocators[$contextClass]) && isset($this->serviceLocators[$this->classLocators[$contextClass]]) && isset($this->serviceLocators[$this->classLocators[$contextClass]][$id])) {
$id = $this->serviceLocators[$this->classLocators[$contextClass]][$id];

try {
Expand Down Expand Up @@ -91,12 +91,12 @@ private function init(array $containerXmlPaths): void
$containerXmlPath = null;
foreach ($containerXmlPaths as $filePath) {
$containerXmlPath = realpath((string) $filePath);
if ($containerXmlPath) {
if (false !== $containerXmlPath) {
break;
}
}

if (!$containerXmlPath) {
if (!is_string($containerXmlPath)) {
throw new ConfigException('Container xml file(s) not found!');
}

Expand All @@ -117,8 +117,7 @@ private function init(array $containerXmlPaths): void
}

foreach ($this->container->findTaggedServiceIds('container.service_locator') as $key => $_) {
$definition = $this->container->getDefinition($key);
foreach ($definition->getArgument(0) as $id => $argument) {
foreach ($this->container->getDefinition($key)->getArgument(0) as $id => $argument) {
if ($argument instanceof Reference) {
$this->addServiceLocator($key, $id, $argument);
} elseif ($argument instanceof ServiceClosureArgument) {
Expand Down
11 changes: 4 additions & 7 deletions src/Twig/TemplateFileAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@
*/
class TemplateFileAnalyzer extends FileAnalyzer
{
/**
* @var string
*/
private static $rootPath = 'templates';
private static string $rootPath = 'templates';

/**
* @var list<class-string>
*/
private static $extensionClasses = [];
private static array $extensionClasses = [];

/**
* @param list<class-string> $extensionClasses
Expand All @@ -37,8 +34,8 @@ public static function initExtensions(array $extensionClasses): void
}

public function analyze(
PsalmContext $file_context = null,
PsalmContext $global_context = null
?PsalmContext $file_context = null,
?PsalmContext $global_context = null
): void {
$codebase = $this->project_analyzer->getCodebase();
$taint = $codebase->taint_flow_graph;
Expand Down

0 comments on commit 257eb04

Please sign in to comment.