Skip to content

Commit d38cb12

Browse files
authored
add new rules docs (#155)
* add first docs * next rule * next rule * next rule * next rule * next rule * next rule * next rule * next rule * add phpunit rules * off
1 parent 025b86d commit d38cb12

File tree

13 files changed

+607
-35
lines changed

13 files changed

+607
-35
lines changed

README.md

Lines changed: 574 additions & 2 deletions
Large diffs are not rendered by default.

config/doctrine-rules.neon

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
rules:
2-
- Symplify\PHPStanRules\PHPStan\Rules\Doctrine\NoGetRepositoryOutsideServiceRule
3-
- Symplify\PHPStanRules\PHPStan\Rules\Doctrine\NoParentRepositoryRule
4-
- Symplify\PHPStanRules\PHPStan\Rules\Doctrine\NoRepositoryCallInDataFixtureRule
2+
- Symplify\PHPStanRules\Rules\Doctrine\NoGetRepositoryOutsideServiceRule
3+
- Symplify\PHPStanRules\Rules\Doctrine\NoParentRepositoryRule
4+
- Symplify\PHPStanRules\Rules\Doctrine\NoRepositoryCallInDataFixtureRule

config/phpunit-rules.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
rules:
2+
- Symplify\PHPStanRules\Rules\PHPUnit\PublicStaticDataProviderRule
3+
- Symplify\PHPStanRules\Rules\PHPUnit\NoMockOnlyTestRule
4+
5+
- Symplify\PHPStanRules\Rules\Doctrine\NoDocumentMockingRule
6+
- Symplify\PHPStanRules\Rules\Doctrine\NoEntityMockingRule

src/Enum/ClassName.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,14 @@ final class ClassName
7070
* @var string
7171
*/
7272
public const DOCTRINE_FIXTURE_INTERFACE = 'Doctrine\Common\DataFixtures\FixtureInterface';
73+
74+
/**
75+
* @var string
76+
*/
77+
public const ENTITY_REPOSITORY_CLASS = 'Doctrine\ORM\EntityRepository';
78+
79+
/**
80+
* @var string
81+
*/
82+
public const MOCK_OBJECT_CLASS = 'PHPUnit\Framework\MockObject\MockObject';
7383
}

src/PHPStan/Rules/Doctrine/NoGetRepositoryOutsideServiceRule.php renamed to src/Rules/Doctrine/NoGetRepositoryOutsideServiceRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Symplify\PHPStanRules\PHPStan\Rules\Doctrine;
5+
namespace Symplify\PHPStanRules\Rules\Doctrine;
66

77
use PhpParser\Node;
88
use PhpParser\Node\Expr\MethodCall;

src/PHPStan/Rules/Doctrine/NoParentRepositoryRule.php renamed to src/Rules/Doctrine/NoParentRepositoryRule.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@
22

33
declare(strict_types=1);
44

5-
namespace Symplify\PHPStanRules\PHPStan\Rules\Doctrine;
5+
namespace Symplify\PHPStanRules\Rules\Doctrine;
66

77
use PhpParser\Node;
88
use PhpParser\Node\Name;
99
use PhpParser\Node\Stmt\Class_;
1010
use PHPStan\Analyser\Scope;
1111
use PHPStan\Rules\Rule;
1212
use PHPStan\Rules\RuleErrorBuilder;
13+
use Symplify\PHPStanRules\Enum\ClassName;
1314
use Symplify\PHPStanRules\Enum\RuleIdentifier;
1415

1516
/**
1617
* Check if class extends repository class,
1718
* the entity manager should be injected via constructor instead
1819
*
19-
* @see \Symplify\PHPStanRules\Tests\PHPStan\Rule\NoParentRepositoryRule\NoParentRepositoryRuleTest
20+
* @see \Symplify\PHPStanRules\Tests\Rules\Doctrine\NoParentRepositoryRule\NoParentRepositoryRuleTest
2021
*
2122
* @implements Rule<Class_>
2223
*/
@@ -27,11 +28,6 @@ final class NoParentRepositoryRule implements Rule
2728
*/
2829
public const ERROR_MESSAGE = 'Extending EntityRepository is not allowed, use constructor injection and pass entity manager instead';
2930

