-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SingleRequiredMethodRule to spot multiple @required methods in Sy…
…mfony projects (#163) * split identifiers by group to easily search through them * Add SingleRequiredMethodRule
- Loading branch information
1 parent
39b9c4a
commit 2b10e91
Showing
44 changed files
with
318 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Symplify\PHPStanRules\Enum; | ||
|
||
final class DoctrineRuleIdentifier | ||
{ | ||
public const DOCTRINE_NO_GET_REPOSITORY_OUTSIDE_SERVICE = 'doctrine.noGetRepositoryOutsideService'; | ||
|
||
public const DOCTRINE_NO_REPOSITORY_CALL_IN_DATA_FIXTURES = 'doctrine.noRepositoryCallInDataFixtures'; | ||
|
||
public const DOCTRINE_NO_PARENT_REPOSITORY = 'doctrine.noParentRepository'; | ||
|
||
public const NO_ENTITY_MOCKING = 'doctrine.noEntityMocking'; | ||
|
||
public const REQUIRE_QUERY_BUILDER_ON_REPOSITORY = 'doctrine.requireQueryBuilderOnRepository'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Symplify\PHPStanRules\Enum; | ||
|
||
final class PHPUnitRuleIdentifier | ||
{ | ||
public const NO_DOCUMENT_MOCKING = 'phpunit.noDocumentMocking'; | ||
|
||
public const NO_MOCK_ONLY = 'phpunit.noMockOnly'; | ||
|
||
public const PUBLIC_STATIC_DATA_PROVIDER = 'phpunit.publicStaticDataProvider'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Symplify\PHPStanRules\Enum; | ||
|
||
final class RectorRuleIdentifier | ||
{ | ||
public const NO_INSTANCE_OF_STATIC_REFLECTION = 'rector.noInstanceOfStaticReflection'; | ||
|
||
public const UPGRADE_DOWNGRADE_REGISTERED_IN_SET = 'rector.upgradeDowngradeRegisteredInSet'; | ||
|
||
public const PHP_RULE_IMPLEMENTS_MIN_VERSION = 'rector.phpRuleImplementsMinVersion'; | ||
|
||
public const NO_CLASS_REFLECTION_STATIC_REFLECTION = 'rector.noClassReflectionStaticReflection'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Symplify\PHPStanRules\Enum; | ||
|
||
final class SymfonyRuleIdentifier | ||
{ | ||
public const NO_GET_IN_CONTROLLER = 'symfony.noGetInController'; | ||
|
||
public const NO_GET_DOCTRINE_IN_CONTROLLER = 'symfony.noGetDoctrineInController'; | ||
|
||
public const SINGLE_ARG_EVENT_DISPATCH = 'symfony.singleArgEventDispatch'; | ||
|
||
public const NO_LISTENER_WITHOUT_CONTRACT = 'symfony.noListenerWithoutContract'; | ||
|
||
public const SYMFONY_REQUIRE_INVOKABLE_CONTROLLER = 'symfony.requireInvokableController'; | ||
|
||
public const SYMFONY_NO_REQUIRED_OUTSIDE_CLASS = 'symfony.noRequiredOutsideClass'; | ||
|
||
public const NO_STRING_IN_GET_SUBSCRIBED_EVENTS = 'symfony.noStringInGetSubscribedEvents'; | ||
|
||
public const SYMFONY_NO_ABSTRACT_CONTROLLER_CONSTRUCTOR = 'symfony.noAbstractControllerConstructor'; | ||
|
||
public const SINGLE_REQUIRED_METHOD = 'symfony.singleRequiredMethod'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Symplify\PHPStanRules\NodeAnalyzer; | ||
|
||
use PhpParser\Comment\Doc; | ||
use PhpParser\Node\Stmt\ClassMethod; | ||
use Symplify\PHPStanRules\Enum\ClassName; | ||
|
||
final class SymfonyRequiredMethodAnalyzer | ||
{ | ||
public static function detect(ClassMethod $classMethod): bool | ||
{ | ||
// speed up | ||
if (! $classMethod->isPublic()) { | ||
return false; | ||
} | ||
|
||
if ($classMethod->isMagic()) { | ||
return false; | ||
} | ||
|
||
foreach ($classMethod->getAttrGroups() as $attributeGroup) { | ||
foreach ($attributeGroup->attrs as $attr) { | ||
if ($attr->name->toString() === ClassName::REQUIRED_ATTRIBUTE) { | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
$docComment = $classMethod->getDocComment(); | ||
if (! $docComment instanceof Doc) { | ||
return false; | ||
} | ||
|
||
return str_contains($docComment->getText(), '@required'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.