Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Rules/Symfony/SingleArgEventDispatchRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,21 @@ public function processNode(Node $node, Scope $scope): array
return [];
}

$args = $node->getArgs();

// all good
if (count($node->getArgs()) === 1) {
if (count($args) === 1) {
return [];
}

// allow 2nd arg when dynamic, e.g. a variable event name
if (count($args) === 2) {
$secondArgType = $scope->getType($args[1]->value);
if ($secondArgType->getConstantStrings() === []) {
return [];
}
}

$callerType = $scope->getType($node->var);
if (! $callerType instanceof ObjectType) {
return [];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Symplify\PHPStanRules\Tests\Rules\Symfony\SingleArgEventDispatchRule\Fixture;

use Symfony\Component\EventDispatcher\EventDispatcherInterface;

final class SkipDynamicSecondArg
{
public function run(EventDispatcherInterface $eventDispatcher, object $event, string $name)
{
$eventDispatcher->dispatch($event, $name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public static function provideData(): Iterator

yield [__DIR__ . '/Fixture/SkipSingleDispatch.php', []];
yield [__DIR__ . '/Fixture/SkipUnrelatedDispatch.php', []];
yield [__DIR__ . '/Fixture/SkipDynamicSecondArg.php', []];
}

protected function getRule(): Rule
Expand Down
Loading