Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/bare_run.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php_version: ['7.2', '7.4', '8.0', '8.2']
php_version: ['7.4', '8.0', '8.2']

steps:
- uses: actions/checkout@v3
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/downgraded_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: Downgraded Release
on:
push:
tags:
# avoid infinite looping, skip tags that ends with ".72"
# avoid infinite looping, skip tags that ends with ".74"
# see https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-including-and-excluding-branches
- '*'
- '!**.72'
- '!**.74'

jobs:
downgrade_release:
Expand All @@ -33,13 +33,13 @@ jobs:
- run: mkdir rector-local
- run: composer require rector/rector:^0.17.1 --working-dir rector-local --ansi

# downgrade to PHP 7.2
- run: rector-local/vendor/bin/rector process src config --config build/rector-downgrade-php-72.php --ansi
# downgrade to PHP 7.4
- run: rector-local/vendor/bin/rector process src config --config build/rector-downgrade-php-74.php --ansi

# clear the dev files
- run: rm -rf tests rector-local ecs.php phpstan.neon phpunit.xml .editorconfig

# copy PHP 7.2 composer + workflows
# copy PHP 7.4 composer + workflows
- run: cp -r build/target-repository/. .

# clear the dev files
Expand All @@ -57,7 +57,7 @@ jobs:
run: |
# separate a "git add" to add untracked (new) files too
git add --all
git commit -m "release PHP 7.2 downgraded"
git commit -m "release PHP 7.4 downgraded"

# force push tag, so there is only 1 version
git tag "${GITHUB_REF#refs/tags/}" --force
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->parallel();

$rectorConfig->sets([DowngradeLevelSetList::DOWN_TO_PHP_72]);
$rectorConfig->sets([DowngradeLevelSetList::DOWN_TO_PHP_74]);

