-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace PHPat\Rule\Assertion\Declaration\ShouldNotExist; | ||
|
||
use PHPat\Configuration; | ||
use PHPat\Rule\Assertion\Declaration\DeclarationAssertion; | ||
use PHPat\Rule\Assertion\Declaration\ValidationTrait; | ||
use PHPat\Statement\Builder\StatementBuilderFactory; | ||
use PhpParser\Node; | ||
use PHPStan\Analyser\Scope; | ||
use PHPStan\Node\InClassNode; | ||
use PHPStan\Reflection\ClassReflection; | ||
use PHPStan\Reflection\ReflectionProvider; | ||
use PHPStan\Rules\Rule; | ||
use PHPStan\Type\FileTypeMapper; | ||
|
||
/** | ||
* @implements Rule<InClassNode> | ||
*/ | ||
final class ShouldNotExist extends DeclarationAssertion implements Rule | ||
Check failure on line 20 in src/Rule/Assertion/Declaration/ShouldNotExist/ShouldNotExist.php GitHub Actions / Static Code and Architecture analysis (8.2, highest)
Check failure on line 20 in src/Rule/Assertion/Declaration/ShouldNotExist/ShouldNotExist.php GitHub Actions / Static Code and Architecture analysis (8.2, highest)
Check failure on line 20 in src/Rule/Assertion/Declaration/ShouldNotExist/ShouldNotExist.php GitHub Actions / Static Code and Architecture analysis (8.0, highest)
Check failure on line 20 in src/Rule/Assertion/Declaration/ShouldNotExist/ShouldNotExist.php GitHub Actions / Static Code and Architecture analysis (8.0, highest)
Check failure on line 20 in src/Rule/Assertion/Declaration/ShouldNotExist/ShouldNotExist.php GitHub Actions / Static Code and Architecture analysis (8.1, highest)
Check failure on line 20 in src/Rule/Assertion/Declaration/ShouldNotExist/ShouldNotExist.php GitHub Actions / Static Code and Architecture analysis (8.1, highest)
Check failure on line 20 in src/Rule/Assertion/Declaration/ShouldNotExist/ShouldNotExist.php GitHub Actions / Static Code and Architecture analysis (7.4, highest)
Check failure on line 20 in src/Rule/Assertion/Declaration/ShouldNotExist/ShouldNotExist.php GitHub Actions / Static Code and Architecture analysis (7.4, highest)
|
||
{ | ||
use ValidationTrait; | ||
|
||
public function __construct( | ||
StatementBuilderFactory $statementBuilderFactory, | ||
Check failure on line 25 in src/Rule/Assertion/Declaration/ShouldNotExist/ShouldNotExist.php GitHub Actions / Static Code and Architecture analysis (8.2, highest)
Check failure on line 25 in src/Rule/Assertion/Declaration/ShouldNotExist/ShouldNotExist.php GitHub Actions / Static Code and Architecture analysis (8.0, highest)
Check failure on line 25 in src/Rule/Assertion/Declaration/ShouldNotExist/ShouldNotExist.php GitHub Actions / Static Code and Architecture analysis (8.1, highest)
Check failure on line 25 in src/Rule/Assertion/Declaration/ShouldNotExist/ShouldNotExist.php GitHub Actions / Static Code and Architecture analysis (7.4, highest)
|
||
Configuration $configuration, | ||
Check failure on line 26 in src/Rule/Assertion/Declaration/ShouldNotExist/ShouldNotExist.php GitHub Actions / Static Code and Architecture analysis (8.2, highest)
Check failure on line 26 in src/Rule/Assertion/Declaration/ShouldNotExist/ShouldNotExist.php GitHub Actions / Static Code and Architecture analysis (8.0, highest)
Check failure on line 26 in src/Rule/Assertion/Declaration/ShouldNotExist/ShouldNotExist.php GitHub Actions / Static Code and Architecture analysis (8.1, highest)
Check failure on line 26 in src/Rule/Assertion/Declaration/ShouldNotExist/ShouldNotExist.php GitHub Actions / Static Code and Architecture analysis (7.4, highest)
|
||
ReflectionProvider $reflectionProvider, | ||
FileTypeMapper $fileTypeMapper | ||
) { | ||
parent::__construct( | ||
Check failure on line 30 in src/Rule/Assertion/Declaration/ShouldNotExist/ShouldNotExist.php GitHub Actions / Static Code and Architecture analysis (8.2, highest)
Check failure on line 30 in src/Rule/Assertion/Declaration/ShouldNotExist/ShouldNotExist.php GitHub Actions / Static Code and Architecture analysis (8.0, highest)
Check failure on line 30 in src/Rule/Assertion/Declaration/ShouldNotExist/ShouldNotExist.php GitHub Actions / Static Code and Architecture analysis (8.1, highest)
Check failure on line 30 in src/Rule/Assertion/Declaration/ShouldNotExist/ShouldNotExist.php GitHub Actions / Static Code and Architecture analysis (7.4, highest)
|
||
__CLASS__, | ||
$statementBuilderFactory, | ||
$configuration, | ||
$reflectionProvider, | ||
$fileTypeMapper | ||
); | ||
} | ||
|
||
public function getNodeType(): string | ||
{ | ||
return InClassNode::class; | ||
} | ||
|
||
protected function applyValidation(string $ruleName, ClassReflection $subject, bool $meetsDeclaration, array $tips, array $params = []): array | ||
{ | ||
return $this->applyShouldNot($ruleName, $subject, $meetsDeclaration, $tips, $params); | ||
} | ||
|
||
protected function getMessage(string $ruleName, string $subject, array $params = []): string | ||
{ | ||
return $this->prepareMessage( | ||
$ruleName, | ||
sprintf('%s should not exist', $subject) | ||
); | ||
} | ||
|
||
protected function meetsDeclaration(Node $node, Scope $scope, array $params = []): bool | ||
{ | ||
return true; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Tests\PHPat\unit\rules\ShouldNotExist; | ||
|
||
use PHPat\Configuration; | ||
use PHPat\Rule\Assertion\Declaration\ShouldNotExist\ShouldNotExist; | ||
use PHPat\Selector\Classname; | ||
use PHPat\Statement\Builder\StatementBuilderFactory; | ||
use PHPStan\Rules\Rule; | ||
use PHPStan\Testing\RuleTestCase; | ||
use PHPStan\Type\FileTypeMapper; | ||
use Tests\PHPat\fixtures\FixtureClass; | ||
use Tests\PHPat\unit\FakeTestParser; | ||
|
||
/** | ||
* @extends RuleTestCase<ShouldNotExist> | ||
* @internal | ||
* @coversNothing | ||
*/ | ||
class ShouldNotExistTest extends RuleTestCase | ||
{ | ||
public const RULE_NAME = 'test_FixtureClassShouldNotExist'; | ||
|
||
public function testRule(): void | ||
{ | ||
$this->analyse(['tests/fixtures/FixtureClass.php'], [ | ||
[sprintf('%s should not exist', FixtureClass::class), 29], | ||
]); | ||
} | ||
|
||
protected function getRule(): Rule | ||
{ | ||
$testParser = FakeTestParser::create( | ||
self::RULE_NAME, | ||
ShouldNotExist::class, | ||
[new Classname(FixtureClass::class, false)], | ||
[] | ||
); | ||
|
||
return new ShouldNotExist( | ||
new StatementBuilderFactory($testParser), | ||
new Configuration(false, true, false), | ||
$this->createReflectionProvider(), | ||
self::getContainer()->getByType(FileTypeMapper::class) | ||
); | ||
} | ||
} |