Skip to content

Commit 65ff3b0

Browse files
authored
Merge pull request #3 from Simtel/2.0.2
2.0.2
2 parents 5f4b587 + c849543 commit 65ff3b0

14 files changed

Lines changed: 99 additions & 58 deletions

.gitattributes

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/.github export-ignore
2+
/tests export-ignore
3+
/.gitattributes export-ignore
4+
/.gitignore export-ignore
5+
/phpstan.neon export-ignore
6+
/phpunit.xml.dist export-ignore
7+
/ecs.php export-ignore

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
}
2121
},
2222
"require-dev": {
23-
"phpunit/phpunit": "^12.0"
23+
"phpunit/phpunit": "^12.0",
24+
"symplify/easy-coding-standard": "^12.5"
2425
}
2526
}

composer.lock

Lines changed: 62 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Rule/CommandClassShouldBeHelpCommandHandlerClass.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
*/
2020
final class CommandClassShouldBeHelpCommandHandlerClass implements Rule
2121
{
22-
2322
public function __construct(
2423
private readonly PhpDocParser $parser,
2524
private readonly Lexer $phpDocLexer,
@@ -44,7 +43,7 @@ public function processNode(Node $node, Scope $scope): array
4443
$className = $node->name->name;
4544
}
4645

47-
if (!str_ends_with($className, 'Command')) {
46+
if (! str_ends_with($className, 'Command')) {
4847
return [];
4948
}
5049

@@ -70,7 +69,7 @@ public function processNode(Node $node, Scope $scope): array
7069
if ($tag->value instanceof GenericTagValueNode) {
7170
$find = true;
7271
$value = $tag->value->value;
73-
if (!str_ends_with($value, 'CommandHandler')) {
72+
if (! str_ends_with($value, 'CommandHandler')) {
7473
return [
7574
RuleErrorBuilder::message(
7675
sprintf(
@@ -92,5 +91,4 @@ public function processNode(Node $node, Scope $scope): array
9291

9392
return [];
9493
}
95-
9694
}

src/Rule/EventListenerClassShouldBeIncludeAsListenerAttribute.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
*/
1717
final class EventListenerClassShouldBeIncludeAsListenerAttribute implements Rule
1818
{
19-
20-
public function __construct(private readonly ReflectionProvider $reflectionProvider)
21-
{
19+
public function __construct(
20+
private readonly ReflectionProvider $reflectionProvider
21+
) {
2222
}
2323

2424
public function getNodeType(): string
@@ -39,7 +39,7 @@ public function processNode(Node $node, Scope $scope): array
3939
$className = $node->name->name;
4040
}
4141

42-
if (!str_ends_with($className, 'EventListener')) {
42+
if (! str_ends_with($className, 'EventListener')) {
4343
return [];
4444
}
4545

@@ -61,8 +61,9 @@ public function processNode(Node $node, Scope $scope): array
6161

6262
if ($find === false) {
6363
return [
64-
RuleErrorBuilder::message('Event listener class should be include attribute #[AsEventListener]')->build(
65-
),
64+
RuleErrorBuilder::message(
65+
'Event listener class should be include attribute #[AsEventListener]'
66+
)->build(),
6667
];
6768
}
6869

src/Rule/NotShouldPhpdocReturnIfExistTypeHint.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@
1313
use PHPStan\PhpDocParser\Parser\TokenIterator;
1414
use PHPStan\Reflection\ReflectionProvider;
1515
use PHPStan\Rules\Rule;
16-
use PHPStan\ShouldNotHappenException;
1716

1817
/**
1918
* @implements Rule<Class_>
2019
*/
2120
final class NotShouldPhpdocReturnIfExistTypeHint implements Rule
2221
{
23-
2422
public function __construct(
2523
private readonly ReflectionProvider $reflectionProvider,
2624
private readonly PhpDocParser $parser,
@@ -33,9 +31,6 @@ public function getNodeType(): string
3331
return Class_::class;
3432
}
3533

36-
/**
37-
* @throws ShouldNotHappenException
38-
*/
3934
public function processNode(Node $node, Scope $scope): array
4035
{
4136
$fullyQualifiedClassName = $node->namespacedName?->toString();
@@ -54,14 +49,13 @@ public function processNode(Node $node, Scope $scope): array
5449
continue;
5550
}
5651

57-
$doc = (string)$method->getDocComment();
52+
$doc = (string) $method->getDocComment();
5853
if ($doc === '') {
5954
continue;
6055
}
6156

62-
6357
$returnType = $method->getReturnType();
64-
if ($returnType === null || !method_exists($returnType, 'getName')) {
58+
if ($returnType === null || ! method_exists($returnType, 'getName')) {
6559
return [];
6660
}
6761

@@ -76,10 +70,13 @@ public function processNode(Node $node, Scope $scope): array
7670
if ($tag->value instanceof ReturnTagValueNode) {
7771
$value = $tag->value->type->name;
7872
if ($value === $returnTypeName
79-
&& $reflection->getName() === $method->getBetterReflection()->getLocatedSource()->getName()) {
73+
&& $reflection->getName() === $method->getBetterReflection()
74+
->getLocatedSource()
75+
->getName()) {
8076
$errors[] = \PHPStan\Rules\RuleErrorBuilder::message(
8177
'PhpDoc attribute @return for method ' . $method->getName() . ' can be remove'
82-
)->line((int)$method->getStartLine())->build();
78+
)->line((int) $method->getStartLine())
79+
->build();
8380
}
8481
}
8582
}

tests/Fixture/EventListener/AsEventListener.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#[Attribute]
1010
class AsEventListener
1111
{
12-
public function __construct(
13-
)
14-
{}
12+
public function __construct()
13+
{
14+
}
1515
}
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
<?php
22

33
declare(strict_types=1);
4-
namespace Simtel\PHPStanRules\Tests\Fixture\EventListener;
54

6-
use Simtel\PHPStanRules\Tests\Fixture\EventListener\AsEventListener;
5+
namespace Simtel\PHPStanRules\Tests\Fixture\EventListener;
76

87
#[AsEventListener]
98
class TestClassEventListener
109
{
11-
public function method():void
10+
public function method(): void
1211
{
13-
1412
}
1513
}

tests/Rules/CommandClassShouldBeHelpCommandHandlerClassTest.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@
44

55
namespace Simtel\PHPStanRules\Tests\Rules;
66

7-
use Simtel\PHPStanRules\Rule\CommandClassShouldBeHelpCommandHandlerClass;
87
use PHPStan\PhpDocParser\Lexer\Lexer;
98
use PHPStan\PhpDocParser\Parser\ConstExprParser;
109
use PHPStan\PhpDocParser\Parser\PhpDocParser;
1110
use PHPStan\PhpDocParser\Parser\TypeParser;
11+
use PHPStan\PhpDocParser\ParserConfig;
1212
use PHPStan\Rules\Rule;
1313
use PHPStan\Testing\RuleTestCase;
14-
use PHPStan\PhpDocParser\ParserConfig;
14+
use Simtel\PHPStanRules\Rule\CommandClassShouldBeHelpCommandHandlerClass;
1515

1616
class CommandClassShouldBeHelpCommandHandlerClassTest extends RuleTestCase
1717
{
18-
1918
/**
2019
* @inheritDoc
2120
*/
@@ -42,20 +41,14 @@ public function testCorrectSeeAttribute(): void
4241
public function testExistsSeeAttribute(): void
4342
{
4443
$this->analyse([__DIR__ . '/../data/command_handler_data2.php'], [
45-
[
46-
'PhpDoc command class should be include @see attribute with CommandHandler class name',
47-
10
48-
]
44+
['PhpDoc command class should be include @see attribute with CommandHandler class name', 10]
4945
]);
5046
}
5147

5248
public function testExistsPhpDoc(): void
5349
{
5450
$this->analyse([__DIR__ . '/../data/command_handler_data3.php'], [
55-
[
56-
'Command class should be include phpDoc with @see attribute',
57-
7
58-
]
51+
['Command class should be include phpDoc with @see attribute', 7]
5952
]);
6053
}
6154

tests/Rules/EventListenerClassShouldBeIncludeAsListenerAttributeTest.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
class EventListenerClassShouldBeIncludeAsListenerAttributeTest extends RuleTestCase
1212
{
13-
1413
/**
1514
* @inheritDoc
1615
*/
@@ -27,11 +26,7 @@ public function testExistsNeedAttribute(): void
2726
public function testExistsAttribute(): void
2827
{
2928
$this->analyse([__DIR__ . '/../Fixture/EventListener/TestNotCorrectClassEventListener.php'], [
30-
[
31-
'Event listener class should be include attribute #[AsEventListener]',
32-
7
33-
]
29+
['Event listener class should be include attribute #[AsEventListener]', 7]
3430
]);
3531
}
36-
3732
}

0 commit comments

Comments
 (0)