From 7dbbab28c411f1e78535014658cc004025a16bbd Mon Sep 17 00:00:00 2001 From: Kirill Nesmeyanov Date: Mon, 1 Jul 2024 12:28:42 +0300 Subject: [PATCH 1/9] Upgrade dev dependencies --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 4df3f53..844e0b5 100644 --- a/composer.json +++ b/composer.json @@ -19,11 +19,11 @@ "require-dev": { "friendsofphp/php-cs-fixer": "^3.53", "jetbrains/phpstorm-attributes": "^1.0", - "phpstan/extension-installer": "^1.3", + "phpstan/extension-installer": "^1.4", "phpstan/phpstan": "^1.11", "phpstan/phpstan-strict-rules": "^1.6", "phpunit/phpunit": "^10.5|^11.0", - "rector/rector": "^1.0", + "rector/rector": "^1.1", "type-lang/parser": "^1.0" }, "autoload-dev": { From 7ae9470400bbdd261c956bb10744ffddbb9a7449 Mon Sep 17 00:00:00 2001 From: Kirill Nesmeyanov Date: Mon, 9 Sep 2024 23:36:35 +0300 Subject: [PATCH 2/9] Improve phpdoc --- src/Parser/Comment/RegexCommentParser.php | 8 ++++---- src/Parser/Description/DescriptionParserInterface.php | 2 +- src/Parser/Tag/TagParserInterface.php | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Parser/Comment/RegexCommentParser.php b/src/Parser/Comment/RegexCommentParser.php index 0cf870b..c6eed7d 100644 --- a/src/Parser/Comment/RegexCommentParser.php +++ b/src/Parser/Comment/RegexCommentParser.php @@ -79,18 +79,18 @@ private function lex(string $docblock): iterable * Returns significant parts of the DocBlock comment with their offsets of * the returned section, relative to the beginning. * - * ```php + * ``` * $result = $reader->read(<<<'DOC' * /** * * Example line 1 * * - * * @tag1 type Description of tag1 - * *∕ + * * @​tag1 type Description of tag1 + * *​/ * DOC); * * // The $result contains: * // object(Segment) { offset: 7, text: 'Example line 1' } - * // object(Segment) { offset: 28, text: '@tag1 type Description of tag1' } + * // object(Segment) { offset: 28, text: '@​tag1 type Description of tag1' } * ``` * * @return iterable diff --git a/src/Parser/Description/DescriptionParserInterface.php b/src/Parser/Description/DescriptionParserInterface.php index 2fc19e7..e448af5 100644 --- a/src/Parser/Description/DescriptionParserInterface.php +++ b/src/Parser/Description/DescriptionParserInterface.php @@ -13,7 +13,7 @@ interface DescriptionParserInterface * * ```php * $description = $parser->parse(<<<'DOC' - * This is a description with {@link Example}. + * This is a description with {@​link Example}. * DOC); * * // $description MAY contains: diff --git a/src/Parser/Tag/TagParserInterface.php b/src/Parser/Tag/TagParserInterface.php index b8d6616..9942973 100644 --- a/src/Parser/Tag/TagParserInterface.php +++ b/src/Parser/Tag/TagParserInterface.php @@ -12,8 +12,8 @@ interface TagParserInterface /** * Returns concrete tag instance by the tag signature. * - * ```php - * $tag = $parser->parse('@param string $tag'); + * ``` + * $tag = $parser->parse('@​param string $tag'); * * // $tag may contains: * // object(ParamTag) { From dddd77b65ea50a49df80f03fdc3b31a56c74995a Mon Sep 17 00:00:00 2001 From: Kirill Nesmeyanov Date: Fri, 27 Sep 2024 01:45:47 +0300 Subject: [PATCH 3/9] Rename "psalm" GH stage to the linter --- .github/workflows/static-analysis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 3fccdb7..0a04cad 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -5,8 +5,8 @@ on: pull_request: jobs: - psalm: - name: Psalm + linter: + name: Linter runs-on: ${{ matrix.os }} strategy: fail-fast: false From 850dd49cd7a297918a05241f5c06ea58236548ed Mon Sep 17 00:00:00 2001 From: Kirill Nesmeyanov Date: Sun, 29 Sep 2024 12:33:23 +0300 Subject: [PATCH 4/9] Fix tests --- .github/workflows/security.yml | 2 +- .github/workflows/tests.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index 939d4a2..5a4d604 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -4,7 +4,7 @@ on: push: pull_request: schedule: - - cron: '0 0 * * *' + - cron: '0 0 * * 0' jobs: security: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0ef0d03..1e5aa6f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -4,7 +4,7 @@ on: push: pull_request: schedule: - - cron: '0 0 * * *' + - cron: '0 0 * * 0' jobs: tests: From 1e80f4fc47aba039676b00db2a33f9854a3deeb5 Mon Sep 17 00:00:00 2001 From: Kirill Nesmeyanov Date: Fri, 10 Jan 2025 18:54:22 +0300 Subject: [PATCH 5/9] Replace branch alias from 1.0.x to 1.x --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 844e0b5..3101d57 100644 --- a/composer.json +++ b/composer.json @@ -33,8 +33,8 @@ }, "extra": { "branch-alias": { - "dev-master": "1.0.x-dev", - "dev-main": "1.0.x-dev" + "dev-master": "1.x-dev", + "dev-main": "1.x-dev" } }, "config": { From 17344c3a84c0b14ec9ad9be33d8f49b8488755f7 Mon Sep 17 00:00:00 2001 From: Kirill Nesmeyanov Date: Sat, 11 Jan 2025 02:41:33 +0300 Subject: [PATCH 6/9] Bump phpstan from 1.x to 2.x and remove unnecessary psalm annotations --- composer.json | 9 +++------ phpstan.neon | 4 +++- src/Parser.php | 7 +------ src/Tag/Content.php | 2 -- src/Tag/Content/TypeParserApplicator.php | 1 - src/Tag/Description/DescriptionInterface.php | 2 -- src/Tag/Description/DescriptionProviderInterface.php | 2 -- .../Description/OptionalDescriptionProviderInterface.php | 2 -- src/Tag/OptionalTypeProviderInterface.php | 2 -- src/Tag/OptionalVariableNameProviderInterface.php | 2 -- src/Tag/TagInterface.php | 4 ---- src/Tag/TagsProviderInterface.php | 2 -- src/Tag/TypeProviderInterface.php | 2 -- src/Tag/VariableNameProviderInterface.php | 2 -- 14 files changed, 7 insertions(+), 36 deletions(-) diff --git a/composer.json b/composer.json index 3101d57..d2ee252 100644 --- a/composer.json +++ b/composer.json @@ -19,9 +19,9 @@ "require-dev": { "friendsofphp/php-cs-fixer": "^3.53", "jetbrains/phpstorm-attributes": "^1.0", - "phpstan/extension-installer": "^1.4", - "phpstan/phpstan": "^1.11", - "phpstan/phpstan-strict-rules": "^1.6", + "phpstan/phpstan": "^2.0", + "phpstan/phpstan-deprecation-rules": "^2.0", + "phpstan/phpstan-strict-rules": "^2.0", "phpunit/phpunit": "^10.5|^11.0", "rector/rector": "^1.1", "type-lang/parser": "^1.0" @@ -44,9 +44,6 @@ "optimize-autoloader": true, "preferred-install": { "*": "dist" - }, - "allow-plugins": { - "phpstan/extension-installer": true } }, "scripts": { diff --git a/phpstan.neon b/phpstan.neon index 73151ee..3257d93 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,7 +1,9 @@ includes: - phar://phpstan.phar/conf/bleedingEdge.neon + - vendor/phpstan/phpstan-deprecation-rules/rules.neon + - vendor/phpstan/phpstan-strict-rules/rules.neon parameters: - level: 9 + level: max strictRules: allRules: true fileExtensions: diff --git a/src/Parser.php b/src/Parser.php index ef4fb67..74ed185 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -42,11 +42,7 @@ public function parse(#[Language('PHP')] string $docblock): DocBlock $mapper = new SourceMap(); try { - /** - * @var Segment $segment - * - * @psalm-suppress InvalidIterator - */ + /** @var Segment $segment */ foreach ($result = $this->analyze($docblock) as $segment) { $mapper->add($segment->offset, $segment->text); } @@ -72,7 +68,6 @@ public function parse(#[Language('PHP')] string $docblock): DocBlock */ private function analyze(string $docblock): \Generator { - /** @psalm-suppress InvalidIterator */ yield from $blocks = $this->groupByCommentSections($docblock); $description = null; diff --git a/src/Tag/Content.php b/src/Tag/Content.php index 623a7be..366fac4 100644 --- a/src/Tag/Content.php +++ b/src/Tag/Content.php @@ -24,8 +24,6 @@ class Content implements \Stringable /** * @var int<0, max> - * - * @psalm-readonly-allow-private-mutation */ public int $offset = 0; diff --git a/src/Tag/Content/TypeParserApplicator.php b/src/Tag/Content/TypeParserApplicator.php index 0e10c0e..d3b0c3e 100644 --- a/src/Tag/Content/TypeParserApplicator.php +++ b/src/Tag/Content/TypeParserApplicator.php @@ -32,7 +32,6 @@ public function __invoke(Content $lexer): TypeStatement try { $type = $this->parser->parse($lexer->value); } catch (ParserExceptionInterface $e) { - /** @psalm-suppress InvalidArgument */ throw $lexer->getTagException( message: \sprintf('Tag @%s contains an incorrect type', $this->tag), previous: $e, diff --git a/src/Tag/Description/DescriptionInterface.php b/src/Tag/Description/DescriptionInterface.php index ef0a3ec..20d65a1 100644 --- a/src/Tag/Description/DescriptionInterface.php +++ b/src/Tag/Description/DescriptionInterface.php @@ -16,8 +16,6 @@ interface DescriptionInterface extends \Stringable * Magic method {@link https://www.php.net/manual/en/language.oop5.magic.php#object.tostring} * allows a class to decide how it will react when it is treated like * a string. - * - * @psalm-immutable Each call to the method must return the same value. */ public function __toString(): string; } diff --git a/src/Tag/Description/DescriptionProviderInterface.php b/src/Tag/Description/DescriptionProviderInterface.php index 3319b4a..c91b92f 100644 --- a/src/Tag/Description/DescriptionProviderInterface.php +++ b/src/Tag/Description/DescriptionProviderInterface.php @@ -9,8 +9,6 @@ interface DescriptionProviderInterface extends OptionalDescriptionProviderInterf /** * Returns description object which can be represented as a string and * contains additional information. - * - * @psalm-immutable Each call to the method must return the same value. */ public function getDescription(): DescriptionInterface; } diff --git a/src/Tag/Description/OptionalDescriptionProviderInterface.php b/src/Tag/Description/OptionalDescriptionProviderInterface.php index c93a60f..0de030c 100644 --- a/src/Tag/Description/OptionalDescriptionProviderInterface.php +++ b/src/Tag/Description/OptionalDescriptionProviderInterface.php @@ -9,8 +9,6 @@ interface OptionalDescriptionProviderInterface /** * Returns description object which can be represented as a string and * contains additional information. - * - * @psalm-immutable Each call to the method must return the same value. */ public function getDescription(): ?DescriptionInterface; } diff --git a/src/Tag/OptionalTypeProviderInterface.php b/src/Tag/OptionalTypeProviderInterface.php index 16cf45d..7ceeb65 100644 --- a/src/Tag/OptionalTypeProviderInterface.php +++ b/src/Tag/OptionalTypeProviderInterface.php @@ -17,8 +17,6 @@ interface OptionalTypeProviderInterface /** * Returns an AST object of the type or {@see null} in case the * type is not specified. - * - * @psalm-immutable Each call to the method must return the same value. */ public function getType(): ?TypeStatement; } diff --git a/src/Tag/OptionalVariableNameProviderInterface.php b/src/Tag/OptionalVariableNameProviderInterface.php index 8c6052c..82189c8 100644 --- a/src/Tag/OptionalVariableNameProviderInterface.php +++ b/src/Tag/OptionalVariableNameProviderInterface.php @@ -11,8 +11,6 @@ interface OptionalVariableNameProviderInterface * which this tag is attached or {@see null} in case of the tag does * not contain a name. * - * @psalm-immutable Each call to the method must return the same value. - * * @return non-empty-string|null */ public function getVariableName(): ?string; diff --git a/src/Tag/TagInterface.php b/src/Tag/TagInterface.php index d51f230..dc2e5c4 100644 --- a/src/Tag/TagInterface.php +++ b/src/Tag/TagInterface.php @@ -15,8 +15,6 @@ interface TagInterface extends OptionalDescriptionProviderInterface, \Stringable * that is, can contain all the characters that can match the PHP FQN, as * well as the '-' character. * - * @psalm-immutable Each call to the method must return the same value. - * * @return non-empty-string */ public function getName(): string; @@ -26,8 +24,6 @@ public function getName(): string; * allows a class to decide how it will react when it is treated like * a string. * - * @psalm-immutable Each call to the method must return the same value. - * * @return string returns string representation of the object that * implements this interface (and/or {@see __toString()} magic * method) diff --git a/src/Tag/TagsProviderInterface.php b/src/Tag/TagsProviderInterface.php index 8fa3bfb..c721b54 100644 --- a/src/Tag/TagsProviderInterface.php +++ b/src/Tag/TagsProviderInterface.php @@ -13,8 +13,6 @@ interface TagsProviderInterface /** * Returns the tags for this object. * - * @psalm-immutable Each call to the method must return the same value. - * * @return iterable */ public function getTags(): iterable; diff --git a/src/Tag/TypeProviderInterface.php b/src/Tag/TypeProviderInterface.php index 2dfbdcb..d1b13b8 100644 --- a/src/Tag/TypeProviderInterface.php +++ b/src/Tag/TypeProviderInterface.php @@ -10,8 +10,6 @@ interface TypeProviderInterface extends OptionalTypeProviderInterface { /** * Returns an AST object of the type. - * - * @psalm-immutable Each call to the method must return the same value. */ public function getType(): TypeStatement; } diff --git a/src/Tag/VariableNameProviderInterface.php b/src/Tag/VariableNameProviderInterface.php index b39e76c..7e2d766 100644 --- a/src/Tag/VariableNameProviderInterface.php +++ b/src/Tag/VariableNameProviderInterface.php @@ -10,8 +10,6 @@ interface VariableNameProviderInterface extends OptionalVariableNameProviderInte * Returns the name of the variable (parameter, field, etc.) to * which this tag is attached. * - * @psalm-immutable Each call to the method must return the same value. - * * @return non-empty-string */ public function getVariableName(): string; From 3ae78edc3e90ed6c84808fea3c6440d5599c0b22 Mon Sep 17 00:00:00 2001 From: Kirill Nesmeyanov Date: Sat, 11 Jan 2025 02:53:41 +0300 Subject: [PATCH 7/9] Bump phpstan from 1.x to 2.1+ and remove unnecessary psalm annotations --- composer.json | 3 +-- phpstan.neon | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/composer.json b/composer.json index d2ee252..150d0b6 100644 --- a/composer.json +++ b/composer.json @@ -19,8 +19,7 @@ "require-dev": { "friendsofphp/php-cs-fixer": "^3.53", "jetbrains/phpstorm-attributes": "^1.0", - "phpstan/phpstan": "^2.0", - "phpstan/phpstan-deprecation-rules": "^2.0", + "phpstan/phpstan": "^2.1", "phpstan/phpstan-strict-rules": "^2.0", "phpunit/phpunit": "^10.5|^11.0", "rector/rector": "^1.1", diff --git a/phpstan.neon b/phpstan.neon index 3257d93..3be61f5 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,6 +1,5 @@ includes: - phar://phpstan.phar/conf/bleedingEdge.neon - - vendor/phpstan/phpstan-deprecation-rules/rules.neon - vendor/phpstan/phpstan-strict-rules/rules.neon parameters: level: max From 0fc59b9431383e8f93ad582ea1aee30392e13337 Mon Sep 17 00:00:00 2001 From: Kirill Nesmeyanov Date: Sat, 11 Jan 2025 03:02:06 +0300 Subject: [PATCH 8/9] Fix errors of phpstan 2.1+ --- src/Exception/ParsingException.php | 4 ++-- src/Tag/Content/OptionalIdentifierApplicator.php | 3 ++- src/Tag/Content/OptionalVariableNameApplicator.php | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Exception/ParsingException.php b/src/Exception/ParsingException.php index 810a820..5d2a6b4 100644 --- a/src/Exception/ParsingException.php +++ b/src/Exception/ParsingException.php @@ -45,8 +45,8 @@ public function withSource(string $source, int $offset): self return new static( source: $source, offset: $offset, - message: $this->message, - code: $this->code, + message: $this->getMessage(), + code: $this->getCode(), previous: $this, ); } diff --git a/src/Tag/Content/OptionalIdentifierApplicator.php b/src/Tag/Content/OptionalIdentifierApplicator.php index 0742dba..4e877e4 100644 --- a/src/Tag/Content/OptionalIdentifierApplicator.php +++ b/src/Tag/Content/OptionalIdentifierApplicator.php @@ -16,13 +16,14 @@ final class OptionalIdentifierApplicator extends Applicator */ public function __invoke(Content $lexer): ?string { + // @phpstan-ignore-next-line : PHPStan false positive if ($lexer->value === '') { return null; } \preg_match('/([a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)\b/u', $lexer->value, $matches); - if (\count($matches) !== 2 || $matches[1] === '') { + if (\count($matches) !== 2) { return null; } diff --git a/src/Tag/Content/OptionalVariableNameApplicator.php b/src/Tag/Content/OptionalVariableNameApplicator.php index 55e9e69..0710677 100644 --- a/src/Tag/Content/OptionalVariableNameApplicator.php +++ b/src/Tag/Content/OptionalVariableNameApplicator.php @@ -22,7 +22,7 @@ public function __invoke(Content $lexer): ?string \preg_match('/\$([a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)\b/u', $lexer->value, $matches); - if (\count($matches) !== 2 || $matches[1] === '') { + if (\count($matches) !== 2) { return null; } From 1a3beda4599656af586974b90cbfb206bbb68ec8 Mon Sep 17 00:00:00 2001 From: Kirill Nesmeyanov Date: Sat, 11 Jan 2025 03:11:49 +0300 Subject: [PATCH 9/9] Remove rector --- .github/workflows/codestyle.yml | 2 +- .github/workflows/security.yml | 2 +- .github/workflows/static-analysis.yml | 2 +- .github/workflows/tests.yml | 2 +- composer.json | 7 +------ rector.php | 15 --------------- 6 files changed, 5 insertions(+), 25 deletions(-) delete mode 100644 rector.php diff --git a/.github/workflows/codestyle.yml b/.github/workflows/codestyle.yml index 6385049..b12941f 100644 --- a/.github/workflows/codestyle.yml +++ b/.github/workflows/codestyle.yml @@ -5,7 +5,7 @@ on: pull_request: jobs: - psalm: + phpcs: name: Code Style runs-on: ${{ matrix.os }} strategy: diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml index 5a4d604..0c22d6f 100644 --- a/.github/workflows/security.yml +++ b/.github/workflows/security.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - php: [ '8.3' ] + php: [ '8.4' ] os: [ ubuntu-latest ] steps: - name: Set Git To Use LF diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 0a04cad..27fc95e 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - php: [ '8.3' ] + php: [ '8.4' ] os: [ ubuntu-latest ] steps: - name: Set Git To Use LF diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1e5aa6f..485da25 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: false matrix: - php: [ '8.1', '8.2', '8.3' ] + php: [ '8.1', '8.2', '8.3', '8.4' ] os: [ ubuntu-latest, macos-latest, windows-latest ] stability: [ prefer-lowest, prefer-stable ] steps: diff --git a/composer.json b/composer.json index 150d0b6..737882e 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,6 @@ "phpstan/phpstan": "^2.1", "phpstan/phpstan-strict-rules": "^2.0", "phpunit/phpunit": "^10.5|^11.0", - "rector/rector": "^1.1", "type-lang/parser": "^1.0" }, "autoload-dev": { @@ -56,11 +55,7 @@ "phpcs": "@phpcs:check", "phpcs:check": "php-cs-fixer fix --config=.php-cs-fixer.php --allow-risky=yes --dry-run --verbose --diff", - "phpcs:fix": "php-cs-fixer fix --config=.php-cs-fixer.php --allow-risky=yes --verbose --diff", - - "rector": "@rector:check", - "rector:check": "rector --dry-run --config=rector.php", - "rector:fix": "rector --config=rector.php" + "phpcs:fix": "php-cs-fixer fix --config=.php-cs-fixer.php --allow-risky=yes --verbose --diff" }, "minimum-stability": "dev", "prefer-stable": true diff --git a/rector.php b/rector.php deleted file mode 100644 index a68f327..0000000 --- a/rector.php +++ /dev/null @@ -1,15 +0,0 @@ -paths([__DIR__ . '/src']); - $config->cacheDirectory(__DIR__ . '/vendor/.cache.rector'); - - $config->sets([ - LevelSetList::UP_TO_PHP_81, - ]); -};