-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check just one callable parameter variant (#293)
As suggested in #288 (comment) Close #288
- Loading branch information
Showing
3 changed files
with
95 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace Spaze\PHPStan\Rules\Disallowed\Calls; | ||
|
||
use PHPStan\Reflection\ReflectionProvider; | ||
use PHPStan\Rules\Rule; | ||
use PHPStan\ShouldNotHappenException; | ||
use PHPStan\Testing\RuleTestCase; | ||
use Spaze\PHPStan\Rules\Disallowed\DisallowedCallFactory; | ||
use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedCallableParameterRuleErrors; | ||
use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedFunctionRuleErrors; | ||
use Spaze\PHPStan\Rules\Disallowed\RuleErrors\DisallowedMethodRuleErrors; | ||
use Spaze\PHPStan\Rules\Disallowed\Type\TypeResolver; | ||
|
||
class Bug288DocblockTemplateCallableParamTest extends RuleTestCase | ||
{ | ||
|
||
/** | ||
* @throws ShouldNotHappenException | ||
*/ | ||
protected function getRule(): Rule | ||
{ | ||
$container = self::getContainer(); | ||
$disallowedCallableParameterRuleErrors = new DisallowedCallableParameterRuleErrors( | ||
$container->getByType(TypeResolver::class), | ||
$container->getByType(DisallowedFunctionRuleErrors::class), | ||
$container->getByType(DisallowedMethodRuleErrors::class), | ||
$container->getByType(DisallowedCallFactory::class), | ||
$container->getByType(ReflectionProvider::class), | ||
[ | ||
[ | ||
'function' => 'disallowedFunction()', | ||
], | ||
], | ||
[], | ||
[], | ||
); | ||
return new MethodCalls( | ||
$container->getByType(DisallowedMethodRuleErrors::class), | ||
$disallowedCallableParameterRuleErrors, | ||
$container->getByType(DisallowedCallFactory::class), | ||
[], | ||
); | ||
} | ||
|
||
|
||
public function testRule(): void | ||
{ | ||
$this->analyse([__DIR__ . '/../src/bugs/Bug288DocblockTemplateCallableParam.php'], []); | ||
} | ||
|
||
|
||
public static function getAdditionalConfigFiles(): array | ||
{ | ||
return [ | ||
__DIR__ . '/../../extension.neon', | ||
]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
function disallowedFunction() | ||
{ | ||
} | ||
|
||
class Bug288DocblockTemplateCallableParam | ||
{ | ||
|
||
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'); | ||
} | ||
|
||
/** | ||
* A copy of PHPUnit\Framework\Assert::assertSame()'s docblock | ||
* | ||
* @template ExpectedType | ||
* @param ExpectedType $expected | ||
* @phpstan-assert =ExpectedType $actual | ||
*/ | ||
public function assertSame(mixed $expected, mixed $actual, string $message = ''): void | ||
{ | ||
} | ||
|
||
} |