Skip to content

Commit

Permalink
NEXT-37352 - Introduce phpat
Browse files Browse the repository at this point in the history
  • Loading branch information
mitelg committed Aug 1, 2024
1 parent 96ec3f8 commit 61d27ad
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 4 deletions.
5 changes: 3 additions & 2 deletions .danger.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
],
'strict' => [
'^phpstan\/phpstan.*$' => 'Even patch updates for PHPStan may lead to a red CI pipeline, because of new static analysis errors',
'^symplify\/phpstan-rules$' => 'Even patch updates for PHPStan may lead to a red CI pipeline, because of new static analysis errors',
'^rector\/type-perfect$' => 'Even patch updates for PHPStan may lead to a red CI pipeline, because of new static analysis errors',
'^symplify\/phpstan-rules$' => 'Even patch updates for PHPStan plugins may lead to a red CI pipeline, because of new static analysis errors',
'^rector\/type-perfect$' => 'Even patch updates for PHPStan plugins may lead to a red CI pipeline, because of new static analysis errors',
'^phpat\/phpat$' => 'Even patch updates for PHPStan plugins may lead to a red CI pipeline, because of new static analysis errors',
'^dompdf\/dompdf$' => 'Patch updates of dompdf have let to a lot of issues in the past, therefore it is pinned.',
'^scssphp\/scssphp$' => 'Patch updates of scssphp might lead to UI breaks, therefore it is pinned.',
'^shopware\/conflicts$' => 'The shopware conflicts packages should be required in any version, so use `*` constraint',
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
"league/flysystem-google-cloud-storage": "^3.10.3",
"nikic/php-parser": "^4.16.0",
"opis/json-schema": "^2.3.0",
"phpat/phpat": "0.10.18",
"phpbench/phpbench": "^1.2.15",
"phpdocumentor/reflection-docblock": "^5.3.0",
"phpdocumentor/type-resolver": "^1.7.1",
Expand Down
8 changes: 8 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,14 @@ services:
- # register the class, so we can decorate it, but don't tag it as a rule, so only our decorator is used by PHPStan
class: Symplify\PHPStanRules\Rules\NoReturnSetterMethodRule

-
class: Shopware\Core\DevOps\StaticAnalyze\PHPStan\Rules\MessageHandlerFinalRule
tags:
- phpat.test
-
class: Shopware\Core\DevOps\StaticAnalyze\PHPStan\Rules\NotExtendFlowEventAwareRule
tags:
- phpat.test
rules:
# rules from https://github.com/symplify/phpstan-rules
# domain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class DeprecatedMethodsThrowDeprecationRule implements Rule
'reason:remove-entity',
// Only the route on controller will be removed
'reason:remove-route',
// Throwing deprecations in PHPStan rules would cause problems while executed
'reason:remove-phpstan-rule',
// Classes that will be internal are still called from inside the core, therefore they do not trigger deprecations.
'reason:becomes-internal',
// New function parameter will be added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use Symfony\Component\Messenger\Attribute\AsMessageHandler;

/**
* @deprecated tag:v6.7.0 - reason:remove-phpstan-rule - Will be removed. Configure Shopware\Core\DevOps\StaticAnalyze\PHPStan\Rules\MessageHandlerFinalRule instead
*
* @implements Rule<InClassNode>
*
* @internal
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php declare(strict_types=1);

namespace Shopware\Core\DevOps\StaticAnalyze\PHPStan\Rules;

use PHPat\Selector\Selector;
use PHPat\Test\Attributes\TestRule;
use PHPat\Test\Builder\Rule;
use PHPat\Test\PHPat;
use Shopware\Core\Framework\Log\Package;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;

/**
* @internal
*/
#[Package('core')]
class MessageHandlerFinalRule
{
#[TestRule]
public function isMessageHandlerFinal(): Rule
{
return PHPat::rule()
->classes(Selector::appliesAttribute(AsMessageHandler::class))
->shouldBeFinal();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use Shopware\Core\Framework\Log\Package;

/**
* @deprecated tag:v6.7.0 - reason:remove-phpstan-rule - Will be removed. Configure Shopware\Core\DevOps\StaticAnalyze\PHPStan\Rules\NotExtendFlowEventAwareRule instead
*
* @implements Rule<InClassNode>
*
* @internal
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Shopware\Core\DevOps\StaticAnalyze\PHPStan\Rules;

use PHPat\Selector\Selector;
use PHPat\Test\Attributes\TestRule;
use PHPat\Test\Builder\Rule;
use PHPat\Test\PHPat;
use Shopware\Core\Framework\Event\FlowEventAware;
use Shopware\Core\Framework\Log\Package;

/**
* @internal
*/
#[Package('core')]
class NotExtendFlowEventAwareRule
{
#[TestRule]
public function doNotExtendFlowEventAware(): Rule
{
return PHPat::rule()
->classes(Selector::isInterface())
->shouldNotDependOn()
->classes(Selector::classname(FlowEventAware::class));
}
}
2 changes: 1 addition & 1 deletion src/Core/DevOps/StaticAnalyze/PHPStan/core-rules.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ rules:
- Shopware\Core\DevOps\StaticAnalyze\PHPStan\Rules\Internal\InternalMethodRule
- Shopware\Core\DevOps\StaticAnalyze\PHPStan\Rules\Tests\CoversAttributeRule
- Shopware\Core\DevOps\StaticAnalyze\PHPStan\Rules\Tests\MockingSimpleObjectsNotAllowedRule
- Shopware\Core\DevOps\StaticAnalyze\PHPStan\Rules\FinalClassRule
- Shopware\Core\DevOps\StaticAnalyze\PHPStan\Rules\FinalClassRule # @deprecated tag:v6.7.0 - Configure \Shopware\Core\DevOps\StaticAnalyze\PHPStan\Rules\MessageHandlerFinalRule instead
- Shopware\Core\DevOps\StaticAnalyze\PHPStan\Rules\AbstractClassUsageRule
- Shopware\Core\DevOps\StaticAnalyze\PHPStan\Rules\DecorationPatternRule
- Shopware\Core\DevOps\StaticAnalyze\PHPStan\Rules\AddColumnRule
Expand Down
2 changes: 1 addition & 1 deletion src/Core/DevOps/StaticAnalyze/PHPStan/rules.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ rules:
- Shopware\Core\DevOps\StaticAnalyze\PHPStan\Rules\RuleAreasFlagNotAllowedRule
- Shopware\Core\DevOps\StaticAnalyze\PHPStan\Rules\RuleConditionHasRuleConfigRule
- Shopware\Core\DevOps\StaticAnalyze\PHPStan\Rules\Tests\NoAssertsOnObjectsRule
- Shopware\Core\DevOps\StaticAnalyze\PHPStan\Rules\NoFlowEventAwareExtendsRule
- Shopware\Core\DevOps\StaticAnalyze\PHPStan\Rules\NoFlowEventAwareExtendsRule # @deprecated tag:v6.7.0 - Configure \Shopware\Core\DevOps\StaticAnalyze\PHPStan\Rules\NotExtendFlowEventAwareRule instead
- Shopware\Core\DevOps\StaticAnalyze\PHPStan\Rules\NoFlowStoreFunctionRule
- Shopware\Core\DevOps\StaticAnalyze\PHPStan\Rules\NoEnvironmentHelperInsideCompilerPassRule
- Shopware\Core\DevOps\StaticAnalyze\PHPStan\Rules\NoSuperGlobalsInsideCompilerPassRule
Expand Down

0 comments on commit 61d27ad

Please sign in to comment.