$rectorConfig->ruleWithConfiguration(RemoveInterfacesRector::class, [
DocumentedRuleInterface::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php_version: ['7.2', '7.3', '7.4', '8.0']
php_version: ['7.4', '8.0']

steps:
# prepare empty composer.json that allows the phpstan extension plugin
Expand Down
4 changes: 2 additions & 2 deletions build/target-repository/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"description": "Set of Symplify rules for PHPStan",
"license": "MIT",
"require": {
"php": "^7.2|^8.0",
"php": "^7.4|^8.0",
"nette/utils": "^3.2.9 || ^4.0",
"phpstan/phpstan": "^1.10.30",
"phpstan/phpstan": "^2.0",
"webmozart/assert": "^1.11"
},
"autoload": {
Expand Down
19 changes: 6 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,18 @@
"php": ">=8.1",
"nette/utils": "^3.2.9 || ^4.0",
"webmozart/assert": "^1.11",
"phpstan/phpstan": "^1.11",
"phpstan/phpstan": "^2.0",
"symplify/rule-doc-generator-contracts": "^11.2"
},
"require-dev": {
"nikic/php-parser": "^4.19",
"symplify/phpstan-extensions": "^11.4",
"nikic/php-parser": "^5.0",
"symplify/rule-doc-generator": "^12.2",
"phpunit/phpunit": "^10.5",
"symfony/framework-bundle": "6.1.*",
"rector/rector": "^1.2.3",
"symplify/easy-coding-standard": "^12.3",
"phpstan/extension-installer": "^1.4",
"tomasvotruba/class-leak": "^0.2",
"tomasvotruba/unused-public": "^0.3.10",
"tomasvotruba/type-coverage": "^0.3.1"
"tomasvotruba/class-leak": "^1.2",
"rector/rector": "^2.0",
"phpstan/extension-installer": "^1.4"
},
"autoload": {
"psr-4": {
Expand All @@ -36,10 +33,6 @@
"stubs"
],
"files": [
"tests/Rules/Rector/PhpUpgradeImplementsMinPhpVersionInterfaceRule/Fixture/SomePhpFeatureRector.php",
"vendor/rector/rector/src/Contract/Rector/RectorInterface.php",
"vendor/rector/rector/src/Contract/Rector/ConfigurableRectorInterface.php",
"vendor/rector/rector/vendor/rector/rector-downgrade-php/src/Set/ValueObject/DowngradeSetList.php"
]
},
"extra": {
Expand All @@ -58,7 +51,7 @@
"scripts": {
"check-cs": "vendor/bin/ecs check --ansi",
"fix-cs": "vendor/bin/ecs check --fix --ansi",
"phpstan": "vendor/bin/phpstan analyse --ansi --error-format symplify",
"phpstan": "vendor/bin/phpstan analyse --ansi",
"rector": "vendor/bin/rector process --dry-run --ansi",
"docs": "vendor/bin/rule-doc-generator generate src --readme --ansi"
}
Expand Down
45 changes: 33 additions & 12 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ includes:
- config/naming-rules.neon

parameters:
treatPhpDocTypesAsCertain: false

level: 8

paths:
Expand All @@ -20,15 +22,15 @@ parameters:
- */Fixture/*

# https://github.com/TomasVotruba/unused-public
unused_public:
methods: true
properties: true
constants: true
# unused_public:
# methods: true
# properties: true
# constants: true

type_coverage:
return: 99
param: 99
property: 99
# type_coverage:
# return: 99
# param: 99
# property: 99

ignoreErrors:
# needless generics
Expand All @@ -38,8 +40,6 @@ parameters:

- '#Method Symplify\\PHPStanRules\\Reflection\\ReflectionParser\:\:parseNativeClassReflection\(\) has parameter \$reflectionClass with generic class ReflectionClass but does not specify its types\: T#'

- '#Method Symplify\\PHPStanRules\\NodeFinder\\TypeAwareNodeFinder\:\:findFirstInstanceOf\(\) should return \(TNode of PhpParser\\Node\)\|null but returns PhpParser\\Node\|null#'

# overly detailed
- '#Class Symplify\\PHPStanRules\\(.*?) extends generic class PHPStan\\Testing\\RuleTestCase but does not specify its types\: TRule#'
- '#Method Symplify\\PHPStanRules\\(.*?)\:\:getRule\(\) return type with generic interface PHPStan\\Rules\\Rule does not specify its types\: TNodeType#'
Expand All @@ -50,5 +50,26 @@ parameters:
# overly detailed
- '#Class Symplify\\PHPStanRules\\Collector\\(.*?) implements generic interface PHPStan\\Collectors\\Collector but does not specify its types\: TNodeType, TValue#'

# used in tests
- '#Public constant "(.*?)\:\:ERROR_MESSAGE" is never used#'
-
identifier: argument.type

-
identifier: phpstanApi.instanceofType

-
identifier: return.type

-
identifier: class.notFound

-
identifier: phpstanApi.runtimeReflection

-
identifier: phpstanApi.instanceofAssumption

-
identifier: generics.wrongParent

-
identifier: method.childReturnType
2 changes: 1 addition & 1 deletion src/Reflection/ReflectionParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(
private readonly TypeAwareNodeFinder $typeAwareNodeFinder
) {
$parserFactory = new ParserFactory();
$this->parser = $parserFactory->create(ParserFactory::PREFER_PHP7);
$this->parser = $parserFactory->createForNewestSupportedVersion();
}

public function parseMethodReflection(ReflectionMethod|MethodReflection $reflectionMethod): ?ClassMethod
Expand Down
1 change: 0 additions & 1 deletion src/ReturnTypeExtension/NodeGetAttributeTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use PhpParser\Node\Scalar\String_;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Type\DynamicMethodReturnTypeExtension;
use PHPStan\Type\NullType;
use PHPStan\Type\ObjectType;
Expand Down
4 changes: 0 additions & 4 deletions src/Rules/AbstractSymplifyRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleError;
use Symplify\PHPStanRules\Contract\ManyNodeRuleInterface;
use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;

Expand All @@ -24,9 +23,6 @@ public function getNodeType(): string
return Node::class;
}

/**
* @return string[]|RuleError[]
*/
public function processNode(Node $node, Scope $scope): array
{
if ($this->shouldSkipNode($node)) {
Expand Down
8 changes: 3 additions & 5 deletions src/Rules/AnnotateRegexClassConstWithRegexLinkRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
use PhpParser\Node\Stmt\ClassConst;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

/**
* @implements Rule<ClassConst>
* @see \Symplify\PHPStanRules\Tests\Rules\AnnotateRegexClassConstWithRegexLinkRule\AnnotateRegexClassConstWithRegexLinkRuleTest
*/
final class AnnotateRegexClassConstWithRegexLinkRule implements Rule, DocumentedRuleInterface
Expand All @@ -31,17 +33,13 @@ final class AnnotateRegexClassConstWithRegexLinkRule implements Rule, Documented
*/
private const ALL_MODIFIERS = 'imsxeADSUXJu';

/**
* @return class-string<Node>
*/
public function getNodeType(): string
{
return ClassConst::class;
}

/**
* @param ClassConst $node
* @return string[]
*/
public function processNode(Node $node, Scope $scope): array
{
Expand Down Expand Up @@ -69,7 +67,7 @@ public function processNode(Node $node, Scope $scope): array
return [];
}

return [self::ERROR_MESSAGE];
return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()];
}

public function getRuleDefinition(): RuleDefinition
Expand Down
5 changes: 3 additions & 2 deletions src/Rules/CheckClassNamespaceFollowPsr4Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PhpParser\Node\Stmt\ClassLike;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use Symplify\PHPStanRules\Composer\ClassNamespaceMatcher;
use Symplify\PHPStanRules\Composer\ComposerAutoloadResolver;
use Symplify\PHPStanRules\Composer\Psr4PathValidator;
Expand All @@ -17,6 +18,7 @@
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

/**
* @implements Rule<ClassLike>
* @see \Symplify\PHPStanRules\Tests\Rules\CheckClassNamespaceFollowPsr4Rule\CheckClassNamespaceFollowPsr4RuleTest
*/
final class CheckClassNamespaceFollowPsr4Rule implements Rule, DocumentedRuleInterface
Expand Down Expand Up @@ -49,7 +51,6 @@ public function getNodeType(): string

/**
* @param ClassLike $node
* @return string[]
*/
public function processNode(Node $node, Scope $scope): array
{
Expand Down Expand Up @@ -87,7 +88,7 @@ public function processNode(Node $node, Scope $scope): array
$namespacePart = substr($namespaceBeforeClass, 0, -1);
$errorMessage = sprintf(self::ERROR_MESSAGE, $namespacePart);

return [$errorMessage];
return [RuleErrorBuilder::message($errorMessage)->identifier('check.classnamespacepsr4')->build()];
}

public function getRuleDefinition(): RuleDefinition
Expand Down
7 changes: 2 additions & 5 deletions src/Rules/CheckRequiredInterfaceInContractNamespaceRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PhpParser\Node\Stmt\Interface_;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand All @@ -30,17 +31,13 @@ final class CheckRequiredInterfaceInContractNamespaceRule implements Rule, Docum
*/
private const A_CONTRACT_NAMESPACE_REGEX = '#\bContracts?\b#';

/**
* @return class-string<Node>
*/
public function getNodeType(): string
{
return Interface_::class;
}

/**
* @param Interface_ $node
* @return string[]
*/
public function processNode(Node $node, Scope $scope): array
{
Expand All @@ -53,7 +50,7 @@ public function processNode(Node $node, Scope $scope): array
return [];
}

return [self::ERROR_MESSAGE];
return [RuleErrorBuilder::message(self::ERROR_MESSAGE)->build()];
}

public function getRuleDefinition(): RuleDefinition
Expand Down
11 changes: 5 additions & 6 deletions src/Rules/ClassNameRespectsParentSuffixRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use PHPStan\Node\InClassNode;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleError;
use PHPStan\Rules\RuleErrorBuilder;
use PHPUnit\Framework\TestCase;
use Rector\Rector\AbstractRector;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
Expand All @@ -23,6 +25,7 @@
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

/**
* @implements Rule<InClassNode>
* @see \Symplify\PHPStanRules\Tests\Rules\ClassNameRespectsParentSuffixRule\ClassNameRespectsParentSuffixRuleTest
*/
final class ClassNameRespectsParentSuffixRule implements Rule, DocumentedRuleInterface, ConfigurableRuleInterface
Expand Down Expand Up @@ -62,17 +65,13 @@ public function __construct(
$this->parentClasses = array_merge($parentClasses, self::DEFAULT_PARENT_CLASSES);
}

/**
* @return class-string<Node>
*/
public function getNodeType(): string
{
return InClassNode::class;
}

/**
* @param InClassNode $node
* @return string[]
*/
public function processNode(Node $node, Scope $scope): array
{
Expand Down Expand Up @@ -117,7 +116,7 @@ class SomeCommand extends Command
}

/**
* @return array<int, string>
* @return list<RuleError>
*/
private function processClassNameAndShort(ClassReflection $classReflection): array
{
Expand All @@ -132,7 +131,7 @@ private function processClassNameAndShort(ClassReflection $classReflection): arr
}

$errorMessage = sprintf(self::ERROR_MESSAGE, $expectedSuffix);
return [$errorMessage];
return [RuleErrorBuilder::message($errorMessage)->build()];
}

return [];
Expand Down
Loading
Loading