Skip to content

Commit d039f80

Browse files
committed
feat: add identifiers for PhpStan 2
1 parent d0ed97e commit d039f80

5 files changed

Lines changed: 15 additions & 19 deletions

src/Rule/DisallowDefaultContextCreation.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ public function getNodeType(): string
2525

2626
public function processNode(Node $node, Scope $scope): array
2727
{
28-
if (!$node instanceof StaticCall) {
29-
return [];
30-
}
31-
3228
if (!$node->name instanceof Node\Identifier) {
3329
return [];
3430
}
@@ -55,6 +51,7 @@ public function processNode(Node $node, Scope $scope): array
5551
RuleErrorBuilder::message(sprintf('Do not use %s::createDefaultContext() function in code.', $node->class->toString()))
5652
->addTip('If you are in a CLI context, use %s::createCliContext() instead.')
5753
->addTip('If you are in a web context, pass down the context from the controller.')
54+
->identifier('shopware.disallow.default.context.creation')
5855
->build(),
5956
];
6057
}

src/Rule/DisallowFunctionsRule.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ public function getNodeType(): string
3434
*/
3535
public function processNode(Node $node, Scope $scope): array
3636
{
37-
if (!$node instanceof FuncCall) {
38-
return [];
39-
}
40-
4137
if (!$node->name instanceof Node\Name) {
4238
return [];
4339
}
@@ -46,7 +42,10 @@ public function processNode(Node $node, Scope $scope): array
4642

4743
if (\in_array($name, self::NOT_ALLOWED_FUNCTIONS, true)) {
4844
return [
49-
RuleErrorBuilder::message(\sprintf('Do not use %s function in code.', $name))->build(),
45+
RuleErrorBuilder::message(\sprintf('Do not use %s function in code.', $name))
46+
->line($node->getLine())
47+
->identifier('shopware.disallow_functions')
48+
->build(),
5049
];
5150
}
5251

src/Rule/InternalFunctionCallRule.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use PHPStan\Analyser\Scope;
1212
use PHPStan\Reflection\ReflectionProvider;
1313
use PHPStan\Rules\Rule;
14+
use PHPStan\Rules\RuleErrorBuilder;
1415
use Shopware\PhpStan\Helper\NamespaceChecker;
1516

1617
/**
@@ -34,8 +35,6 @@ public function getNodeType(): string
3435

3536
public function processNode(Node $node, Scope $scope): array
3637
{
37-
assert($node instanceof FuncCall);
38-
3938
if (!$node->name instanceof Node\Name) {
4039
return [];
4140
}
@@ -54,7 +53,10 @@ public function processNode(Node $node, Scope $scope): array
5453
}
5554

5655
return [
57-
sprintf('Call of internal function %s Please refrain from using functions which are annotated with @internal in the Shopware 6 repository.', $function->getName()),
56+
RuleErrorBuilder::message(sprintf('Call of internal function %s Please refrain from using functions which are annotated with @internal in the Shopware 6 repository.', $function->getName()))
57+
->line($node->getLine())
58+
->identifier('shopware.internal_function_call')
59+
->build(),
5860
];
5961
}
6062
}

src/Rule/InternalMethodCallRule.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use PHPStan\Reflection\MissingMethodFromReflectionException;
1414
use PHPStan\Reflection\ReflectionProvider;
1515
use PHPStan\Rules\Rule;
16+
use PHPStan\Rules\RuleErrorBuilder;
1617
use Shopware\PhpStan\Helper\NamespaceChecker;
1718

1819
/**
@@ -31,8 +32,6 @@ public function getNodeType(): string
3132

3233
public function processNode(Node $node, Scope $scope): array
3334
{
34-
assert($node instanceof MethodCall);
35-
3635
if (!$node->name instanceof Identifier) {
3736
return [];
3837
}
@@ -63,7 +62,9 @@ public function processNode(Node $node, Scope $scope): array
6362
}
6463
if (!NamespaceChecker::arePartOfTheSamePackage($scope->getNamespace(), $methodOwnerNamespace)) {
6564
return [
66-
sprintf('Call of internal method %s::%s Please refrain from using methods which are annotated with @internal in the Shopware 6 repository.', $classInfo->getName(), $methodDetails->getName()),
65+
RuleErrorBuilder::message(sprintf('Call of internal method %s::%s Please refrain from using methods which are annotated with @internal in the Shopware 6 repository.', $classInfo->getName(), $methodDetails->getName()))
66+
->identifier('shopware.internal_method_call')
67+
->build(),
6768
];
6869
}
6970
}

src/Rule/SetForeignKeyRule.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ public function getNodeType(): string
2323

2424
public function processNode(Node $node, Scope $scope): array
2525
{
26-
if (!$node instanceof Node\Stmt\ClassMethod) {
27-
return [];
28-
}
29-
3026
if ($node->name->name !== 'update') {
3127
return [];
3228
}
@@ -52,6 +48,7 @@ public function processNode(Node $node, Scope $scope): array
5248
if (str_contains($string->value, 'FOREIGN_KEY_CHECKS')) {
5349
$errors[] = RuleErrorBuilder::message('Do not disable FOREIGN KEY checks in migrations. Delete the data in the right order')
5450
->line($string->getLine())
51+
->identifier('shopware.foreign.key.checks')
5552
->build();
5653
}
5754
}

0 commit comments

Comments
 (0)