├── .github
├── FUNDING.yml
└── workflows
│ └── all_tests.yml
├── .gitignore
├── LICENSE
├── README.md
├── composer.json
├── config
└── sets
│ ├── php-static-analysis-annotations-to-attributes.php
│ └── php-static-analysis-attributes-to-annotations.php
├── ecs.php
├── patches
├── rector-rector-src-application-fileprocessor-php.patch
├── rector-rector-src-betterphpdocparser-phpdocinfo-phpdocinfofactory-php.patch
└── rector-rector-src-phpparser-nodetraverser-rectornodetraverser-php.patch
├── phpstan.neon
├── phpunit.xml
├── psalm.xml
├── rector.php
├── src
├── AnnotationsToAttributesRector.php
├── AttributesToAnnotationsRector.php
├── Composer
│ └── Plugin.php
└── Set
│ ├── PhpStaticAnalysisAnnotationsToAttributesSetList.php
│ ├── PhpStaticAnalysisAttributesToAnnotationsSetList.php
│ └── Provider
│ ├── PhpStaticAnalysisAnnotationsToAttributesSetProvider.php
│ └── PhpStaticAnalysisAttributesToAnnotationsSetProvider.php
└── tests
├── AnnotationsToAttributesRectorTest.php
├── AnnotationsToAttributesWithAssertOnParamRectorTest.php
├── AnnotationsToAttributesWithParamOnParamRectorTest.php
├── AnnotationsToAttributesWithPropertyAttributeForVarRectorTest.php
├── AnnotationsToAttributesWithTypeAttributeForReturnRectorTest.php
├── AnnotationsToAttributesWithTypeAttributeForTypeClassRectorTest.php
├── AttributesToAnnotationsRectorTest.php
├── AttributesToAnnotationsToAttributesRectorTest.php
├── AttributesToAnnotationsToAttributesWithExtraRulesRectorTest.php
├── BothWaysFixture
├── AssertAttributeTest.php.inc
├── AssertIfFalseAttributeTest.php.inc
├── AssertIfTrueAttributeTest.php.inc
├── DefineTypeAttributeTest.php.inc
├── DeprecatedAttributeTest.php.inc
├── ImmutableAttributeTest.php.inc
├── ImportTypeAttributeTest.php.inc
├── ImpureAttributeTest.php.inc
├── InternalAttributeTest.php.inc
├── IsReadOnlyAttributeTest.php.inc
├── MethodAttributeTest.php.inc
├── MixinAttributeTest.php.inc
├── ParamAttributeTest.php.inc
├── ParamOutAttributeTest.php.inc
├── PropertyAttributeTest.php.inc
├── PropertyReadAttributeTest.php.inc
├── PropertyWriteAttributeTest.php.inc
├── PureAttributeTest.php.inc
├── RequireExtendsAttributeTest.php.inc
├── RequireImplementsAttributeTest.php.inc
├── ReturnsAttributeTest.php.inc
├── SelfOutAttributeTest.php.inc
├── TemplateAttributeTest.php.inc
├── TemplateContravariantAttributeTest.php.inc
├── TemplateCovariantAttributeTest.php.inc
├── TemplateExtendsAttributeTest.php.inc
├── TemplateImplementsAttributeTest.php.inc
├── TemplateUseAttributeTest.php.inc
├── ThrowsAttributeTest.php.inc
└── TypeAttributeTest.php.inc
├── ExcludeAnnotationsTest.php
├── Fixture
├── AssertAttributeTest.php.inc
├── AssertIfFalseAttributeTest.php.inc
├── AssertIfTrueAttributeTest.php.inc
├── DefineTypeAttributeTest.php.inc
├── DeprecatedAttributeTest.php.inc
├── ImmutableAttributeTest.php.inc
├── ImportTypeAttributeTest.php.inc
├── ImpureAttributeTest.php.inc
├── InternalAttributeTest.php.inc
├── IsReadOnlyAttributeTest.php.inc
├── MethodAttributeTest.php.inc
├── MixinAttributeTest.php.inc
├── ParamAttributeTest.php.inc
├── ParamOutAttributeTest.php.inc
├── PropertyAttributeTest.php.inc
├── PropertyReadAttributeTest.php.inc
├── PropertyWriteAttributeTest.php.inc
├── PureAttributeTest.php.inc
├── RequireExtendsAttributeTest.php.inc
├── RequireImplementsAttributeTest.php.inc
├── ReturnsAttributeTest.php.inc
├── SelfOutAttributeTest.php.inc
├── TemplateAttributeTest.php.inc
├── TemplateContravariantAttributeTest.php.inc
├── TemplateCovariantAttributeTest.php.inc
├── TemplateExtendsAttributeTest.php.inc
├── TemplateImplementsAttributeTest.php.inc
├── TemplateUseAttributeTest.php.inc
├── ThrowsAttributeTest.php.inc
└── TypeAttributeTest.php.inc
├── InverseFixture
├── AssertAttributeTest.php.inc
├── AssertIfFalseAttributeTest.php.inc
├── AssertIfTrueAttributeTest.php.inc
├── DefineTypeAttributeTest.php.inc
├── DeprecatedAttributeTest.php.inc
├── ImmutableAttributeTest.php.inc
├── ImportTypeAttributeTest.php.inc
├── ImpureAttributeTest.php.inc
├── InternalAttributeTest.php.inc
├── IsReadOnlyAttributeTest.php.inc
├── MethodAttributeTest.php.inc
├── MixinAttributeTest.php.inc
├── ParamAttributeTest.php.inc
├── ParamOutAttributeTest.php.inc
├── PropertyAttributeTest.php.inc
├── PropertyReadAttributeTest.php.inc
├── PropertyWriteAttributeTest.php.inc
├── PureAttributeTest.php.inc
├── RequireExtendsAttributeTest.php.inc
├── RequireImplementsAttributeTest.php.inc
├── ReturnsAttributeTest.php.inc
├── SelfOutAttributeTest.php.inc
├── TemplateAttributeTest.php.inc
├── TemplateContravariantAttributeTest.php.inc
├── TemplateCovariantAttributeTest.php.inc
├── TemplateExtendsAttributeTest.php.inc
├── TemplateImplementsAttributeTest.php.inc
├── TemplateUseAttributeTest.php.inc
├── ThrowsAttributeTest.php.inc
└── TypeAttributeTest.php.inc
├── SpecialFixture
├── AssertAttributeTestWithAssertOnParam.php.inc
├── AssertIfFalseAttributeTestWithAssertOnParam.php.inc
├── AssertIfTrueAttributeTestWithAssertOnParam.php.inc
├── ExcludeAnnotationsTest.php.inc
├── ParamAttributeTestWithParamOnParam.php.inc
├── ParamOutAttributeTestWithParamOnParam.php.inc
├── PropertyAttributeTestForVarAnnotation.php.inc
├── TypeAttributeTestForReturnAnnotation.php.inc
└── TypeAttributeTestForTypeClassAnnotation.php.inc
├── WithExtraRulesFixture
├── ParamAttributeTest.php.inc
├── ReturnsAttributeTest.php.inc
└── TypeAttributeTest.php.inc
└── config
├── configured-both-ways-rule.php
├── configured-inverse-rule.php
├── configured-rule-with-assert-on-param.php
├── configured-rule-with-exclude-annotations.php
├── configured-rule-with-param-on-param.php
├── configured-rule-with-property-attribute-for-var.php
├── configured-rule-with-type-attribute-for-return.php
├── configured-rule-with-type-attribute-for-type-class.php
├── configured-rule.php
└── configured-with-extra-rule-rule.php
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | github: [carlos-granados]
2 |
--------------------------------------------------------------------------------
/.github/workflows/all_tests.yml:
--------------------------------------------------------------------------------
1 | name: "All Tests"
2 |
3 | on:
4 | pull_request:
5 | push:
6 |
7 | jobs:
8 | test:
9 | name: "Run all checks for all supported PHP versions"
10 |
11 | runs-on: "ubuntu-22.04"
12 |
13 | strategy:
14 | fail-fast: false
15 | matrix:
16 | php-version:
17 | - "8.1"
18 | - "8.2"
19 | - "8.3"
20 | - "8.4"
21 |
22 | steps:
23 | - name: "Checkout"
24 | uses: "actions/checkout@v4"
25 |
26 | - name: "Install PHP"
27 | uses: "shivammathur/setup-php@v2"
28 | with:
29 | php-version: "${{ matrix.php-version }}"
30 | tools: composer
31 |
32 | - name: Get composer cache directory
33 | id: composercache
34 | run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
35 |
36 | - name: Cache dependencies
37 | uses: actions/cache@v4
38 | with:
39 | path: ${{ steps.composercache.outputs.dir }}
40 | key: "php-${{ matrix.php-version }}-${{ hashFiles('**/composer.lock') }}"
41 | restore-keys: "php-${{ matrix.php-version }}-${{ hashFiles('**/composer.lock') }}"
42 |
43 | - name: "Install composer dependencies"
44 | run: "composer install --no-interaction --no-progress"
45 |
46 | - name: "Run tests"
47 | run: "composer tests-without-psalm"
48 |
49 | - name: "Run Psalm"
50 | if: matrix.php-version != '8.4' # Psalm does not fully support PHP 8.4 yet
51 | run: "composer psalm"
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /vendor/
2 | composer.lock
3 | .idea
4 | .phpunit.cache
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2024 php-static-analysis
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "php-static-analysis/rector-rule",
3 | "description": "RectorPHP rule to convert PHPDoc annotations for static analysis to PHP attributes",
4 | "type": "rector-extension",
5 | "keywords": [
6 | "dev",
7 | "static analysis"
8 | ],
9 | "license": "MIT",
10 | "autoload": {
11 | "psr-4": {
12 | "PhpStaticAnalysis\\RectorRule\\": "src/"
13 | }
14 | },
15 | "autoload-dev": {
16 | "psr-4": {
17 | "test\\PhpStaticAnalysis\\RectorRule\\": "tests/"
18 | }
19 | },
20 | "authors": [
21 | {
22 | "name": "Carlos Granados",
23 | "email": "carlos@fastdebug.io"
24 | }
25 | ],
26 | "minimum-stability": "dev",
27 | "prefer-stable": true,
28 | "require": {
29 | "php": ">=8.1",
30 | "php-static-analysis/attributes": "^0.5.0 || dev-main",
31 | "php-static-analysis/node-visitor": "^0.5.0 || dev-main",
32 | "rector/rector": "^2.0"
33 | },
34 | "require-dev": {
35 | "composer/composer": "^2.8",
36 | "php-static-analysis/phpstan-extension": "^0.5.0 || dev-main",
37 | "php-static-analysis/psalm-plugin": "^0.5.0 || dev-main",
38 | "phpstan/extension-installer": "^1.3",
39 | "phpstan/phpstan": "^2.0",
40 | "phpunit/phpunit": "^9.0",
41 | "symplify/easy-coding-standard": "^12.1",
42 | "vimeo/psalm": "^6",
43 | "webmozart/assert": "^1.11"
44 | },
45 | "scripts": {
46 | "tests": [
47 | "@ecs",
48 | "@psalm",
49 | "@phpunit",
50 | "@phpstan",
51 | "@rector"
52 | ],
53 | "tests-without-psalm": [
54 | "@ecs",
55 | "@phpunit",
56 | "@phpstan",
57 | "@rector"
58 | ],
59 | "psalm": "psalm",
60 | "ecs": "ecs",
61 | "ecs-fix": "ecs --fix",
62 | "phpunit": "phpunit",
63 | "phpstan": "phpstan analyse",
64 | "rector": "rector --dry-run",
65 | "rector-fix": "rector",
66 | "rector-debug": "rector --clear-cache --xdebug --dry-run",
67 | "post-install-cmd": "PhpStaticAnalysis\\RectorRule\\Composer\\Plugin::onPostInstall",
68 | "post-update-cmd": "PhpStaticAnalysis\\RectorRule\\Composer\\Plugin::onPostUpdate"
69 | },
70 | "config": {
71 | "allow-plugins": {
72 | "php-static-analysis/psalm-plugin": true,
73 | "phpstan/extension-installer": true
74 | },
75 | "sort-packages": true
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/config/sets/php-static-analysis-annotations-to-attributes.php:
--------------------------------------------------------------------------------
1 | withConfiguredRule(
41 | AnnotationsToAttributesRector::class,
42 | [
43 | new AnnotationToAttribute('assert', Assert::class),
44 | new AnnotationToAttribute('assert_if_false', AssertIfFalse::class),
45 | new AnnotationToAttribute('assert_if_true', AssertIfTrue::class),
46 | new AnnotationToAttribute('deprecated', Deprecated::class),
47 | new AnnotationToAttribute('extends', TemplateExtends::class),
48 | new AnnotationToAttribute('immutable', Immutable::class),
49 | new AnnotationToAttribute('import_type', ImportType::class),
50 | new AnnotationToAttribute('impure', Impure::class),
51 | new AnnotationToAttribute('implements', TemplateImplements::class),
52 | new AnnotationToAttribute('internal', Internal::class),
53 | new AnnotationToAttribute('method', Method::class),
54 | new AnnotationToAttribute('mixin', Mixin::class),
55 | new AnnotationToAttribute('param', Param::class),
56 | new AnnotationToAttribute('param_out', ParamOut::class),
57 | new AnnotationToAttribute('property', Property::class),
58 | new AnnotationToAttribute('property_read', PropertyRead::class),
59 | new AnnotationToAttribute('property_write', PropertyWrite::class),
60 | new AnnotationToAttribute('pure', Pure::class),
61 | new AnnotationToAttribute('readonly', IsReadOnly::class),
62 | new AnnotationToAttribute('require_extends', RequireExtends::class),
63 | new AnnotationToAttribute('require_implements', RequireImplements::class),
64 | new AnnotationToAttribute('return', Returns::class),
65 | new AnnotationToAttribute('self_out', SelfOut::class),
66 | new AnnotationToAttribute('template', Template::class),
67 | new AnnotationToAttribute('template_contravariant', TemplateContravariant::class),
68 | new AnnotationToAttribute('template_covariant', TemplateCovariant::class),
69 | new AnnotationToAttribute('template_extends', TemplateExtends::class),
70 | new AnnotationToAttribute('template_implements', TemplateImplements::class),
71 | new AnnotationToAttribute('template_use', TemplateUse::class),
72 | new AnnotationToAttribute('this_out', SelfOut::class),
73 | new AnnotationToAttribute('throws', Throws::class),
74 | new AnnotationToAttribute('type', DefineType::class),
75 | new AnnotationToAttribute('use', TemplateUse::class),
76 | new AnnotationToAttribute('var', Type::class),
77 | 'addParamAttributeOnParameters' => false,
78 | 'addAssertAttributeOnParameters' => false,
79 | 'useTypeAttributeForReturnAnnotation' => false,
80 | 'usePropertyAttributeForVarAnnotation' => false,
81 | 'excludeAnnotations' => [],
82 | 'useTypeAttributeForTypeClassAnnotation' => false,
83 | ]
84 | );
85 |
--------------------------------------------------------------------------------
/config/sets/php-static-analysis-attributes-to-annotations.php:
--------------------------------------------------------------------------------
1 | withRules([
10 | AttributesToAnnotationsRector::class
11 | ]);
12 |
--------------------------------------------------------------------------------
/ecs.php:
--------------------------------------------------------------------------------
1 | withPaths([
10 | __DIR__ . '/src',
11 | __DIR__ . '/tests',
12 | ])
13 | ->withPreparedSets(
14 | psr12: true,
15 | );
16 |
--------------------------------------------------------------------------------
/patches/rector-rector-src-application-fileprocessor-php.patch:
--------------------------------------------------------------------------------
1 | --- /dev/null
2 | +++ ../src/Application/FileProcessor.php
3 | @@ -3,3 +3,4 @@
4 | declare (strict_types=1);
5 | namespace Rector\Application;
6 | +use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
7 |
8 | @@ -66,7 +67,9 @@
9 | * @readonly
10 | */
11 | private NodeScopeAndMetadataDecorator $nodeScopeAndMetadataDecorator;
12 | - public function __construct(BetterStandardPrinter $betterStandardPrinter, RectorNodeTraverser $rectorNodeTraverser, SymfonyStyle $symfonyStyle, FileDiffFactory $fileDiffFactory, ChangedFilesDetector $changedFilesDetector, ErrorFactory $errorFactory, FilePathHelper $filePathHelper, PostFileProcessor $postFileProcessor, RectorParser $rectorParser, NodeScopeAndMetadataDecorator $nodeScopeAndMetadataDecorator)
13 | + public function __construct(BetterStandardPrinter $betterStandardPrinter, RectorNodeTraverser $rectorNodeTraverser, SymfonyStyle $symfonyStyle, FileDiffFactory $fileDiffFactory, ChangedFilesDetector $changedFilesDetector, ErrorFactory $errorFactory, FilePathHelper $filePathHelper, PostFileProcessor $postFileProcessor, RectorParser $rectorParser, NodeScopeAndMetadataDecorator $nodeScopeAndMetadataDecorator,
14 | + private PhpDocInfoFactory $phpDocInfoFactory
15 | + )
16 | {
17 | $this->betterStandardPrinter = $betterStandardPrinter;
18 | $this->rectorNodeTraverser = $rectorNodeTraverser;
19 | @@ -90,6 +93,7 @@
20 | $fileHasChanged = \false;
21 | $filePath = $file->getFilePath();
22 | do {
23 | + $this->phpDocInfoFactory->clearCache();
24 | $file->changeHasChanged(\false);
25 | // 1. change nodes with Rector Rules
26 | $newStmts = $this->rectorNodeTraverser->traverse($file->getNewStmts());
27 |
--------------------------------------------------------------------------------
/patches/rector-rector-src-betterphpdocparser-phpdocinfo-phpdocinfofactory-php.patch:
--------------------------------------------------------------------------------
1 | --- /dev/null
2 | +++ ../src/BetterPhpDocParser/PhpDocInfo/PhpDocInfoFactory.php
3 | @@ -55,6 +55,10 @@
4 | $this->annotationNaming = $annotationNaming;
5 | $this->phpDocNodeByTypeFinder = $phpDocNodeByTypeFinder;
6 | }
7 | + public function clearCache(): void
8 | + {
9 | + $this->phpDocInfosByObjectId = [];
10 | + }
11 | public function createFromNodeOrEmpty(Node $node) : \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo
12 | {
13 | // already added
14 |
--------------------------------------------------------------------------------
/patches/rector-rector-src-phpparser-nodetraverser-rectornodetraverser-php.patch:
--------------------------------------------------------------------------------
1 | --- /dev/null
2 | +++ ../src/PhpParser/NodeTraverser/RectorNodeTraverser.php
3 | @@ -7,6 +7,8 @@
4 | use PhpParser\Node\Stmt;
5 | use PhpParser\NodeTraverser;
6 | use PhpParser\NodeVisitor;
7 | +use PhpStaticAnalysis\RectorRule\AnnotationsToAttributesRector;
8 | +use PhpStaticAnalysis\RectorRule\AttributesToAnnotationsRector;
9 | use Rector\Configuration\ConfigurationRuleFilter;
10 | use Rector\Contract\Rector\RectorInterface;
11 | use Rector\VersionBonding\PhpVersionedFilter;
12 | @@ -97,6 +99,23 @@
13 | $this->visitors = $this->phpVersionedFilter->filter($this->rectors);
14 | // filter by configuration
15 | $this->visitors = $this->configurationRuleFilter->filter($this->visitors);
16 | +
17 | + $first = [];
18 | + $middle = [];
19 | + $last = [];
20 | +
21 | + foreach ($this->visitors as $visitor) {
22 | + if ($visitor instanceof AttributesToAnnotationsRector) {
23 | + $first[] = $visitor;
24 | + } elseif ($visitor instanceof AnnotationsToAttributesRector) {
25 | + $last[] = $visitor;
26 | + } else {
27 | + $middle[] = $visitor;
28 | + }
29 | + }
30 | +
31 | + $this->visitors = array_merge($first, $middle, $last);
32 | +
33 | $this->areNodeVisitorsPrepared = \true;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/phpstan.neon:
--------------------------------------------------------------------------------
1 | parameters:
2 | level: max
3 | paths:
4 | - src
5 | - tests
6 | excludePaths:
7 | - tests/Fixture/*
8 | - tests/SpecialFixture/*
9 |
--------------------------------------------------------------------------------
/phpunit.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
16 | tests
17 |
18 |
19 |
--------------------------------------------------------------------------------
/psalm.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/rector.php:
--------------------------------------------------------------------------------
1 | withPaths([
10 | __DIR__ . '/src',
11 | __DIR__ . '/tests',
12 | ])
13 | ->withSkip([
14 | __DIR__ . '/tests/Fixture',
15 | __DIR__ . '/tests/SpecialFixture',
16 | ])
17 | ->withSets([
18 | PhpStaticAnalysisAnnotationsToAttributesSetList::ANNOTATIONS_TO_ATTRIBUTES
19 | ]);
20 |
--------------------------------------------------------------------------------
/src/AttributesToAnnotationsRector.php:
--------------------------------------------------------------------------------
1 | nodeVisitor = new AttributeNodeVisitor(AttributeNodeVisitor::TOOL_PHPSTAN);
33 | }
34 |
35 | public function getRuleDefinition(): RuleDefinition
36 | {
37 | return new RuleDefinition('// Converts PHP attributes for static analysis to PHPDoc annotations', [
38 | new CodeSample(
39 | <<<'CODE_SAMPLE'
40 | ')]
49 | private array $result;
50 |
51 | #[Param(array1: 'array')]
52 | #[Param(array2: 'array')]
53 | #[Returns('array')]
54 | public function addArrays(array $array1, array $array2): array
55 | {
56 | $this->array = $array1 + $array2;
57 | return $this->array;
58 | }
59 | }
60 |
61 | CODE_SAMPLE
62 | ,
63 | <<<'CODE_SAMPLE'
64 | */
69 | private array $result;
70 |
71 | /**
72 | * @param array $array1
73 | * @param array $array2
74 | * @return array
75 | */
76 | public function addArrays(array $array1, array $array2): array
77 | {
78 | $this->result = $array1 + $array2;
79 | return $this->result;
80 | }
81 | }
82 | CODE_SAMPLE
83 | ),
84 | ]);
85 | }
86 |
87 | #[Returns('array>')]
88 | public function getNodeTypes(): array
89 | {
90 | return [
91 | Class_::class,
92 | ClassConst::class,
93 | ClassMethod::class,
94 | Function_::class,
95 | Interface_::class,
96 | Stmt\Property::class,
97 | Trait_::class
98 | ];
99 | }
100 |
101 | /**
102 | * @psalm-suppress MoreSpecificImplementedParamType
103 | */
104 | #[Param(node: 'Stmt\Class_|Stmt\ClassConst|Stmt\ClassMethod|Stmt\Function_|Stmt\Interface_|Stmt\Property|Stmt\Trait_')]
105 | public function refactor(Node $node): ?Node
106 | {
107 | $existingComments = $node->getDocComment();
108 | $node = $this->nodeVisitor->enterNode($node);
109 | assert($node instanceof Node);
110 | $newComments = $node->getDocComment();
111 | if ($newComments !== null && ($existingComments === null ||
112 | $newComments->getText() !== $existingComments->getText())) {
113 | return $node;
114 | }
115 | return null;
116 | }
117 |
118 | #[Returns('PhpVersion::PHP_80')]
119 | public function provideMinPhpVersion(): int
120 | {
121 | return PhpVersionFeature::ATTRIBUTES;
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/src/Composer/Plugin.php:
--------------------------------------------------------------------------------
1 | ')]
27 | public static function getSubscribedEvents(): array
28 | {
29 | return [
30 | 'post-install-cmd' => 'onPostInstall',
31 | 'post-update-cmd' => 'onPostUpdate'
32 | ];
33 | }
34 |
35 | public static function onPostInstall(Event $event): void
36 | {
37 | self::applyPatches($event);
38 | }
39 |
40 | public static function onPostUpdate(Event $event): void
41 | {
42 | self::applyPatches($event);
43 | }
44 |
45 | private static function applyPatches(Event $event): void
46 | {
47 | /**
48 | * @var string $vendorDir
49 | */
50 | $vendorDir = $event->getComposer()->getConfig()->get('vendor-dir');
51 |
52 | $dependencyPath = $vendorDir . '/rector/rector';
53 |
54 | $patchFile = __DIR__ . '/../../patches/rector-rector-src-application-fileprocessor-php.patch';
55 |
56 | exec("patch -p1 -d $dependencyPath --forward < $patchFile");
57 |
58 | $patchFile = __DIR__ . '/../../patches/rector-rector-src-betterphpdocparser-phpdocinfo-phpdocinfofactory-php.patch';
59 |
60 | exec("patch -p1 -d $dependencyPath --forward < $patchFile");
61 |
62 | $patchFile = __DIR__ . '/../../patches/rector-rector-src-phpparser-nodetraverser-rectornodetraverser-php.patch';
63 |
64 | exec("patch -p1 -d $dependencyPath --forward < $patchFile");
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/Set/PhpStaticAnalysisAnnotationsToAttributesSetList.php:
--------------------------------------------------------------------------------
1 | doTestFile($filePath);
18 | }
19 |
20 | public static function provideData(): Iterator
21 | {
22 | return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
23 | }
24 |
25 | public function provideConfigFilePath(): string
26 | {
27 | return __DIR__ . '/config/configured-rule.php';
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/tests/AnnotationsToAttributesWithAssertOnParamRectorTest.php:
--------------------------------------------------------------------------------
1 | doTestFile($filePath);
18 | }
19 |
20 | public static function provideData(): Iterator
21 | {
22 | yield [__DIR__ . '/SpecialFixture/AssertAttributeTestWithAssertOnParam.php.inc'];
23 | yield [__DIR__ . '/SpecialFixture/AssertIfFalseAttributeTestWithAssertOnParam.php.inc'];
24 | yield [__DIR__ . '/SpecialFixture/AssertIfTrueAttributeTestWithAssertOnParam.php.inc'];
25 | }
26 |
27 | public function provideConfigFilePath(): string
28 | {
29 | return __DIR__ . '/config/configured-rule-with-assert-on-param.php';
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/tests/AnnotationsToAttributesWithParamOnParamRectorTest.php:
--------------------------------------------------------------------------------
1 | doTestFile($filePath);
18 | }
19 |
20 | public static function provideData(): Iterator
21 | {
22 | yield [__DIR__ . '/SpecialFixture/ParamAttributeTestWithParamOnParam.php.inc'];
23 | yield [__DIR__ . '/SpecialFixture/ParamOutAttributeTestWithParamOnParam.php.inc'];
24 | }
25 |
26 | public function provideConfigFilePath(): string
27 | {
28 | return __DIR__ . '/config/configured-rule-with-param-on-param.php';
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/tests/AnnotationsToAttributesWithPropertyAttributeForVarRectorTest.php:
--------------------------------------------------------------------------------
1 | doTestFile($filePath);
18 | }
19 |
20 | public static function provideData(): Iterator
21 | {
22 | yield [__DIR__ . '/SpecialFixture/PropertyAttributeTestForVarAnnotation.php.inc'];
23 | }
24 |
25 | public function provideConfigFilePath(): string
26 | {
27 | return __DIR__ . '/config/configured-rule-with-property-attribute-for-var.php';
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/tests/AnnotationsToAttributesWithTypeAttributeForReturnRectorTest.php:
--------------------------------------------------------------------------------
1 | doTestFile($filePath);
18 | }
19 |
20 | public static function provideData(): Iterator
21 | {
22 | yield [__DIR__ . '/SpecialFixture/TypeAttributeTestForReturnAnnotation.php.inc'];
23 | }
24 |
25 | public function provideConfigFilePath(): string
26 | {
27 | return __DIR__ . '/config/configured-rule-with-type-attribute-for-return.php';
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/tests/AnnotationsToAttributesWithTypeAttributeForTypeClassRectorTest.php:
--------------------------------------------------------------------------------
1 | doTestFile($filePath);
18 | }
19 |
20 | public static function provideData(): Iterator
21 | {
22 | yield [__DIR__ . '/SpecialFixture/TypeAttributeTestForTypeClassAnnotation.php.inc'];
23 | }
24 |
25 | public function provideConfigFilePath(): string
26 | {
27 | return __DIR__ . '/config/configured-rule-with-type-attribute-for-type-class.php';
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/tests/AttributesToAnnotationsRectorTest.php:
--------------------------------------------------------------------------------
1 | doTestFile($filePath);
18 | }
19 |
20 | public static function provideData(): Iterator
21 | {
22 | return self::yieldFilesFromDirectory(__DIR__ . '/InverseFixture');
23 | }
24 |
25 | public function provideConfigFilePath(): string
26 | {
27 | return __DIR__ . '/config/configured-inverse-rule.php';
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/tests/AttributesToAnnotationsToAttributesRectorTest.php:
--------------------------------------------------------------------------------
1 | expectOutputString(
19 | <<doTestFile($filePath);
29 | }
30 |
31 | public static function provideData(): Iterator
32 | {
33 | return self::yieldFilesFromDirectory(__DIR__ . '/BothWaysFixture');
34 | }
35 |
36 | public function provideConfigFilePath(): string
37 | {
38 | return __DIR__ . '/config/configured-both-ways-rule.php';
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/tests/AttributesToAnnotationsToAttributesWithExtraRulesRectorTest.php:
--------------------------------------------------------------------------------
1 | doTestFile($filePath);
18 | }
19 |
20 | public static function provideData(): Iterator
21 | {
22 | return self::yieldFilesFromDirectory(__DIR__ . '/WithExtraRulesFixture');
23 | }
24 |
25 | public function provideConfigFilePath(): string
26 | {
27 | return __DIR__ . '/config/configured-with-extra-rule-rule.php';
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/tests/BothWaysFixture/AssertAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 | item')]
36 | public function checkPropertyName($name)
37 | {
38 | if (!is_string($name)) {
39 | throw new Exception();
40 | }
41 | }
42 |
43 | #[Assert('string $this->getName()')]
44 | public function checkMethodName($name)
45 | {
46 | if (!is_string($name)) {
47 | throw new Exception();
48 | }
49 | }
50 |
51 | /**
52 | * @codeCoverageIgnore
53 | */
54 | #[Assert(name: 'string')]
55 | public function checkMoreNames($name)
56 | {
57 | if (!is_string($name)) {
58 | throw new Exception();
59 | }
60 | }
61 |
62 | #[Returns('string')]
63 | #[Assert(name: 'string')]
64 | public function checkAnotherName($name)
65 | {
66 | if (!is_string($name)) {
67 | throw new Exception();
68 | }
69 | }
70 |
71 | #[Assert(name1: 'string')]
72 | #[Assert(name2: 'string')]
73 | public function checkTwoNames($name1, $name2)
74 | {
75 | if (!is_string($name1) && !is_string($name2)) {
76 | throw new Exception();
77 | }
78 | }
79 |
80 | #[Assert(name: 'string')]
81 | public function checkUserName($name) // the name of the user
82 | {
83 | if (!is_string($name)) {
84 | throw new Exception();
85 | }
86 | }
87 | }
88 |
89 | #[Assert(name: 'string')]
90 | function checkName($name)
91 | {
92 | if (!is_string($name)) {
93 | throw new Exception();
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/tests/BothWaysFixture/AssertIfFalseAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 | item')]
29 | public function checkPropertyName($name)
30 | {
31 | return !is_string($name);
32 | }
33 |
34 | #[AssertIfFalse('string $this->getName()')]
35 | public function checkMethodName($name)
36 | {
37 | return !is_string($name);
38 | }
39 |
40 | /**
41 | * @codeCoverageIgnore
42 | */
43 | #[AssertIfFalse(name: 'string')]
44 | public function checkMoreNames($name)
45 | {
46 | return !is_string($name);
47 | }
48 |
49 | #[Returns('string')]
50 | #[AssertIfFalse(name: 'string')]
51 | public function checkAnotherName($name)
52 | {
53 | return !is_string($name);
54 | }
55 |
56 | #[AssertIfFalse(name1: 'string')]
57 | #[AssertIfFalse(name2: 'string')]
58 | public function checkTwoNames($name1, $name2)
59 | {
60 | return !is_string($name1) || !is_string($name2);
61 | }
62 |
63 | #[AssertIfFalse(name: 'string')] // the name of the user
64 | public function checkUserName($name)
65 | {
66 | return !is_string($name);
67 | }
68 | }
69 |
70 | #[AssertIfFalse(name: 'string')]
71 | function checkName($name)
72 | {
73 | return !is_string($name);
74 | }
75 |
--------------------------------------------------------------------------------
/tests/BothWaysFixture/AssertIfTrueAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 | item')]
29 | public function checkPropertyName($name)
30 | {
31 | return !is_string($name);
32 | }
33 |
34 | #[AssertIfTrue('string $this->getName()')]
35 | public function checkMethodName($name)
36 | {
37 | return !is_string($name);
38 | }
39 |
40 | /**
41 | * @codeCoverageIgnore
42 | */
43 | #[AssertIfTrue(name: 'string')]
44 | public function checkMoreNames($name)
45 | {
46 | return !is_string($name);
47 | }
48 |
49 | #[Returns('string')]
50 | #[AssertIfTrue(name: 'string')]
51 | public function checkAnotherName($name)
52 | {
53 | return !is_string($name);
54 | }
55 |
56 | #[AssertIfTrue(name1: 'string')]
57 | #[AssertIfTrue(name2: 'string')]
58 | public function checkTwoNames($name1, $name2)
59 | {
60 | return !is_string($name1) || !is_string($name2);
61 | }
62 |
63 | #[AssertIfTrue(name: 'string')] // the name of the user
64 | public function checkUserName($name)
65 | {
66 | return !is_string($name);
67 | }
68 | }
69 |
70 | #[AssertIfTrue(name: 'string')]
71 | function checkName($name)
72 | {
73 | return !is_string($name);
74 | }
75 |
--------------------------------------------------------------------------------
/tests/BothWaysFixture/DefineTypeAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 | ')]
11 | public function add()
12 | {
13 | }
14 |
15 | /**
16 | * @codeCoverageIgnore
17 | */
18 | #[SelfOut('self')]
19 | public function addMore()
20 | {
21 | }
22 |
23 | #[Param(name: 'string')]
24 | #[SelfOut('self')]
25 | public function addAnother()
26 | {
27 | }
28 |
29 | #[SelfOut('self')] // this is the new type
30 | public function addUserName()
31 | {
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/tests/BothWaysFixture/TemplateAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 | ')] // this is the extended class
19 | class TemplateExtendsAttributeTest extends TemplateClass
20 | {
21 | }
22 |
23 | #[TemplateExtends('TemplateClass')]
24 | class TemplateExtendsAttributeTest2 extends TemplateClass
25 | {
26 | }
27 |
--------------------------------------------------------------------------------
/tests/BothWaysFixture/TemplateImplementsAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 | ')] // this is the implemented interface
19 | class TemplateImplementsAttributeTest implements TemplateInterface
20 | {
21 | }
22 |
--------------------------------------------------------------------------------
/tests/BothWaysFixture/TemplateUseAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 | ')] // this is the used trait
16 | class TemplateUseAttributeTest
17 | {
18 | /**
19 | * @codeCoverageIgnore
20 | */
21 | use TemplateTrait;
22 | }
23 |
--------------------------------------------------------------------------------
/tests/BothWaysFixture/ThrowsAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 | doTestFile($filePath);
18 | }
19 |
20 | public static function provideData(): Iterator
21 | {
22 | yield [__DIR__ . '/SpecialFixture/ExcludeAnnotationsTest.php.inc'];
23 | }
24 |
25 | public function provideConfigFilePath(): string
26 | {
27 | return __DIR__ . '/config/configured-rule-with-exclude-annotations.php';
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/tests/Fixture/AssertAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 | item
43 | */
44 | public function checkPropertyName($name)
45 | {
46 | if (!is_string($name)) {
47 | throw new Exception();
48 | }
49 | }
50 |
51 | /**
52 | * @phpstan-assert string $this->getName()
53 | */
54 | public function checkMethodName($name)
55 | {
56 | if (!is_string($name)) {
57 | throw new Exception();
58 | }
59 | }
60 |
61 | /**
62 | * @codeCoverageIgnore
63 | * @phpstan-assert string $name
64 | */
65 | public function checkMoreNames($name)
66 | {
67 | if (!is_string($name)) {
68 | throw new Exception();
69 | }
70 | }
71 |
72 | /**
73 | * @phpstan-assert string $name
74 | */
75 | #[Returns('string')]
76 | public function checkAnotherName($name)
77 | {
78 | if (!is_string($name)) {
79 | throw new Exception();
80 | }
81 | }
82 |
83 | /**
84 | * @phpstan-assert string $name1
85 | * @phpstan-assert string $name2
86 | */
87 | public function checkTwoNames($name1, $name2)
88 | {
89 | if (!is_string($name1) && !is_string($name2)) {
90 | throw new Exception();
91 | }
92 | }
93 |
94 | /**
95 | * @phpstan-assert string $name2
96 | */
97 | #[Assert(name1: 'string')]
98 | public function checkTwoMoreNames($name1, $name2)
99 | {
100 | if (!is_string($name1) && !is_string($name2)) {
101 | throw new Exception();
102 | }
103 | }
104 |
105 | /**
106 | * @phpstan-assert string $name the name of the user
107 | */
108 | public function checkUserName($name)
109 | {
110 | if (!is_string($name)) {
111 | throw new Exception();
112 | }
113 | }
114 |
115 | /**
116 | * @psalm-assert string $name
117 | */
118 | public function checkPsalmName($name)
119 | {
120 | if (!is_string($name)) {
121 | throw new Exception();
122 | }
123 | }
124 | }
125 |
126 | /**
127 | * @phpstan-assert string $name
128 | */
129 | function checkName($name)
130 | {
131 | if (!is_string($name)) {
132 | throw new Exception();
133 | }
134 | }
135 |
136 | ?>
137 | -----
138 | item')]
173 | public function checkPropertyName($name)
174 | {
175 | if (!is_string($name)) {
176 | throw new Exception();
177 | }
178 | }
179 |
180 | #[Assert('string $this->getName()')]
181 | public function checkMethodName($name)
182 | {
183 | if (!is_string($name)) {
184 | throw new Exception();
185 | }
186 | }
187 |
188 | /**
189 | * @codeCoverageIgnore
190 | */
191 | #[Assert(name: 'string')]
192 | public function checkMoreNames($name)
193 | {
194 | if (!is_string($name)) {
195 | throw new Exception();
196 | }
197 | }
198 |
199 | #[Returns('string')]
200 | #[Assert(name: 'string')]
201 | public function checkAnotherName($name)
202 | {
203 | if (!is_string($name)) {
204 | throw new Exception();
205 | }
206 | }
207 |
208 | #[Assert(name1: 'string')]
209 | #[Assert(name2: 'string')]
210 | public function checkTwoNames($name1, $name2)
211 | {
212 | if (!is_string($name1) && !is_string($name2)) {
213 | throw new Exception();
214 | }
215 | }
216 |
217 | #[Assert(name1: 'string')]
218 | #[Assert(name2: 'string')]
219 | public function checkTwoMoreNames($name1, $name2)
220 | {
221 | if (!is_string($name1) && !is_string($name2)) {
222 | throw new Exception();
223 | }
224 | }
225 |
226 | #[Assert(name: 'string')] // the name of the user
227 | public function checkUserName($name)
228 | {
229 | if (!is_string($name)) {
230 | throw new Exception();
231 | }
232 | }
233 |
234 | #[Assert(name: 'string')]
235 | public function checkPsalmName($name)
236 | {
237 | if (!is_string($name)) {
238 | throw new Exception();
239 | }
240 | }
241 | }
242 |
243 | #[Assert(name: 'string')]
244 | function checkName($name)
245 | {
246 | if (!is_string($name)) {
247 | throw new Exception();
248 | }
249 | }
250 |
251 | ?>
252 |
--------------------------------------------------------------------------------
/tests/Fixture/AssertIfFalseAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 | item
36 | */
37 | public function checkPropertyName($name)
38 | {
39 | return !is_string($name);
40 | }
41 |
42 | /**
43 | * @phpstan-assert-if-false string $this->getName()
44 | */
45 | public function checkMethodName($name)
46 | {
47 | return !is_string($name);
48 | }
49 |
50 | /**
51 | * @codeCoverageIgnore
52 | * @phpstan-assert-if-false string $name
53 | */
54 | public function checkMoreNames($name)
55 | {
56 | return !is_string($name);
57 | }
58 |
59 | /**
60 | * @phpstan-assert-if-false string $name
61 | */
62 | #[Returns('string')]
63 | public function checkAnotherName($name)
64 | {
65 | return !is_string($name);
66 | }
67 |
68 | /**
69 | * @phpstan-assert-if-false string $name1
70 | * @phpstan-assert-if-false string $name2
71 | */
72 | public function checkTwoNames($name1, $name2)
73 | {
74 | return !is_string($name1) || !is_string($name2);
75 | }
76 |
77 | /**
78 | * @phpstan-assert-if-false string $name2
79 | */
80 | #[AssertIfFalse(name1: 'string')]
81 | public function checkTwoMoreNames($name1, $name2)
82 | {
83 | return !is_string($name1) || !is_string($name2);
84 | }
85 |
86 | /**
87 | * @phpstan-assert-if-false string $name the name of the user
88 | */
89 | public function checkUserName($name)
90 | {
91 | return !is_string($name);
92 | }
93 |
94 | /**
95 | * @psalm-assert-if-false string $name
96 | */
97 | public function checkPsalmName($name)
98 | {
99 | return !is_string($name);
100 | }
101 | }
102 |
103 | /**
104 | * @phpstan-assert-if-false string $name
105 | */
106 | function checkName($name)
107 | {
108 | return !is_string($name);
109 | }
110 |
111 | ?>
112 | -----
113 | item')]
141 | public function checkPropertyName($name)
142 | {
143 | return !is_string($name);
144 | }
145 |
146 | #[AssertIfFalse('string $this->getName()')]
147 | public function checkMethodName($name)
148 | {
149 | return !is_string($name);
150 | }
151 |
152 | /**
153 | * @codeCoverageIgnore
154 | */
155 | #[AssertIfFalse(name: 'string')]
156 | public function checkMoreNames($name)
157 | {
158 | return !is_string($name);
159 | }
160 |
161 | #[Returns('string')]
162 | #[AssertIfFalse(name: 'string')]
163 | public function checkAnotherName($name)
164 | {
165 | return !is_string($name);
166 | }
167 |
168 | #[AssertIfFalse(name1: 'string')]
169 | #[AssertIfFalse(name2: 'string')]
170 | public function checkTwoNames($name1, $name2)
171 | {
172 | return !is_string($name1) || !is_string($name2);
173 | }
174 |
175 | #[AssertIfFalse(name1: 'string')]
176 | #[AssertIfFalse(name2: 'string')]
177 | public function checkTwoMoreNames($name1, $name2)
178 | {
179 | return !is_string($name1) || !is_string($name2);
180 | }
181 |
182 | #[AssertIfFalse(name: 'string')] // the name of the user
183 | public function checkUserName($name)
184 | {
185 | return !is_string($name);
186 | }
187 |
188 | #[AssertIfFalse(name: 'string')]
189 | public function checkPsalmName($name)
190 | {
191 | return !is_string($name);
192 | }
193 | }
194 |
195 | #[AssertIfFalse(name: 'string')]
196 | function checkName($name)
197 | {
198 | return !is_string($name);
199 | }
200 |
201 | ?>
202 |
--------------------------------------------------------------------------------
/tests/Fixture/AssertIfTrueAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 | item
36 | */
37 | public function checkPropertyName($name)
38 | {
39 | return !is_string($name);
40 | }
41 |
42 | /**
43 | * @phpstan-assert-if-true string $this->getName()
44 | */
45 | public function checkMethodName($name)
46 | {
47 | return !is_string($name);
48 | }
49 |
50 | /**
51 | * @codeCoverageIgnore
52 | * @phpstan-assert-if-true string $name
53 | */
54 | public function checkMoreNames($name)
55 | {
56 | return !is_string($name);
57 | }
58 |
59 | /**
60 | * @phpstan-assert-if-true string $name
61 | */
62 | #[Returns('string')]
63 | public function checkAnotherName($name)
64 | {
65 | return !is_string($name);
66 | }
67 |
68 | /**
69 | * @phpstan-assert-if-true string $name1
70 | * @phpstan-assert-if-true string $name2
71 | */
72 | public function checkTwoNames($name1, $name2)
73 | {
74 | return !is_string($name1) || !is_string($name2);
75 | }
76 |
77 | /**
78 | * @phpstan-assert-if-true string $name2
79 | */
80 | #[AssertIfTrue(name1: 'string')]
81 | public function checkTwoMoreNames($name1, $name2)
82 | {
83 | return !is_string($name1) || !is_string($name2);
84 | }
85 |
86 | /**
87 | * @phpstan-assert-if-true string $name the name of the user
88 | */
89 | public function checkUserName($name)
90 | {
91 | return !is_string($name);
92 | }
93 |
94 | /**
95 | * @psalm-assert-if-true string $name
96 | */
97 | public function checkPsalmName($name)
98 | {
99 | return !is_string($name);
100 | }
101 | }
102 |
103 | /**
104 | * @phpstan-assert-if-true string $name
105 | */
106 | function checkName($name)
107 | {
108 | return !is_string($name);
109 | }
110 |
111 | ?>
112 | -----
113 | item')]
141 | public function checkPropertyName($name)
142 | {
143 | return !is_string($name);
144 | }
145 |
146 | #[AssertIfTrue('string $this->getName()')]
147 | public function checkMethodName($name)
148 | {
149 | return !is_string($name);
150 | }
151 |
152 | /**
153 | * @codeCoverageIgnore
154 | */
155 | #[AssertIfTrue(name: 'string')]
156 | public function checkMoreNames($name)
157 | {
158 | return !is_string($name);
159 | }
160 |
161 | #[Returns('string')]
162 | #[AssertIfTrue(name: 'string')]
163 | public function checkAnotherName($name)
164 | {
165 | return !is_string($name);
166 | }
167 |
168 | #[AssertIfTrue(name1: 'string')]
169 | #[AssertIfTrue(name2: 'string')]
170 | public function checkTwoNames($name1, $name2)
171 | {
172 | return !is_string($name1) || !is_string($name2);
173 | }
174 |
175 | #[AssertIfTrue(name1: 'string')]
176 | #[AssertIfTrue(name2: 'string')]
177 | public function checkTwoMoreNames($name1, $name2)
178 | {
179 | return !is_string($name1) || !is_string($name2);
180 | }
181 |
182 | #[AssertIfTrue(name: 'string')] // the name of the user
183 | public function checkUserName($name)
184 | {
185 | return !is_string($name);
186 | }
187 |
188 | #[AssertIfTrue(name: 'string')]
189 | public function checkPsalmName($name)
190 | {
191 | return !is_string($name);
192 | }
193 | }
194 |
195 | #[AssertIfTrue(name: 'string')]
196 | function checkName($name)
197 | {
198 | return !is_string($name);
199 | }
200 |
201 | ?>
202 |
--------------------------------------------------------------------------------
/tests/Fixture/DefineTypeAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
18 | -----
19 |
36 |
--------------------------------------------------------------------------------
/tests/Fixture/DeprecatedAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
76 | -----
77 |
135 |
--------------------------------------------------------------------------------
/tests/Fixture/ImmutableAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
30 | -----
31 |
57 |
--------------------------------------------------------------------------------
/tests/Fixture/ImportTypeAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
18 | -----
19 |
36 |
--------------------------------------------------------------------------------
/tests/Fixture/ImpureAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
49 | -----
50 |
91 |
--------------------------------------------------------------------------------
/tests/Fixture/InternalAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
76 | -----
77 |
135 |
--------------------------------------------------------------------------------
/tests/Fixture/IsReadOnlyAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
43 | -----
44 |
77 |
--------------------------------------------------------------------------------
/tests/Fixture/MethodAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
20 | -----
21 |
41 |
--------------------------------------------------------------------------------
/tests/Fixture/MixinAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
18 | -----
19 |
37 |
--------------------------------------------------------------------------------
/tests/Fixture/ParamAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
88 | -----
89 |
160 |
--------------------------------------------------------------------------------
/tests/Fixture/ParamOutAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
90 | -----
91 |
164 |
--------------------------------------------------------------------------------
/tests/Fixture/PropertyAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
20 | -----
21 |
41 |
--------------------------------------------------------------------------------
/tests/Fixture/PropertyReadAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
20 | -----
21 |
41 |
--------------------------------------------------------------------------------
/tests/Fixture/PropertyWriteAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
20 | -----
21 |
41 |
--------------------------------------------------------------------------------
/tests/Fixture/PureAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
56 | -----
57 |
103 |
--------------------------------------------------------------------------------
/tests/Fixture/RequireExtendsAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
35 | -----
36 |
67 |
--------------------------------------------------------------------------------
/tests/Fixture/RequireImplementsAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
35 | -----
36 |
67 |
--------------------------------------------------------------------------------
/tests/Fixture/ReturnsAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
69 | -----
70 |
127 |
--------------------------------------------------------------------------------
/tests/Fixture/SelfOutAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
11 | */
12 | public function add()
13 | {
14 | }
15 |
16 | /**
17 | * @phpstan-this-out self
18 | */
19 | public function addThis()
20 | {
21 | }
22 |
23 | /**
24 | * @codeCoverageIgnore
25 | * @phpstan-self-out self
26 | */
27 | public function addMore()
28 | {
29 | }
30 |
31 | /**
32 | * @phpstan-self-out self
33 | */
34 | #[Param(name:'string')]
35 | public function addAnother()
36 | {
37 | }
38 |
39 | /**
40 | * @phpstan-self-out self this is the new type
41 | */
42 | public function addUserName()
43 | {
44 | }
45 |
46 | /**
47 | * @psalm-self-out self
48 | */
49 | public function addPsalm()
50 | {
51 | }
52 | }
53 |
54 | ?>
55 | -----
56 | ')]
66 | public function add()
67 | {
68 | }
69 |
70 | #[SelfOut('self')]
71 | public function addThis()
72 | {
73 | }
74 |
75 | /**
76 | * @codeCoverageIgnore
77 | */
78 | #[SelfOut('self')]
79 | public function addMore()
80 | {
81 | }
82 |
83 | #[Param(name:'string')]
84 | #[SelfOut('self')]
85 | public function addAnother()
86 | {
87 | }
88 |
89 | #[SelfOut('self')] // this is the new type
90 | public function addUserName()
91 | {
92 | }
93 |
94 | #[SelfOut('self')]
95 | public function addPsalm()
96 | {
97 | }
98 | }
99 |
100 | ?>
101 |
--------------------------------------------------------------------------------
/tests/Fixture/TemplateAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
88 | -----
89 |
159 |
--------------------------------------------------------------------------------
/tests/Fixture/TemplateContravariantAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
22 | -----
23 |
45 |
--------------------------------------------------------------------------------
/tests/Fixture/TemplateCovariantAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
23 | -----
24 |
47 |
--------------------------------------------------------------------------------
/tests/Fixture/TemplateExtendsAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 | this is the extended class
16 | */
17 | #[Property(name:'string')]
18 | class TemplateExtendsAttributeTest extends TemplateClass
19 | {
20 | }
21 |
22 | /**
23 | * @template-extends TemplateClass
24 | */
25 | class TemplateExtendsAttributeTest2 extends TemplateClass
26 | {
27 | }
28 |
29 | /**
30 | * @phpstan-extends TemplateClass
31 | */
32 | class TemplateExtendsAttributeTest3 extends TemplateClass
33 | {
34 | }
35 |
36 | ?>
37 | -----
38 | ')] // this is the extended class
56 | class TemplateExtendsAttributeTest extends TemplateClass
57 | {
58 | }
59 |
60 | #[TemplateExtends('TemplateClass')]
61 | class TemplateExtendsAttributeTest2 extends TemplateClass
62 | {
63 | }
64 |
65 | #[TemplateExtends('TemplateClass')]
66 | class TemplateExtendsAttributeTest3 extends TemplateClass
67 | {
68 | }
69 |
70 | ?>
71 |
--------------------------------------------------------------------------------
/tests/Fixture/TemplateImplementsAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 | this is the implemented interface
16 | */
17 | #[Property(name:'string')]
18 | class TemplateImplementsAttributeTest implements TemplateInterface
19 | {
20 | }
21 |
22 | /**
23 | * @template-implements TemplateInterface
24 | */
25 | class TemplateImplementsAttributeTest2 implements TemplateInterface
26 | {
27 | }
28 |
29 | /**
30 | * @phpstan-implements TemplateInterface
31 | */
32 | class TemplateImplementsAttributeTest3 implements TemplateInterface
33 | {
34 | }
35 |
36 | ?>
37 | -----
38 | ')] // this is the implemented interface
56 | class TemplateImplementsAttributeTest implements TemplateInterface
57 | {
58 | }
59 |
60 | #[TemplateImplements('TemplateInterface')]
61 | class TemplateImplementsAttributeTest2 implements TemplateInterface
62 | {
63 | }
64 |
65 | #[TemplateImplements('TemplateInterface')]
66 | class TemplateImplementsAttributeTest3 implements TemplateInterface
67 | {
68 | }
69 |
70 | ?>
71 |
--------------------------------------------------------------------------------
/tests/Fixture/TemplateUseAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 | this is the used trait
19 | */
20 | use TemplateTrait;
21 | }
22 |
23 | class TemplateUseAttributeTest2
24 | {
25 | /**
26 | * @template-use TemplateTrait
27 | */
28 | use TemplateTrait;
29 | }
30 |
31 | class TemplateUseAttributeTest3
32 | {
33 | /**
34 | * @phpstan-use TemplateTrait
35 | */
36 | use TemplateTrait;
37 | }
38 |
39 | ?>
40 | -----
41 | ')] // this is the used trait
56 | class TemplateUseAttributeTest
57 | {
58 | /**
59 | * @codeCoverageIgnore
60 | */
61 | use TemplateTrait;
62 | }
63 |
64 | #[TemplateUse('TemplateTrait')]
65 | class TemplateUseAttributeTest2
66 | {
67 | use TemplateTrait;
68 | }
69 |
70 | #[TemplateUse('TemplateTrait')]
71 | class TemplateUseAttributeTest3
72 | {
73 | use TemplateTrait;
74 | }
75 |
76 | ?>
77 |
--------------------------------------------------------------------------------
/tests/Fixture/ThrowsAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
62 | -----
63 |
115 |
--------------------------------------------------------------------------------
/tests/Fixture/TypeAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
48 | -----
49 |
85 |
--------------------------------------------------------------------------------
/tests/InverseFixture/AssertAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 | item')]
36 | public function checkPropertyName($name)
37 | {
38 | if (!is_string($name)) {
39 | throw new Exception();
40 | }
41 | }
42 |
43 | #[Assert('string $this->getName()')]
44 | public function checkMethodName($name)
45 | {
46 | if (!is_string($name)) {
47 | throw new Exception();
48 | }
49 | }
50 |
51 | /**
52 | * @codeCoverageIgnore
53 | */
54 | #[Assert(name: 'string')]
55 | public function checkMoreNames($name)
56 | {
57 | if (!is_string($name)) {
58 | throw new Exception();
59 | }
60 | }
61 |
62 | #[Returns('string')]
63 | #[Assert(name: 'string')]
64 | public function checkAnotherName($name)
65 | {
66 | if (!is_string($name)) {
67 | throw new Exception();
68 | }
69 | }
70 |
71 | #[Assert(name1: 'string')]
72 | #[Assert(name2: 'string')]
73 | public function checkTwoNames($name1, $name2)
74 | {
75 | if (!is_string($name1) && !is_string($name2)) {
76 | throw new Exception();
77 | }
78 | }
79 |
80 | #[Assert(name: 'string')]
81 | public function checkUserName($name) // the name of the user
82 | {
83 | if (!is_string($name)) {
84 | throw new Exception();
85 | }
86 | }
87 | }
88 |
89 | #[Assert(name: 'string')]
90 | function checkName($name)
91 | {
92 | if (!is_string($name)) {
93 | throw new Exception();
94 | }
95 | }
96 |
97 | ?>
98 | -----
99 | item
141 | */
142 | public function checkPropertyName($name)
143 | {
144 | if (!is_string($name)) {
145 | throw new Exception();
146 | }
147 | }
148 |
149 | /**
150 | * @phpstan-assert string $this->getName()
151 | */
152 | public function checkMethodName($name)
153 | {
154 | if (!is_string($name)) {
155 | throw new Exception();
156 | }
157 | }
158 |
159 | /**
160 | * @codeCoverageIgnore
161 | * @phpstan-assert string $name
162 | */
163 | public function checkMoreNames($name)
164 | {
165 | if (!is_string($name)) {
166 | throw new Exception();
167 | }
168 | }
169 |
170 | /**
171 | * @return string
172 | * @phpstan-assert string $name
173 | */
174 | public function checkAnotherName($name)
175 | {
176 | if (!is_string($name)) {
177 | throw new Exception();
178 | }
179 | }
180 |
181 | /**
182 | * @phpstan-assert string $name1
183 | * @phpstan-assert string $name2
184 | */
185 | public function checkTwoNames($name1, $name2)
186 | {
187 | if (!is_string($name1) && !is_string($name2)) {
188 | throw new Exception();
189 | }
190 | }
191 |
192 | /**
193 | * @phpstan-assert string $name
194 | */
195 | public function checkUserName($name)
196 | {
197 | if (!is_string($name)) {
198 | throw new Exception();
199 | }
200 | }
201 | }
202 |
203 | /**
204 | * @phpstan-assert string $name
205 | */
206 | function checkName($name)
207 | {
208 | if (!is_string($name)) {
209 | throw new Exception();
210 | }
211 | }
212 |
213 | ?>
214 |
--------------------------------------------------------------------------------
/tests/InverseFixture/AssertIfFalseAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 | item')]
29 | public function checkPropertyName($name)
30 | {
31 | return !is_string($name);
32 | }
33 |
34 | #[AssertIfFalse('string $this->getName()')]
35 | public function checkMethodName($name)
36 | {
37 | return !is_string($name);
38 | }
39 |
40 | /**
41 | * @codeCoverageIgnore
42 | */
43 | #[AssertIfFalse(name: 'string')]
44 | public function checkMoreNames($name)
45 | {
46 | return !is_string($name);
47 | }
48 |
49 | #[Returns('string')]
50 | #[AssertIfFalse(name: 'string')]
51 | public function checkAnotherName($name)
52 | {
53 | return !is_string($name);
54 | }
55 |
56 | #[AssertIfFalse(name1: 'string')]
57 | #[AssertIfFalse(name2: 'string')]
58 | public function checkTwoNames($name1, $name2)
59 | {
60 | return !is_string($name1) || !is_string($name2);
61 | }
62 |
63 | #[AssertIfFalse(name: 'string')] // the name of the user
64 | public function checkUserName($name)
65 | {
66 | return !is_string($name);
67 | }
68 | }
69 |
70 | #[AssertIfFalse(name: 'string')]
71 | function checkName($name)
72 | {
73 | return !is_string($name);
74 | }
75 |
76 | ?>
77 | -----
78 | item
113 | */
114 | public function checkPropertyName($name)
115 | {
116 | return !is_string($name);
117 | }
118 |
119 | /**
120 | * @phpstan-assert-if-false string $this->getName()
121 | */
122 | public function checkMethodName($name)
123 | {
124 | return !is_string($name);
125 | }
126 |
127 | /**
128 | * @codeCoverageIgnore
129 | * @phpstan-assert-if-false string $name
130 | */
131 | public function checkMoreNames($name)
132 | {
133 | return !is_string($name);
134 | }
135 |
136 | /**
137 | * @return string
138 | * @phpstan-assert-if-false string $name
139 | */
140 | public function checkAnotherName($name)
141 | {
142 | return !is_string($name);
143 | }
144 |
145 | /**
146 | * @phpstan-assert-if-false string $name1
147 | * @phpstan-assert-if-false string $name2
148 | */
149 | public function checkTwoNames($name1, $name2)
150 | {
151 | return !is_string($name1) || !is_string($name2);
152 | }
153 |
154 | /**
155 | * @phpstan-assert-if-false string $name
156 | */
157 | public function checkUserName($name)
158 | {
159 | return !is_string($name);
160 | }
161 | }
162 |
163 | /**
164 | * @phpstan-assert-if-false string $name
165 | */
166 | function checkName($name)
167 | {
168 | return !is_string($name);
169 | }
170 |
171 | ?>
172 |
--------------------------------------------------------------------------------
/tests/InverseFixture/AssertIfTrueAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 | item')]
29 | public function checkPropertyName($name)
30 | {
31 | return !is_string($name);
32 | }
33 |
34 | #[AssertIfTrue('string $this->getName()')]
35 | public function checkMethodName($name)
36 | {
37 | return !is_string($name);
38 | }
39 |
40 | /**
41 | * @codeCoverageIgnore
42 | */
43 | #[AssertIfTrue(name: 'string')]
44 | public function checkMoreNames($name)
45 | {
46 | return !is_string($name);
47 | }
48 |
49 | #[Returns('string')]
50 | #[AssertIfTrue(name: 'string')]
51 | public function checkAnotherName($name)
52 | {
53 | return !is_string($name);
54 | }
55 |
56 | #[AssertIfTrue(name1: 'string')]
57 | #[AssertIfTrue(name2: 'string')]
58 | public function checkTwoNames($name1, $name2)
59 | {
60 | return !is_string($name1) || !is_string($name2);
61 | }
62 |
63 | #[AssertIfTrue(name: 'string')] // the name of the user
64 | public function checkUserName($name)
65 | {
66 | return !is_string($name);
67 | }
68 | }
69 |
70 | #[AssertIfTrue(name: 'string')]
71 | function checkName($name)
72 | {
73 | return !is_string($name);
74 | }
75 |
76 | ?>
77 | -----
78 | item
113 | */
114 | public function checkPropertyName($name)
115 | {
116 | return !is_string($name);
117 | }
118 |
119 | /**
120 | * @phpstan-assert-if-true string $this->getName()
121 | */
122 | public function checkMethodName($name)
123 | {
124 | return !is_string($name);
125 | }
126 |
127 | /**
128 | * @codeCoverageIgnore
129 | * @phpstan-assert-if-true string $name
130 | */
131 | public function checkMoreNames($name)
132 | {
133 | return !is_string($name);
134 | }
135 |
136 | /**
137 | * @return string
138 | * @phpstan-assert-if-true string $name
139 | */
140 | public function checkAnotherName($name)
141 | {
142 | return !is_string($name);
143 | }
144 |
145 | /**
146 | * @phpstan-assert-if-true string $name1
147 | * @phpstan-assert-if-true string $name2
148 | */
149 | public function checkTwoNames($name1, $name2)
150 | {
151 | return !is_string($name1) || !is_string($name2);
152 | }
153 |
154 | /**
155 | * @phpstan-assert-if-true string $name
156 | */
157 | public function checkUserName($name)
158 | {
159 | return !is_string($name);
160 | }
161 | }
162 |
163 | /**
164 | * @phpstan-assert-if-true string $name
165 | */
166 | function checkName($name)
167 | {
168 | return !is_string($name);
169 | }
170 |
171 | ?>
172 |
--------------------------------------------------------------------------------
/tests/InverseFixture/DefineTypeAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
16 | -----
17 |
32 |
--------------------------------------------------------------------------------
/tests/InverseFixture/DeprecatedAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
49 | -----
50 |
107 |
--------------------------------------------------------------------------------
/tests/InverseFixture/ImmutableAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
16 | -----
17 |
32 |
--------------------------------------------------------------------------------
/tests/InverseFixture/ImportTypeAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
16 | -----
17 |
32 |
--------------------------------------------------------------------------------
/tests/InverseFixture/ImpureAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
37 | -----
38 |
80 |
--------------------------------------------------------------------------------
/tests/InverseFixture/InternalAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
59 | -----
60 |
129 |
--------------------------------------------------------------------------------
/tests/InverseFixture/IsReadOnlyAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
28 | -----
29 |
62 |
--------------------------------------------------------------------------------
/tests/InverseFixture/MethodAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
19 | -----
20 |
38 |
--------------------------------------------------------------------------------
/tests/InverseFixture/MixinAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
19 | -----
20 |
38 |
--------------------------------------------------------------------------------
/tests/InverseFixture/ParamAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
53 | -----
54 |
116 |
--------------------------------------------------------------------------------
/tests/InverseFixture/ParamOutAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
54 | -----
55 |
118 |
--------------------------------------------------------------------------------
/tests/InverseFixture/PropertyAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
19 | -----
20 |
38 |
--------------------------------------------------------------------------------
/tests/InverseFixture/PropertyReadAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
19 | -----
20 |
38 |
--------------------------------------------------------------------------------
/tests/InverseFixture/PropertyWriteAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
19 | -----
20 |
38 |
--------------------------------------------------------------------------------
/tests/InverseFixture/PureAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
37 | -----
38 |
80 |
--------------------------------------------------------------------------------
/tests/InverseFixture/RequireExtendsAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
27 | -----
28 |
56 |
--------------------------------------------------------------------------------
/tests/InverseFixture/RequireImplementsAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
27 | -----
28 |
56 |
--------------------------------------------------------------------------------
/tests/InverseFixture/ReturnsAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
46 | -----
47 |
100 |
--------------------------------------------------------------------------------
/tests/InverseFixture/SelfOutAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 | ')]
11 | public function add()
12 | {
13 | }
14 |
15 | /**
16 | * @codeCoverageIgnore
17 | */
18 | #[SelfOut('self')]
19 | public function addMore()
20 | {
21 | }
22 |
23 | #[Param(name:'string')]
24 | #[SelfOut('self')]
25 | public function addAnother()
26 | {
27 | }
28 |
29 | #[SelfOut('self')] // this is the new type
30 | public function addUserName()
31 | {
32 | }
33 | }
34 |
35 | ?>
36 | -----
37 |
48 | */
49 | public function add()
50 | {
51 | }
52 |
53 | /**
54 | * @codeCoverageIgnore
55 | * @phpstan-self-out self
56 | */
57 | public function addMore()
58 | {
59 | }
60 |
61 | /**
62 | * @param string $name
63 | * @phpstan-self-out self
64 | */
65 | public function addAnother()
66 | {
67 | }
68 |
69 | /**
70 | * @phpstan-self-out self
71 | */
72 | public function addUserName()
73 | {
74 | }
75 | }
76 |
77 | ?>
78 |
--------------------------------------------------------------------------------
/tests/InverseFixture/TemplateAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
59 | -----
60 |
127 |
--------------------------------------------------------------------------------
/tests/InverseFixture/TemplateContravariantAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
22 | -----
23 |
44 |
--------------------------------------------------------------------------------
/tests/InverseFixture/TemplateCovariantAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
21 | -----
22 |
42 |
--------------------------------------------------------------------------------
/tests/InverseFixture/TemplateExtendsAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 | ')] // this is the extended class
19 | class TemplateExtendsAttributeTest extends TemplateClass
20 | {
21 | }
22 |
23 | #[TemplateExtends('TemplateClass')]
24 | class TemplateExtendsAttributeTest2 extends TemplateClass
25 | {
26 | }
27 |
28 | ?>
29 | -----
30 |
49 | */
50 | class TemplateExtendsAttributeTest extends TemplateClass
51 | {
52 | }
53 |
54 | /**
55 | * @template-extends TemplateClass
56 | */
57 | class TemplateExtendsAttributeTest2 extends TemplateClass
58 | {
59 | }
60 |
61 | ?>
62 |
--------------------------------------------------------------------------------
/tests/InverseFixture/TemplateImplementsAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 | ')] // this is the implemented interface
19 | class TemplateImplementsAttributeTest implements TemplateInterface
20 | {
21 | }
22 |
23 | ?>
24 | -----
25 |
44 | */
45 | class TemplateImplementsAttributeTest implements TemplateInterface
46 | {
47 | }
48 |
49 | ?>
50 |
--------------------------------------------------------------------------------
/tests/InverseFixture/TemplateUseAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 | ')] // this is the used trait
16 | class TemplateUseAttributeTest
17 | {
18 | /**
19 | * @codeCoverageIgnore
20 | */
21 | use TemplateTrait;
22 | }
23 |
24 | ?>
25 | -----
26 |
49 | */
50 | use TemplateTrait;
51 | }
52 |
53 | ?>
54 |
--------------------------------------------------------------------------------
/tests/InverseFixture/ThrowsAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
47 | -----
48 |
102 |
--------------------------------------------------------------------------------
/tests/InverseFixture/TypeAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
28 | -----
29 |
62 |
--------------------------------------------------------------------------------
/tests/SpecialFixture/AssertAttributeTestWithAssertOnParam.php.inc:
--------------------------------------------------------------------------------
1 | item
43 | */
44 | public function checkPropertyName($name)
45 | {
46 | if (!is_string($name)) {
47 | throw new Exception();
48 | }
49 | }
50 |
51 | /**
52 | * @phpstan-assert string $this->getName()
53 | */
54 | public function checkMethodName($name)
55 | {
56 | if (!is_string($name)) {
57 | throw new Exception();
58 | }
59 | }
60 |
61 | /**
62 | * @codeCoverageIgnore
63 | * @phpstan-assert string $name
64 | */
65 | public function checkMoreNames($name)
66 | {
67 | if (!is_string($name)) {
68 | throw new Exception();
69 | }
70 | }
71 |
72 | /**
73 | * @phpstan-assert string $name
74 | */
75 | #[Returns('string')]
76 | public function checkAnotherName($name)
77 | {
78 | if (!is_string($name)) {
79 | throw new Exception();
80 | }
81 | }
82 |
83 | /**
84 | * @phpstan-assert string $name1
85 | * @phpstan-assert string $name2
86 | */
87 | public function checkTwoNames($name1, $name2)
88 | {
89 | if (!is_string($name1) || !is_string($name2)) {
90 | throw new Exception();
91 | }
92 | }
93 |
94 | /**
95 | * @phpstan-assert string $name2
96 | */
97 | #[Assert(name1: 'string')]
98 | public function checkTwoMoreNames($name1, $name2)
99 | {
100 | if (!is_string($name1) || !is_string($name2)) {
101 | throw new Exception();
102 | }
103 | }
104 |
105 | /**
106 | * @psalm-assert string $name
107 | */
108 | public function checkPsalmName($name)
109 | {
110 | if (!is_string($name)) {
111 | throw new Exception();
112 | }
113 | }
114 | }
115 |
116 | /**
117 | * @phpstan-assert string $name
118 | */
119 | function checkName($name)
120 | {
121 | if (!is_string($name)) {
122 | throw new Exception();
123 | }
124 | }
125 |
126 | ?>
127 | -----
128 | item')]
163 | public function checkPropertyName($name)
164 | {
165 | if (!is_string($name)) {
166 | throw new Exception();
167 | }
168 | }
169 |
170 | #[Assert('string $this->getName()')]
171 | public function checkMethodName($name)
172 | {
173 | if (!is_string($name)) {
174 | throw new Exception();
175 | }
176 | }
177 |
178 | /**
179 | * @codeCoverageIgnore
180 | */
181 | public function checkMoreNames(#[Assert('string')]
182 | $name)
183 | {
184 | if (!is_string($name)) {
185 | throw new Exception();
186 | }
187 | }
188 |
189 | #[Returns('string')]
190 | public function checkAnotherName(#[Assert('string')]
191 | $name)
192 | {
193 | if (!is_string($name)) {
194 | throw new Exception();
195 | }
196 | }
197 |
198 | public function checkTwoNames(#[Assert('string')]
199 | $name1, #[Assert('string')]
200 | $name2)
201 | {
202 | if (!is_string($name1) || !is_string($name2)) {
203 | throw new Exception();
204 | }
205 | }
206 |
207 | #[Assert(name1: 'string')]
208 | public function checkTwoMoreNames($name1, #[Assert('string')]
209 | $name2)
210 | {
211 | if (!is_string($name1) || !is_string($name2)) {
212 | throw new Exception();
213 | }
214 | }
215 |
216 | public function checkPsalmName(#[Assert('string')]
217 | $name)
218 | {
219 | if (!is_string($name)) {
220 | throw new Exception();
221 | }
222 | }
223 | }
224 |
225 | function checkName(#[Assert('string')]
226 | $name)
227 | {
228 | if (!is_string($name)) {
229 | throw new Exception();
230 | }
231 | }
232 |
233 | ?>
234 |
--------------------------------------------------------------------------------
/tests/SpecialFixture/AssertIfFalseAttributeTestWithAssertOnParam.php.inc:
--------------------------------------------------------------------------------
1 | item
37 | */
38 | public function checkPropertyName($name)
39 | {
40 | return !is_string($name);
41 | }
42 |
43 | /**
44 | * @phpstan-assert-if-false string $this->getName()
45 | */
46 | public function checkMethodName($name)
47 | {
48 | return !is_string($name);
49 | }
50 |
51 | /**
52 | * @codeCoverageIgnore
53 | * @phpstan-assert-if-false string $name
54 | */
55 | public function checkMoreNames($name)
56 | {
57 | return !is_string($name);
58 | }
59 |
60 | /**
61 | * @phpstan-assert-if-false string $name
62 | */
63 | #[Returns('string')]
64 | public function checkAnotherName($name)
65 | {
66 | return !is_string($name);
67 | }
68 |
69 | /**
70 | * @phpstan-assert-if-false string $name1
71 | * @phpstan-assert-if-false string $name2
72 | */
73 | public function checkTwoNames($name1, $name2)
74 | {
75 | return !is_string($name1) || !is_string($name2);
76 | }
77 |
78 | /**
79 | * @phpstan-assert-if-false string $name2
80 | */
81 | #[AssertIfFalse(name1: 'string')]
82 | public function checkTwoMoreNames($name1, $name2)
83 | {
84 | return !is_string($name1) || !is_string($name2);
85 | }
86 |
87 | /**
88 | * @psalm-assert-if-false string $name
89 | */
90 | public function checkPsalmName($name)
91 | {
92 | return !is_string($name);
93 | }
94 | }
95 |
96 | /**
97 | * @phpstan-assert-if-false string $name
98 | */
99 | function checkName($name)
100 | {
101 | return !is_string($name);
102 | }
103 |
104 | ?>
105 | -----
106 | item')]
135 | public function checkPropertyName($name)
136 | {
137 | return !is_string($name);
138 | }
139 |
140 | #[AssertIfFalse('string $this->getName()')]
141 | public function checkMethodName($name)
142 | {
143 | return !is_string($name);
144 | }
145 |
146 | /**
147 | * @codeCoverageIgnore
148 | */
149 | public function checkMoreNames(#[AssertIfFalse('string')]
150 | $name)
151 | {
152 | return !is_string($name);
153 | }
154 |
155 | #[Returns('string')]
156 | public function checkAnotherName(#[AssertIfFalse('string')]
157 | $name)
158 | {
159 | return !is_string($name);
160 | }
161 |
162 | public function checkTwoNames(#[AssertIfFalse('string')]
163 | $name1, #[AssertIfFalse('string')]
164 | $name2)
165 | {
166 | return !is_string($name1) || !is_string($name2);
167 | }
168 |
169 | #[AssertIfFalse(name1: 'string')]
170 | public function checkTwoMoreNames($name1, #[AssertIfFalse('string')]
171 | $name2)
172 | {
173 | return !is_string($name1) || !is_string($name2);
174 | }
175 |
176 | public function checkPsalmName(#[AssertIfFalse('string')]
177 | $name)
178 | {
179 | return !is_string($name);
180 | }
181 | }
182 |
183 | function checkName(#[AssertIfFalse('string')]
184 | $name)
185 | {
186 | return !is_string($name);
187 | }
188 |
189 | ?>
190 |
--------------------------------------------------------------------------------
/tests/SpecialFixture/AssertIfTrueAttributeTestWithAssertOnParam.php.inc:
--------------------------------------------------------------------------------
1 | item
37 | */
38 | public function checkPropertyName($name)
39 | {
40 | return !is_string($name);
41 | }
42 |
43 | /**
44 | * @phpstan-assert-if-true string $this->getName()
45 | */
46 | public function checkMethodName($name)
47 | {
48 | return !is_string($name);
49 | }
50 |
51 | /**
52 | * @codeCoverageIgnore
53 | * @phpstan-assert-if-true string $name
54 | */
55 | public function checkMoreNames($name)
56 | {
57 | return !is_string($name);
58 | }
59 |
60 | /**
61 | * @phpstan-assert-if-true string $name
62 | */
63 | #[Returns('string')]
64 | public function checkAnotherName($name)
65 | {
66 | return !is_string($name);
67 | }
68 |
69 | /**
70 | * @phpstan-assert-if-true string $name1
71 | * @phpstan-assert-if-true string $name2
72 | */
73 | public function checkTwoNames($name1, $name2)
74 | {
75 | return !is_string($name1) || !is_string($name2);
76 | }
77 |
78 | /**
79 | * @phpstan-assert-if-true string $name2
80 | */
81 | #[AssertIfTrue(name1: 'string')]
82 | public function checkTwoMoreNames($name1, $name2)
83 | {
84 | return !is_string($name1) || !is_string($name2);
85 | }
86 |
87 | /**
88 | * @psalm-assert-if-true string $name
89 | */
90 | public function checkPsalmName($name)
91 | {
92 | return !is_string($name);
93 | }
94 | }
95 |
96 | /**
97 | * @phpstan-assert-if-true string $name
98 | */
99 | function checkName($name)
100 | {
101 | return !is_string($name);
102 | }
103 |
104 | ?>
105 | -----
106 | item')]
135 | public function checkPropertyName($name)
136 | {
137 | return !is_string($name);
138 | }
139 |
140 | #[AssertIfTrue('string $this->getName()')]
141 | public function checkMethodName($name)
142 | {
143 | return !is_string($name);
144 | }
145 |
146 | /**
147 | * @codeCoverageIgnore
148 | */
149 | public function checkMoreNames(#[AssertIfTrue('string')]
150 | $name)
151 | {
152 | return !is_string($name);
153 | }
154 |
155 | #[Returns('string')]
156 | public function checkAnotherName(#[AssertIfTrue('string')]
157 | $name)
158 | {
159 | return !is_string($name);
160 | }
161 |
162 | public function checkTwoNames(#[AssertIfTrue('string')]
163 | $name1, #[AssertIfTrue('string')]
164 | $name2)
165 | {
166 | return !is_string($name1) || !is_string($name2);
167 | }
168 |
169 | #[AssertIfTrue(name1: 'string')]
170 | public function checkTwoMoreNames($name1, #[AssertIfTrue('string')]
171 | $name2)
172 | {
173 | return !is_string($name1) || !is_string($name2);
174 | }
175 |
176 | public function checkPsalmName(#[AssertIfTrue('string')]
177 | $name)
178 | {
179 | return !is_string($name);
180 | }
181 | }
182 |
183 | function checkName(#[AssertIfTrue('string')]
184 | $name)
185 | {
186 | return !is_string($name);
187 | }
188 |
189 | ?>
190 |
--------------------------------------------------------------------------------
/tests/SpecialFixture/ExcludeAnnotationsTest.php.inc:
--------------------------------------------------------------------------------
1 |
27 | -----
28 |
54 |
--------------------------------------------------------------------------------
/tests/SpecialFixture/ParamAttributeTestWithParamOnParam.php.inc:
--------------------------------------------------------------------------------
1 |
80 | -----
81 |
146 |
--------------------------------------------------------------------------------
/tests/SpecialFixture/ParamOutAttributeTestWithParamOnParam.php.inc:
--------------------------------------------------------------------------------
1 |
82 | -----
83 |
150 |
--------------------------------------------------------------------------------
/tests/SpecialFixture/PropertyAttributeTestForVarAnnotation.php.inc:
--------------------------------------------------------------------------------
1 |
38 | -----
39 |
69 |
--------------------------------------------------------------------------------
/tests/SpecialFixture/TypeAttributeTestForReturnAnnotation.php.inc:
--------------------------------------------------------------------------------
1 |
61 | -----
62 |
113 |
--------------------------------------------------------------------------------
/tests/SpecialFixture/TypeAttributeTestForTypeClassAnnotation.php.inc:
--------------------------------------------------------------------------------
1 |
18 | -----
19 |
36 |
--------------------------------------------------------------------------------
/tests/WithExtraRulesFixture/ParamAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
18 | -----
19 |
35 |
--------------------------------------------------------------------------------
/tests/WithExtraRulesFixture/ReturnsAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
25 | -----
26 |
49 |
--------------------------------------------------------------------------------
/tests/WithExtraRulesFixture/TypeAttributeTest.php.inc:
--------------------------------------------------------------------------------
1 |
17 | -----
18 |
33 |
--------------------------------------------------------------------------------
/tests/config/configured-both-ways-rule.php:
--------------------------------------------------------------------------------
1 | withSets([
11 | PhpStaticAnalysisAttributesToAnnotationsSetList::ATTRIBUTES_TO_ANNOTATIONS
12 | ])
13 | ->withSets([
14 | PhpStaticAnalysisAnnotationsToAttributesSetList::ANNOTATIONS_TO_ATTRIBUTES
15 | ])
16 | ->withImportNames();
17 |
--------------------------------------------------------------------------------
/tests/config/configured-inverse-rule.php:
--------------------------------------------------------------------------------
1 | withSets([
10 | PhpStaticAnalysisAttributesToAnnotationsSetList::ATTRIBUTES_TO_ANNOTATIONS
11 | ])
12 | ->withImportNames();
13 |
--------------------------------------------------------------------------------
/tests/config/configured-rule-with-assert-on-param.php:
--------------------------------------------------------------------------------
1 | withSets([
11 | PhpStaticAnalysisAnnotationsToAttributesSetList::ANNOTATIONS_TO_ATTRIBUTES
12 | ])
13 | ->withConfiguredRule(
14 | AnnotationsToAttributesRector::class,
15 | [
16 | 'addAssertAttributeOnParameters' => true,
17 | ]
18 | )
19 | ->withImportNames();
20 |
--------------------------------------------------------------------------------
/tests/config/configured-rule-with-exclude-annotations.php:
--------------------------------------------------------------------------------
1 | withSets([
11 | PhpStaticAnalysisAnnotationsToAttributesSetList::ANNOTATIONS_TO_ATTRIBUTES
12 | ])
13 | ->withConfiguredRule(
14 | AnnotationsToAttributesRector::class,
15 | [
16 | 'excludeAnnotations' => ['throws', 'deprecated'],
17 | ]
18 | )
19 | ->withImportNames();
20 |
--------------------------------------------------------------------------------
/tests/config/configured-rule-with-param-on-param.php:
--------------------------------------------------------------------------------
1 | withSets([
11 | PhpStaticAnalysisAnnotationsToAttributesSetList::ANNOTATIONS_TO_ATTRIBUTES
12 | ])
13 | ->withConfiguredRule(
14 | AnnotationsToAttributesRector::class,
15 | [
16 | 'addParamAttributeOnParameters' => true,
17 | ]
18 | )
19 | ->withImportNames();
20 |
--------------------------------------------------------------------------------
/tests/config/configured-rule-with-property-attribute-for-var.php:
--------------------------------------------------------------------------------
1 | withSets([
11 | PhpStaticAnalysisAnnotationsToAttributesSetList::ANNOTATIONS_TO_ATTRIBUTES
12 | ])
13 | ->withConfiguredRule(
14 | AnnotationsToAttributesRector::class,
15 | [
16 | 'usePropertyAttributeForVarAnnotation' => true,
17 | ]
18 | )
19 | ->withImportNames();
20 |
--------------------------------------------------------------------------------
/tests/config/configured-rule-with-type-attribute-for-return.php:
--------------------------------------------------------------------------------
1 | withSets([
11 | PhpStaticAnalysisAnnotationsToAttributesSetList::ANNOTATIONS_TO_ATTRIBUTES
12 | ])
13 | ->withConfiguredRule(
14 | AnnotationsToAttributesRector::class,
15 | [
16 | 'useTypeAttributeForReturnAnnotation' => true,
17 | ]
18 | )
19 | ->withImportNames();
20 |
--------------------------------------------------------------------------------
/tests/config/configured-rule-with-type-attribute-for-type-class.php:
--------------------------------------------------------------------------------
1 | withSets([
11 | PhpStaticAnalysisAnnotationsToAttributesSetList::ANNOTATIONS_TO_ATTRIBUTES
12 | ])
13 | ->withConfiguredRule(
14 | AnnotationsToAttributesRector::class,
15 | [
16 | 'useTypeAttributeForTypeClassAnnotation' => true,
17 | ]
18 | )
19 | ->withImportNames();
20 |
--------------------------------------------------------------------------------
/tests/config/configured-rule.php:
--------------------------------------------------------------------------------
1 | withSets([
10 | PhpStaticAnalysisAnnotationsToAttributesSetList::ANNOTATIONS_TO_ATTRIBUTES
11 | ])
12 | ->withImportNames();
13 |
--------------------------------------------------------------------------------
/tests/config/configured-with-extra-rule-rule.php:
--------------------------------------------------------------------------------
1 | withSets([
14 | PhpStaticAnalysisAttributesToAnnotationsSetList::ATTRIBUTES_TO_ANNOTATIONS
15 | ])
16 | ->withRules([
17 | RemoveUselessParamTagRector::class,
18 | RemoveUselessReturnTagRector::class,
19 | RemoveUselessVarTagRector::class
20 | ])
21 | ->withSets([
22 | PhpStaticAnalysisAnnotationsToAttributesSetList::ANNOTATIONS_TO_ATTRIBUTES
23 | ])
24 | ->withImportNames();
25 |
--------------------------------------------------------------------------------