Skip to content

Commit

Permalink
More callable param tests (#295)
Browse files Browse the repository at this point in the history
More tests related to bug #288

Follow-up to #294
  • Loading branch information
spaze authored Jan 24, 2025
2 parents eb3841e + 37bc8b4 commit 40eca12
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/RuleErrors/DisallowedFunctionRuleErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function get(FuncCall $node, Scope $scope, array $disallowedCalls): array
*/
public function getByString(string $name, Scope $scope, array $disallowedCalls): array
{
return $this->getErrors(new Name($name), $scope, null, null, $disallowedCalls);
return $name === '' ? [] : $this->getErrors(new Name($name), $scope, null, null, $disallowedCalls);
}


Expand Down
7 changes: 6 additions & 1 deletion tests/Bugs/Bug288DocblockTemplateCallableParamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ protected function getRule(): Rule

public function testRule(): void
{
$this->analyse([__DIR__ . '/../src/bugs/Bug288DocblockTemplateCallableParam.php'], []);
$this->analyse([__DIR__ . '/../src/bugs/Bug288DocblockTemplateCallableParam.php'], [
[
'Calling disallowedFunction() is forbidden.',
15,
],
]);
}


Expand Down
18 changes: 18 additions & 0 deletions tests/src/bugs/Bug288DocblockTemplateCallableParam.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public function testItDoesNothing(): void
{
// the $expected param here is a string param, not a callable param, no error should be reported here
$this->assertSame('disallowedFunction', 'whatever');
$this->constantStringIsCallable('disallowedFunction');
$this->callableString('');
}

/**
Expand All @@ -25,4 +27,20 @@ public function assertSame(mixed $expected, mixed $actual, string $message = '')
{
}


/**
* @param 'disallowedFunction' $callable
*/
public function constantStringIsCallable(string $callable)
{
}


/**
* @param callable-string $callable
*/
public function callableString(string $callable)
{
}

}

0 comments on commit 40eca12

Please sign in to comment.