Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to phpstan/phpdoc-parser 2.0 #1708

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ jobs:
dependencies:
- "highest"
php-version:
- "7.2"
- "7.3"
- "7.4"
- "8.0"
- "8.1"
Expand All @@ -45,7 +43,7 @@ jobs:
ini-values: error_reporting=-1, display_errors=On, zend.assertions=1

- name: "Reset composer platform"
if: matrix.php-version == '7.2' || matrix.php-version == '7.3' || matrix.php-version == '7.4'
if: matrix.php-version == '7.4'
run: "composer config --unset platform"

- name: "Install dependencies"
Expand Down Expand Up @@ -135,8 +133,6 @@ jobs:
- "lowest"
- "highest"
php-version:
- "7.2"
- "7.3"
- "7.4"
- "8.0"
- "8.1"
Expand All @@ -159,7 +155,7 @@ jobs:
ini-values: error_reporting=-1, display_errors=On, zend.assertions=1

- name: "Reset composer platform"
if: matrix.php-version == '7.2' || matrix.php-version == '7.3' || matrix.php-version == '7.4' || matrix.php-version == '8.0'
if: matrix.php-version == '7.4' || matrix.php-version == '8.0'
run: "composer config --unset platform"

- name: "Install dependencies"
Expand Down
29 changes: 18 additions & 11 deletions SlevomatCodingStandard/Helpers/PhpDocParserHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PHPStan\PhpDocParser\Parser\ConstExprParser;
use PHPStan\PhpDocParser\Parser\PhpDocParser;
use PHPStan\PhpDocParser\Parser\TypeParser;
use PHPStan\PhpDocParser\ParserConfig;
use PHPStan\PhpDocParser\Printer\Printer;

/**
Expand All @@ -22,7 +23,7 @@ public static function getLexer(): Lexer
static $lexer;

if ($lexer === null) {
$lexer = new Lexer(true);
$lexer = new Lexer(self::getConfig());
}

return $lexer;
Expand All @@ -33,17 +34,12 @@ public static function getParser(): PhpDocParser
static $parser;

if ($parser === null) {
$usedAttributes = ['lines' => true, 'indexes' => true];

$constantExpressionParser = new ConstExprParser(true, true, $usedAttributes);
$config = self::getConfig();
$constantExpressionParser = new ConstExprParser($config);
$parser = new PhpDocParser(
new TypeParser($constantExpressionParser, true, $usedAttributes),
$constantExpressionParser,
true,
true,
$usedAttributes,
true,
true
$config,
new TypeParser($config, $constantExpressionParser),
$constantExpressionParser
);
}

Expand Down Expand Up @@ -79,4 +75,15 @@ public static function cloneNode(Node $node): Node
return $cloneNode;
}

private static function getConfig(): ParserConfig
{
static $config;

if ($config === null) {
$config = new ParserConfig(['lines' => true, 'indexes' => true]);
}

return $config;
}

}
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
}
},
"require": {
"php": "^7.2 || ^8.0",
"php": "^7.4 || ^8.0",
"dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7 || ^1.0",
"phpstan/phpdoc-parser": "^1.23.1",
"phpstan/phpdoc-parser": "^2.0",
"squizlabs/php_codesniffer": "^3.9.0"
},
"require-dev": {
Expand All @@ -28,7 +28,7 @@
"phpstan/phpstan-deprecation-rules": "1.1.4",
"phpstan/phpstan-phpunit": "1.3.16",
"phpstan/phpstan-strict-rules": "1.5.2",
"phpunit/phpunit": "8.5.21|9.6.8|10.5.11"
"phpunit/phpunit": "9.6.8|10.5.11"
},
"autoload": {
"psr-4": {
Expand Down