30-
/**
31-
* @var string
32-
*/
33-
private const ENTITY_REPOSITORY_CLASS = 'Doctrine\ORM\EntityRepository';
34-
3531
public function getNodeType(): string
3632
{
3733
return Class_::class;
@@ -47,7 +43,7 @@ public function processNode(Node $node, Scope $scope): array
4743
}
4844

4945
$parentClass = $node->extends->toString();
50-
if ($parentClass !== self::ENTITY_REPOSITORY_CLASS) {
46+
if ($parentClass !== ClassName::ENTITY_REPOSITORY_CLASS) {
5147
return [];
5248
}
5349

src/PHPStan/Rules/Doctrine/NoRepositoryCallInDataFixtureRule.php renamed to src/Rules/Doctrine/NoRepositoryCallInDataFixtureRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Symplify\PHPStanRules\PHPStan\Rules\Doctrine;
5+
namespace Symplify\PHPStanRules\Rules\Doctrine;
66

77
use PhpParser\Node;
88
use PhpParser\Node\Expr\MethodCall;

src/Rules/PHPUnit/NoMockOnlyTestRule.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use PHPStan\Node\InClassNode;
1212
use PHPStan\Rules\Rule;
1313
use PHPStan\Rules\RuleErrorBuilder;
14+
use Symplify\PHPStanRules\Enum\ClassName;
1415
use Symplify\PHPStanRules\Enum\RuleIdentifier;
1516
use Symplify\PHPStanRules\Testing\PHPUnitTestAnalyser;
1617

@@ -26,11 +27,6 @@
2627
*/
2728
public const ERROR_MESSAGE = 'Test should have at least one non-mocked property, to test something';
2829

29-
/**
30-
* @var string
31-
*/
32-
private const MOCK_OBJECT_CLASS = 'PHPUnit\Framework\MockObject\MockObject';
33-
3430
public function getNodeType(): string
3531
{
3632
return InClassNode::class;
@@ -63,7 +59,7 @@ public function processNode(Node $node, Scope $scope): array
6359

6460
$propertyClassName = $property->type->toString();
6561

66-
if ($propertyClassName !== self::MOCK_OBJECT_CLASS) {
62+
if ($propertyClassName !== ClassName::MOCK_OBJECT_CLASS) {
6763
$hasExclusivelyMockedProperties = false;
6864
}
6965
}

src/Rules/Symfony/NoRequiredOutsideClassRule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Symplify\PHPStanRules\Enum\RuleIdentifier;
1515

1616
/**
17-
* @see \Symplify\PHPStanRules\Tests\PHPStan\Rule\NoRequiredOutsideClassRule\NoRequiredOutsideClassRuleTest
17+
* @see \Symplify\PHPStanRules\Tests\Rules\Symfony\NoRequiredOutsideClassRule\NoRequiredOutsideClassRuleTest
1818
*
1919
* @implements Rule<Trait_>
2020
*/
@@ -23,7 +23,7 @@ final class NoRequiredOutsideClassRule implements Rule
2323
/**
2424
* @var string
2525
*/
26-
public const ERROR_MESSAGE = 'Symfony #[Require]/@required should be used only in classes to avoid missuse';
26+
public const ERROR_MESSAGE = 'Symfony #[Require]/@required should be used only in classes to avoid misuse';
2727

2828
/**
2929
* @var string

src/Rules/Symfony/NoStringInGetSubscribedEventsRule.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@
2222
*/
2323
final class NoStringInGetSubscribedEventsRule implements Rule
2424
{
25-
/**
26-
* @var string
27-
*/
28-
private const EVENT_SUBSCRIBER_INTERFACE = 'Symfony\Component\EventDispatcher\EventSubscriberInterface';
29-
3025
/**
3126
* @var string
3227
*/
@@ -56,7 +51,7 @@ public function processNode(Node $node, Scope $scope): array
5651
}
5752

5853
// only handle symfony one
59-
if (! $classReflection->implementsInterface(self::EVENT_SUBSCRIBER_INTERFACE)) {
54+
if (! $classReflection->implementsInterface(ClassName::EVENT_SUBSCRIBER_INTERFACE)) {
6055
return [];
6156
}
6257

0 commit comments

Comments
 (0)