Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
"phpstan/phpstan-phpunit": "^2.0.4",
"phpstan/phpstan-strict-rules": "^2.0.3",
"phpunit/phpunit": "^9.6.22",
"shipmonk/coding-standard": "^0.1.3",
"shipmonk/composer-dependency-analyser": "^1.8.1",
"shipmonk/dead-code-detector": "^0.9.0",
"shipmonk/name-collision-detector": "^2.1.1",
"slevomat/coding-standard": "^8.16.0"
"shipmonk/name-collision-detector": "^2.1.1"
},
"autoload": {
"psr-4": {
Expand Down
391 changes: 167 additions & 224 deletions composer.lock

Large diffs are not rendered by default.

416 changes: 5 additions & 411 deletions phpcs.xml.dist

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions src/Rule/AllowComparingOnlyComparableTypesRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ public function getNodeType(): string
* @param BinaryOp $node
* @return list<IdentifierRuleError>
*/
public function processNode(Node $node, Scope $scope): array
public function processNode(
Node $node,
Scope $scope
): array
{
if (
!$node instanceof Greater
Expand Down Expand Up @@ -99,7 +102,10 @@ private function isComparable(Type $type): bool
return true;
}

private function isComparableTogether(Type $leftType, Type $rightType): bool
private function isComparableTogether(
Type $leftType,
Type $rightType
): bool
{
$intType = new IntegerType();
$floatType = new FloatType();
Expand Down Expand Up @@ -149,7 +155,10 @@ private function isComparableTogether(Type $leftType, Type $rightType): bool
/**
* @param Type[] $allowedTypes
*/
private function containsOnlyTypes(Type $checkedType, array $allowedTypes): bool
private function containsOnlyTypes(
Type $checkedType,
array $allowedTypes
): bool
{
$allowedType = TypeCombinator::union(...$allowedTypes);
return $allowedType->isSuperTypeOf($checkedType)->yes();
Expand Down
10 changes: 8 additions & 2 deletions src/Rule/BackedEnumGenericsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ public function getNodeType(): string
* @param InClassNode $node
* @return list<IdentifierRuleError>
*/
public function processNode(Node $node, Scope $scope): array
public function processNode(
Node $node,
Scope $scope
): array
{
$classReflection = $node->getClassReflection();
$backedEnumType = $classReflection->getBackedEnumType();
Expand Down Expand Up @@ -55,7 +58,10 @@ public function processNode(Node $node, Scope $scope): array
return [$error];
}

private function hasGenericsTag(ClassReflection $classReflection, string $expectedTag): bool
private function hasGenericsTag(
ClassReflection $classReflection,
string $expectedTag
): bool
{
if ($classReflection->isBackedEnum()) {
$tags = $classReflection->getImplementsTags();
Expand Down
5 changes: 4 additions & 1 deletion src/Rule/ClassSuffixNamingRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ class ClassSuffixNamingRule implements Rule
/**
* @param array<class-string, string> $superclassToSuffixMapping
*/
public function __construct(ReflectionProvider $reflectionProvider, array $superclassToSuffixMapping = [])
public function __construct(
ReflectionProvider $reflectionProvider,
array $superclassToSuffixMapping = []
)
{
foreach ($superclassToSuffixMapping as $className => $suffix) {
if (!$reflectionProvider->hasClass($className)) {
Expand Down
5 changes: 4 additions & 1 deletion src/Rule/EnforceEnumMatchRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ public function getNodeType(): string
* @param BinaryOp $node
* @return list<IdentifierRuleError>
*/
public function processNode(Node $node, Scope $scope): array
public function processNode(
Node $node,
Scope $scope
): array
{
if (!$node instanceof Identical && !$node instanceof NotIdentical) {
return [];
Expand Down
5 changes: 4 additions & 1 deletion src/Rule/EnforceIteratorToArrayPreserveKeysRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ public function getNodeType(): string
* @param FuncCall $node
* @return list<IdentifierRuleError>
*/
public function processNode(Node $node, Scope $scope): array
public function processNode(
Node $node,
Scope $scope
): array
{
if (!$node->name instanceof Name) {
return [];
Expand Down
5 changes: 4 additions & 1 deletion src/Rule/EnforceListReturnRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ public function getNodeType(): string
* @param ReturnStatementsNode $node
* @return list<IdentifierRuleError>
*/
public function processNode(Node $node, Scope $scope): array
public function processNode(
Node $node,
Scope $scope
): array
{
$methodReflection = $scope->getFunction();

Expand Down
10 changes: 8 additions & 2 deletions src/Rule/EnforceNativeReturnTypehintRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ public function getNodeType(): string
* @param ReturnStatementsNode $node
* @return list<IdentifierRuleError>
*/
public function processNode(Node $node, Scope $scope): array
public function processNode(
Node $node,
Scope $scope
): array
{
if ($this->treatPhpDocTypesAsCertain === false) {
return [];
Expand Down Expand Up @@ -202,7 +205,10 @@ private function getTypeOfReturnStatements(ReturnStatementsNode $node): Type
return TypeCombinator::union(...$types);
}

private function getPhpDocReturnType(Node $node, Scope $scope): ?Type
private function getPhpDocReturnType(
Node $node,
Scope $scope
): ?Type
{
$docComment = $node->getDocComment();

Expand Down
5 changes: 4 additions & 1 deletion src/Rule/EnforceReadonlyPublicPropertyRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ public function getNodeType(): string
* @param ClassPropertyNode $node
* @return list<IdentifierRuleError>
*/
public function processNode(Node $node, Scope $scope): array
public function processNode(
Node $node,
Scope $scope
): array
{
if (!$this->phpVersion->supportsReadOnlyProperties()) {
return [];
Expand Down
25 changes: 21 additions & 4 deletions src/Rule/ForbidArithmeticOperationOnNonNumberRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ public function getNodeType(): string
/**
* @return list<IdentifierRuleError>
*/
public function processNode(Node $node, Scope $scope): array
public function processNode(
Node $node,
Scope $scope
): array
{
if (
$node instanceof UnaryPlus
Expand All @@ -70,7 +73,11 @@ public function processNode(Node $node, Scope $scope): array
/**
* @return list<IdentifierRuleError>
*/
private function processUnary(Expr $expr, Scope $scope, string $operator): array
private function processUnary(
Expr $expr,
Scope $scope,
string $operator
): array
{
$exprType = $scope->getType($expr);

Expand All @@ -92,7 +99,12 @@ private function processUnary(Expr $expr, Scope $scope, string $operator): array
/**
* @return list<IdentifierRuleError>
*/
private function processBinary(Expr $left, Expr $right, Scope $scope, string $operator): array
private function processBinary(
Expr $left,
Expr $right,
Scope $scope,
string $operator
): array
{
$leftType = $scope->getType($left);
$rightType = $scope->getType($right);
Expand Down Expand Up @@ -130,7 +142,12 @@ private function isNumeric(Type $type): bool
/**
* @return list<IdentifierRuleError>
*/
private function buildBinaryErrors(string $operator, string $type, Type $leftType, Type $rightType): array
private function buildBinaryErrors(
string $operator,
string $type,
Type $leftType,
Type $rightType
): array
{
$errorMessage = sprintf(
'Using %s over %s (%s %s %s)',
Expand Down
5 changes: 4 additions & 1 deletion src/Rule/ForbidCastRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ public function getNodeType(): string
* @param Cast $node
* @return list<IdentifierRuleError>
*/
public function processNode(Node $node, Scope $scope): array
public function processNode(
Node $node,
Scope $scope
): array
{
$castString = $this->getCastString($node);

Expand Down
21 changes: 17 additions & 4 deletions src/Rule/ForbidCheckedExceptionInCallableRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,10 @@ private function checkClassExistence(
*
* @param FunctionReflection|MethodReflection $reflection
*/
private function isImmediatelyInvokedCallable(object $reflection, ?ParameterReflection $parameter): bool
private function isImmediatelyInvokedCallable(
object $reflection,
?ParameterReflection $parameter
): bool
{
if ($parameter instanceof ExtendedParameterReflection) {
$parameterCallImmediately = $parameter->isImmediatelyInvokedCallable();
Expand Down Expand Up @@ -411,7 +414,10 @@ private function isAllowedCheckedExceptionCallable(
return false;
}

private function whitelistAllowedCallables(CallLike $node, Scope $scope): void
private function whitelistAllowedCallables(
CallLike $node,
Scope $scope
): void
{
if ($node instanceof MethodCall && $node->name instanceof Identifier) {
$callerType = $scope->getType($node->var);
Expand Down Expand Up @@ -491,7 +497,11 @@ private function whitelistAllowedCallables(CallLike $node, Scope $scope): void
/**
* @param array<int, ParameterReflection> $parameters
*/
private function getParameterIndex(Arg $arg, int $argumentIndex, array $parameters): ?int
private function getParameterIndex(
Arg $arg,
int $argumentIndex,
array $parameters
): ?int
{
if ($arg->name === null) {
return $argumentIndex;
Expand Down Expand Up @@ -534,7 +544,10 @@ private function buildError(
return $builder->build();
}

private function getFunctionReflection(Name $functionName, Scope $scope): ?FunctionReflection
private function getFunctionReflection(
Name $functionName,
Scope $scope
): ?FunctionReflection
{
return $this->reflectionProvider->hasFunction($functionName, $scope)
? $this->reflectionProvider->getFunction($functionName, $scope)
Expand Down
Loading