diff --git a/.gitignore b/.gitignore index c1ffed2..c26410d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ composer.lock # php (phpunit) build/logs/ .phpunit.result.cache +/.phpunit.result/ # phpcs fixer .php_cs.cache diff --git a/composer.json b/composer.json index 8ecd799..1e6a143 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "phpdocumentor/reflection-common": "~2.2", "phpstan/phpdoc-parser": "~1.23", "voku/simple-cache": "~4.1", - "nikic/php-parser": "~4.16" + "nikic/php-parser": "^4.18 || ^5" }, "require-dev": { "phpunit/phpunit": "~6.0 || ~7.0 || ~9.0" @@ -38,5 +38,16 @@ "psr-4": { "voku\\tests\\": "tests/" } + }, + "scripts": { + "test-coverage": [ + "Composer\\Config::disableProcessTimeout", + "if [ \"$XDEBUG_MODE\" != \"coverage\" ]; then echo \"Run with 'XDEBUG_MODE=coverage composer test-coverage'\"; exit 1; fi;", + "phpunit --coverage-text --coverage-clover .phpunit.result/unitclover.xml --coverage-php .phpunit.result/unitphp.cov --coverage-html .phpunit.result/html -d memory_limit=-1 --order-by=random", + "# Run 'open ./.phpunit.result/html/index.html' to view report." + ] + }, + "scripts-descriptions": { + "test-coverage": "Run PHPUnit tests with coverage. Use 'XDEBUG_MODE=coverage composer test-coverage' to run, 'open ./.phpunit.result/html/index.html' to view." } } diff --git a/src/voku/SimplePhpParser/Model/BasePHPElement.php b/src/voku/SimplePhpParser/Model/BasePHPElement.php index 55fc0ac..0ece538 100644 --- a/src/voku/SimplePhpParser/Model/BasePHPElement.php +++ b/src/voku/SimplePhpParser/Model/BasePHPElement.php @@ -97,6 +97,13 @@ protected static function getFQN($node): string protected function prepareNode(Node $node): void { - $this->line = $node->getLine(); + $this->line = method_exists($node, 'getStartLine') + ? $node->getStartLine() + /** + * Deprecated in PHP-Parser v5 + * + * @see https://github.com/nikic/PHP-Parser/blob/master/UPGRADE-5.0.md#miscellaneous-changes + */ + : $node->getLine(); } } diff --git a/src/voku/SimplePhpParser/Parsers/Helper/Utils.php b/src/voku/SimplePhpParser/Parsers/Helper/Utils.php index dcd4cc4..6e422e1 100644 --- a/src/voku/SimplePhpParser/Parsers/Helper/Utils.php +++ b/src/voku/SimplePhpParser/Parsers/Helper/Utils.php @@ -112,7 +112,9 @@ public static function getPhpParserValueFromNode( && $node->value->name ) { - $value = implode('\\', $node->value->name->getParts()) ?: $node->value->name->name; + $value = method_exists($node->value->name,'getParts') + ? implode('\\', $node->value->name->getParts()) + : $node->value->name->name; return $value === 'null' ? null : $value; } } @@ -468,7 +470,7 @@ public static function getCpuCores(): int } /** @noinspection PhpUsageOfSilenceOperatorInspection */ - $ret = @\shell_exec('nproc'); + $ret = @\shell_exec('nproc 2>&1'); if (\is_string($ret)) { $ret = \trim($ret); /** @noinspection PhpAssignmentInConditionInspection */ @@ -495,6 +497,23 @@ public static function getCpuCores(): int } } + /** + * macOS (FreeBSD) + */ + $ret = @\shell_exec('sysctl -n hw.ncpu'); + if (\is_string($ret)) { + $ret = \trim($ret); + /** @noinspection PhpAssignmentInConditionInspection */ + if ($ret && ($tmp = \filter_var($ret, \FILTER_VALIDATE_INT)) !== false) { + $return = (int)round($tmp / 2); + if ($return > 1) { + return $return; + } + + return 1; + } + } + return 1; } diff --git a/src/voku/SimplePhpParser/Parsers/PhpCodeParser.php b/src/voku/SimplePhpParser/Parsers/PhpCodeParser.php index 5645859..c3b0ea7 100644 --- a/src/voku/SimplePhpParser/Parsers/PhpCodeParser.php +++ b/src/voku/SimplePhpParser/Parsers/PhpCodeParser.php @@ -5,7 +5,6 @@ namespace voku\SimplePhpParser\Parsers; use FilesystemIterator; -use PhpParser\Lexer\Emulative; use PhpParser\NodeTraverser; use PhpParser\NodeVisitor\NameResolver; use PhpParser\ParserFactory; @@ -200,20 +199,7 @@ public static function process( ParserContainer $parserContainer, ASTVisitor $visitor ) { - $parser = (new ParserFactory())->create( - ParserFactory::PREFER_PHP7, - new Emulative( - [ - 'usedAttributes' => [ - 'comments', - 'startLine', - 'endLine', - 'startTokenPos', - 'endTokenPos', - ], - ] - ) - ); + $parser = (new ParserFactory())->createForNewestSupportedVersion(); $errorHandler = new ParserErrorHandler();