mirror of
https://github.com/composer/composer
synced 2025-05-09 00:22:53 +00:00
Added PHPStan rule that checks we don't use $this in closures.
This commit is contained in:
parent
406a28708f
commit
e5b13b4c8f
6 changed files with 125 additions and 2 deletions
28
phpstan/Rules/tests/AnonymousFunctionWithThisRuleTest.php
Normal file
28
phpstan/Rules/tests/AnonymousFunctionWithThisRuleTest.php
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?php declare(strict_types = 1);
|
||||
|
||||
namespace Composer\PHPStanRulesTests;
|
||||
|
||||
use Composer\PHPStanRules\AnonymousFunctionWithThisRule;
|
||||
use PHPStan\Testing\RuleTestCase;
|
||||
|
||||
/**
|
||||
* @phpstan-extends RuleTestCase<AnonymousFunctionWithThisRule>
|
||||
*/
|
||||
final class AnonymousFunctionWithThisRuleTest extends RuleTestCase
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function getRule(): \PHPStan\Rules\Rule
|
||||
{
|
||||
return new AnonymousFunctionWithThisRule();
|
||||
}
|
||||
|
||||
public function testWithThis(): void
|
||||
{
|
||||
$this->analyse([__DIR__ . '/data/method-with-this.php'], [
|
||||
['Using $this inside anonymous function is prohibited because of PHP 5.3 support.', 13],
|
||||
['Using $this inside anonymous function is prohibited because of PHP 5.3 support.', 17],
|
||||
]);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue