-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Geert Broekmans
committed
Feb 28, 2024
1 parent
68ed6b6
commit b71de31
Showing
7 changed files
with
87 additions
and
0 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
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
15 changes: 15 additions & 0 deletions
15
src/Rule/Assertion/Declaration/ShouldNotBeReadonly/IsReadonlyRule.php
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,15 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace PHPat\Rule\Assertion\Declaration\ShouldNotBeReadonly; | ||
|
||
use PHPat\Rule\Extractor\Declaration\ReadonlyExtractor; | ||
use PHPStan\Node\InClassNode; | ||
use PHPStan\Rules\Rule; | ||
|
||
/** | ||
* @implements Rule<InClassNode> | ||
*/ | ||
final class IsReadonlyRule extends ShouldNotBeReadonly implements Rule | ||
{ | ||
use ReadonlyExtractor; | ||
} |
49 changes: 49 additions & 0 deletions
49
src/Rule/Assertion/Declaration/ShouldNotBeReadonly/ShouldNotBeReadonly.php
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,49 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace PHPat\Rule\Assertion\Declaration\ShouldNotBeReadonly; | ||
|
||
use PHPat\Configuration; | ||
use PHPat\Rule\Assertion\Declaration\DeclarationAssertion; | ||
use PHPat\Rule\Assertion\Declaration\ValidationTrait; | ||
use PHPat\Statement\Builder\StatementBuilderFactory; | ||
use PHPStan\Reflection\ClassReflection; | ||
use PHPStan\Reflection\ReflectionProvider; | ||
use PHPStan\Rules\RuleError; | ||
use PHPStan\Type\FileTypeMapper; | ||
|
||
abstract class ShouldNotBeReadonly extends DeclarationAssertion | ||
{ | ||
use ValidationTrait; | ||
|
||
public function __construct( | ||
StatementBuilderFactory $statementBuilderFactory, | ||
Configuration $configuration, | ||
ReflectionProvider $reflectionProvider, | ||
FileTypeMapper $fileTypeMapper | ||
) { | ||
parent::__construct( | ||
__CLASS__, | ||
$statementBuilderFactory, | ||
$configuration, | ||
$reflectionProvider, | ||
$fileTypeMapper | ||
); | ||
} | ||
|
||
/** | ||
* @param array<string> $tips | ||
* @return array<RuleError> | ||
*/ | ||
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 be readonly', $subject) | ||
); | ||
} | ||
} |
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