Skip to content

Commit 78540f9

Browse files
committed
⬆️ Standardization of the rules structure
1 parent 3391874 commit 78540f9

10 files changed

+19
-16
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Ensure banned functions like `dd()` are not called.
5757

5858
*Identifier : xefi.booleanPropertyNaming*
5959

60-
Ensure that a Boolean is always named with an “is” at the beginning of its name, to clarify the condition it represents.
60+
Ensure that a Boolean is always named with an `is` at the beginning of its name, to clarify the condition it represents.
6161

6262
### Max Line Per Class Rule
6363

src/Rules/BooleanPropertyNamingRule.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public function processNode(Node $node, Scope $scope): array
2525

2626
if ($propertyType === "bool" && substr($propertyName, 0, 2 ) !== "is") {
2727
$errors[] = RuleErrorBuilder::message('A boolean property should start with "is".')
28-
->line($node->getLine())
2928
->identifier('xefi.booleanPropertyNaming')
3029
->build();
3130
}

src/Rules/MaxLinePerClassRule.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,17 @@ public function processNode(Node $node, Scope $scope): array
2828
return [
2929
RuleErrorBuilder::message(
3030
sprintf(
31-
'The %s class has more than %d code lines. Please reduce it. The recommended class length is %d lines.',
31+
'The %s class has more than %d code lines. Please reduce it.',
3232
$node->name->toString(),
33-
self::MAX_LINES,
33+
self::MAX_LINES
34+
)
35+
)
36+
->tip(
37+
sprintf(
38+
'The recommended class length is %d lines.',
3439
self::RECOMMENDED_LINES
3540
)
3641
)
37-
->line($node->getLine())
3842
->identifier('xefi.maxLinePerClass')
3943
->build(),
4044
];

src/Rules/MaxLinePerMethodRule.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,17 @@ public function processNode(Node $node, Scope $scope): array
2828
return [
2929
RuleErrorBuilder::message(
3030
sprintf(
31-
'The %s function has more than %d code lines. Please reduce it. The recommended method length is %d lines.',
31+
'The %s function has more than %d code lines. Please reduce it.',
3232
$node->name->toString(),
33-
self::MAX_LINES,
33+
self::MAX_LINES
34+
)
35+
)
36+
->tip(
37+
sprintf(
38+
'The recommended method length is %d lines.',
3439
self::RECOMMENDED_LINES
3540
)
3641
)
37-
->line($node->getLine())
3842
->identifier('xefi.maxLinePerMethod')
3943
->build(),
4044
];

src/Rules/NoBasicExceptionRule.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public function processNode(Node $node, Scope $scope): array
2121
if ($exceptionClass instanceof Node\Name && $exceptionClass->toString() === 'Exception') {
2222
return [
2323
RuleErrorBuilder::message('Basic exceptions are not allowed. Please create a custom Exception instead.')
24-
->line($node->getLine())
2524
->identifier('xefi.noBasicException')
2625
->build()
2726
];

src/Rules/NoGenericWordRule.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ public function processNode(Node $node, Scope $scope): array
6464
$varName
6565
)
6666
)
67-
->line($node->getLine())
6867
->identifier('xefi.noGenericWord')
6968
->build()
7069
];

src/Rules/NoLaravelObserverRule.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ protected function checkObserveMethod(array &$errors, Node $node) : void
3434
{
3535
if ($node instanceof Node\Expr\StaticCall && $node->name?->toString() === 'observe') {
3636
$errors[] = RuleErrorBuilder::message('Observers are forbidden because it can create technical debt. Please use Event & Listeners instead.')
37-
->line($node->getLine())
3837
->identifier(self::$ruleIdentifier)
3938
->build();
4039
}
@@ -48,7 +47,6 @@ protected function checkClassesAndNamespaces(array &$errors, Node $node, Scope $
4847

4948
if (str_ends_with($className, 'Observer') || str_contains($namespace, 'Observers')) {
5049
$errors[] = RuleErrorBuilder::message('Observers are forbidden because it can create technical debt. Please use Event & Listeners instead.')
51-
->line($node->getLine())
5250
->identifier(self::$ruleIdentifier)
5351
->build();
5452
}
@@ -62,7 +60,6 @@ protected function checkObservedByAttribute(array &$errors, Node $node) : void
6260
foreach ($attrGroup->attrs as $attr) {
6361
if ($attr->name->getParts() !== null && in_array('ObservedBy', $attr->name->getParts(), true)) {
6462
$errors[] = RuleErrorBuilder::message('Observers are forbidden because it can create technical debt. Please use Event & Listeners instead.')
65-
->line($node->getLine())
6663
->identifier(self::$ruleIdentifier)
6764
->build();
6865
break 2;

src/Rules/NoTryCatchRule.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public function processNode(Node $node, Scope $scope): array
1919
{
2020
return [
2121
RuleErrorBuilder::message("Try-catch's are forbidden. Please use Exceptions instead.")
22-
->line($node->getLine())
2322
->identifier('xefi.noTryCatch')
2423
->build(),
2524
];

tests/Rules/MaxLinePerClassRuleTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public function testRuleDumpAnException(): void
2323
// each error consists of the asserted error message, and the asserted error file line
2424
$this->analyse([__DIR__ . '/data/MaxLinePerClassRule/TwoHundredLinesClass.php'], [
2525
[
26-
"The TwoHundredLinesClass class has more than 200 code lines. Please reduce it. The recommended class length is 100 lines.", // asserted error message
26+
"The TwoHundredLinesClass class has more than 200 code lines. Please reduce it.
27+
💡 The recommended class length is 100 lines.", // asserted error message
2728
5, // asserted error line
2829
],
2930
]);

tests/Rules/MaxLinePerMethodRuleTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public function testWithMultipleLines(): void
2323
// each error consists of the asserted error message, and the asserted error file line
2424
$this->analyse([__DIR__ . '/data/MaxLinePerMethodRule/MultipleLinesMethods.php'], [
2525
[
26-
"The fortyOneLines function has more than 40 code lines. Please reduce it. The recommended method length is 20 lines.", // asserted error message
26+
"The fortyOneLines function has more than 40 code lines. Please reduce it.
27+
💡 The recommended method length is 20 lines.", // asserted error message
2728
93, // asserted error line
2829
],
2930
]);

0 commit comments

Comments
 (0)