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
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"editorconfig-checker/editorconfig-checker": "^10.6.0",
"ergebnis/composer-normalize": "^2.28",
"nette/neon": "^3.3.1",
"phpstan/phpstan-deprecation-rules": "^1.2",
"phpstan/phpstan-phpunit": "^1.4.0",
"phpstan/phpstan-strict-rules": "^1.6.0",
"phpunit/phpunit": "^9.5.20",
Expand Down
49 changes: 48 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ includes:
- ./vendor/phpstan/phpstan-strict-rules/rules.neon
- ./vendor/phpstan/phpstan-phpunit/extension.neon
- ./vendor/phpstan/phpstan-phpunit/rules.neon
- ./vendor/phpstan/phpstan-deprecation-rules/rules.neon
- ./vendor/shipmonk/dead-code-detector/rules.neon
- ./rules.neon

Expand Down
2 changes: 1 addition & 1 deletion src/Rule/EnforceClosureParamNativeTypehintRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function processNode(

$errors[] = RuleErrorBuilder::message("Missing parameter typehint for {$type} parameter \${$param->var->name}.")
->identifier('shipmonk.unknownClosureParamType')
->line($param->getLine())
->line($param->getStartLine())
->build();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Rule/EnforceIteratorToArrayPreserveKeysRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function processNode(Node $node, Scope $scope): array
}

return [RuleErrorBuilder::message('Calling iterator_to_array without 2nd parameter $preserve_keys. Default value true might cause failures or data loss.')
->line($node->getLine())
->line($node->getStartLine())
->identifier('shipmonk.iteratorToArrayWithoutPreserveKeys')
->build()];
}
Expand Down
6 changes: 3 additions & 3 deletions src/Rule/ForbidCheckedExceptionInCallableRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function processFirstClassCallable(
}

$errors = [];
$line = $callNode->getLine();
$line = $callNode->getStartLine();

if ($callNode instanceof MethodCall && $callNode->name instanceof Identifier) {
$callerType = $scope->getType($callNode->var);
Expand Down Expand Up @@ -208,7 +208,7 @@ public function processClosure(
$errors[] = $this->buildError(
$exceptionClass,
'closure',
$throwPoint->getNode()->getLine(),
$throwPoint->getNode()->getStartLine(),
$this->callablesInArguments[$nodeHash] ?? null,
);
}
Expand Down Expand Up @@ -257,7 +257,7 @@ static function (): void {
$errors[] = $this->buildError(
$exceptionClass,
'arrow function',
$throwPoint->getNode()->getLine(),
$throwPoint->getNode()->getStartLine(),
$this->callablesInArguments[$nodeHash] ?? null,
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/ForbidCheckedExceptionInYieldingMethodRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function processNode(
foreach ($throwPoint->getType()->getObjectClassNames() as $exceptionClass) {
if ($this->exceptionTypeResolver->isCheckedException($exceptionClass, $throwPoint->getScope())) {
$errors[] = RuleErrorBuilder::message("Throwing checked exception $exceptionClass in yielding method is denied as it gets thrown upon Generator iteration")
->line($throwPoint->getNode()->getLine())
->line($throwPoint->getNode()->getStartLine())
->identifier('shipmonk.checkedExceptionInYieldingMethod')
->build();
}
Expand Down
6 changes: 3 additions & 3 deletions src/Rule/ForbidNotNormalizedTypeRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,15 +530,15 @@ private function processMultiTypePhpParserNode(

if ($typeA->isSuperTypeOf($typeB)->yes()) {
$errors[] = RuleErrorBuilder::message("Found non-normalized type {$multiTypeNodeString} for {$identification}: {$typeNodeBString} is a subtype of {$typeNodeAString}.")
->line($multiTypeNode->getLine())
->line($multiTypeNode->getStartLine())
->identifier('shipmonk.nonNormalizedType')
->build();
continue;
}

if ($typeB->isSuperTypeOf($typeA)->yes()) {
$errors[] = RuleErrorBuilder::message("Found non-normalized type {$multiTypeNodeString} for {$identification}: {$typeNodeAString} is a subtype of {$typeNodeBString}.")
->line($multiTypeNode->getLine())
->line($multiTypeNode->getStartLine())
->identifier('shipmonk.nonNormalizedType')
->build();
}
Expand Down Expand Up @@ -645,7 +645,7 @@ private function getPhpDocLine(PhpParserNode $node, PhpDocRootNode $phpDocNode):
$phpDoc = $node->getDocComment();

if ($phpDocTagLine === null || $phpDoc === null) {
return $node->getLine();
return $node->getStartLine();
}

return $phpDoc->getStartLine() + $phpDocTagLine - 1;
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/ForbidProtectedEnumMethodRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function processNode(Node $node, Scope $scope): array
&& !$classMethod->isDeclaredInTrait()
) {
$errors[] = RuleErrorBuilder::message('Protected methods within enum makes no sense as you cannot extend them anyway.')
->line($classMethod->getLine())
->line($classMethod->getStartLine())
->identifier('shipmonk.protectedEnumMethod')
->build();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/ForbidReturnValueInYieldingMethodRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function processNode(
: 'function';

$errors[] = RuleErrorBuilder::message("Returned value from yielding $callType can be accessed only via Generator::getReturn, $suffix.")
->line($returnNode->getLine())
->line($returnNode->getStartLine())
->identifier('shipmonk.returnValueFromYieldingMethod')
->build();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/RequirePreviousExceptionPassRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private function processExceptionCreation(
if (!$passed && $accepts) {
$exceptionName = $caughtExceptionVariableName === null ? "({$caughtExceptionType->describe(VerbosityLevel::typeOnly())})" : "\${$caughtExceptionVariableName}";
$error = RuleErrorBuilder::message("Exception {$exceptionName} not passed as previous to {$this->printer->prettyPrintExpr($node)}")
->line($node->getLine())
->line($node->getStartLine())
->identifier('shipmonk.missingPreviousException')
->build();
return [$error];
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/UselessPrivatePropertyDefaultValueRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function processNode(Node $node, Scope $scope): array

if (isset($noDefaultValueNeededProperties[$propertyName])) {
$errors[] = RuleErrorBuilder::message("Property {$className}::{$propertyName} has useless default value (overwritten in constructor)")
->line($property->getLine())
->line($property->getStartLine())
->identifier('shipmonk.uselessPrivatePropertyDefaultValue')
->build();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rule/UselessPrivatePropertyNullabilityRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function processNode(Node $node, Scope $scope): array

if ($definitionHasTypehint && $definitionIsNullable && !$nullIsAssigned && !$hasNullDefaultValue && !$isUninitialized) {
$errors[] = RuleErrorBuilder::message("Property {$className}::{$propertyName} is defined as nullable, but null is never assigned")
->line($property->getLine())
->line($property->getStartLine())
->identifier('shipmonk.uselessPrivatePropertyNullability')
->build();
}
Expand Down
Loading