Composer installs update

This commit is contained in:
Clemens Schwaighofer
2022-03-14 19:49:37 +09:00
parent 40edbe271d
commit 38903020fb
33 changed files with 495 additions and 534 deletions

View File

@@ -10,21 +10,27 @@
namespace SebastianBergmann\CodeCoverage\StaticAnalysis;
use PhpParser\Node;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\BinaryOp;
use PhpParser\Node\Expr\CallLike;
use PhpParser\Node\Expr\Cast;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\Match_;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\NullsafePropertyFetch;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticPropertyFetch;
use PhpParser\Node\Expr\Ternary;
use PhpParser\Node\MatchArm;
use PhpParser\Node\Scalar\Encapsed;
use PhpParser\Node\Stmt\Break_;
use PhpParser\Node\Stmt\Case_;
use PhpParser\Node\Stmt\Catch_;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Continue_;
use PhpParser\Node\Stmt\Do_;
use PhpParser\Node\Stmt\Echo_;
@@ -60,6 +66,11 @@ final class ExecutableLinesFindingVisitor extends NodeVisitorAbstract
*/
private $propertyLines = [];
/**
* @psalm-var array<int, Return_>
*/
private $returns = [];
public function enterNode(Node $node): void
{
$this->savePropertyLines($node);
@@ -82,6 +93,8 @@ final class ExecutableLinesFindingVisitor extends NodeVisitorAbstract
*/
public function executableLines(): array
{
$this->computeReturns();
sort($this->executableLines);
return $this->executableLines;
@@ -98,6 +111,25 @@ final class ExecutableLinesFindingVisitor extends NodeVisitorAbstract
}
}
private function computeReturns(): void
{
foreach ($this->returns as $return) {
foreach (range($return->getStartLine(), $return->getEndLine()) as $loc) {
if (isset($this->executableLines[$loc])) {
continue 2;
}
}
$line = $return->getEndLine();
if ($return->expr !== null) {
$line = $return->expr->getStartLine();
}
$this->executableLines[$line] = $line;
}
}
/**
* @return int[]
*/
@@ -118,6 +150,46 @@ final class ExecutableLinesFindingVisitor extends NodeVisitorAbstract
return [$node->dim->getStartLine()];
}
if ($node instanceof Array_) {
$startLine = $node->getStartLine();
if (isset($this->executableLines[$startLine])) {
return [];
}
if ([] === $node->items) {
return [$node->getEndLine()];
}
if ($node->items[0] instanceof ArrayItem) {
return [$node->items[0]->getStartLine()];
}
}
if ($node instanceof ClassMethod) {
if ($node->name->name !== '__construct') {
return [];
}
$existsAPromotedProperty = false;
foreach ($node->getParams() as $param) {
if (0 !== ($param->flags & Class_::VISIBILITY_MODIFIER_MASK)) {
$existsAPromotedProperty = true;
break;
}
}
if ($existsAPromotedProperty) {
// Only the line with `function` keyword should be listed here
// but `nikic/php-parser` doesn't provide a way to fetch it
return range($node->getStartLine(), $node->name->getEndLine());
}
return [];
}
if ($node instanceof MethodCall) {
return [$node->name->getStartLine()];
}
@@ -134,6 +206,28 @@ final class ExecutableLinesFindingVisitor extends NodeVisitorAbstract
return $lines;
}
if ($node instanceof Match_) {
return [$node->cond->getStartLine()];
}
if ($node instanceof MatchArm) {
return [$node->body->getStartLine()];
}
if ($node instanceof Expression && (
$node->expr instanceof Cast ||
$node->expr instanceof Match_ ||
$node->expr instanceof MethodCall
)) {
return [];
}
if ($node instanceof Return_) {
$this->returns[] = $node;
return [];
}
return [$node->getStartLine()];
}
@@ -141,12 +235,14 @@ final class ExecutableLinesFindingVisitor extends NodeVisitorAbstract
{
return $node instanceof Assign ||
$node instanceof ArrayDimFetch ||
$node instanceof Array_ ||
$node instanceof BinaryOp ||
$node instanceof Break_ ||
$node instanceof CallLike ||
$node instanceof Case_ ||
$node instanceof Cast ||
$node instanceof Catch_ ||
$node instanceof ClassMethod ||
$node instanceof Closure ||
$node instanceof Continue_ ||
$node instanceof Do_ ||
@@ -160,6 +256,8 @@ final class ExecutableLinesFindingVisitor extends NodeVisitorAbstract
$node instanceof Foreach_ ||
$node instanceof Goto_ ||
$node instanceof If_ ||
$node instanceof Match_ ||
$node instanceof MatchArm ||
$node instanceof MethodCall ||
$node instanceof NullsafePropertyFetch ||
$node instanceof PropertyFetch ||

View File

@@ -13,6 +13,7 @@ use function array_unique;
use function assert;
use function file_get_contents;
use function is_array;
use function max;
use function sprintf;
use function substr_count;
use function token_get_all;
@@ -132,7 +133,7 @@ final class ParsingFileAnalyser implements FileAnalyser
}
$source = file_get_contents($filename);
$linesOfCode = substr_count($source, "\n");
$linesOfCode = max(substr_count($source, "\n") + 1, substr_count($source, "\r") + 1);
if ($linesOfCode === 0 && !empty($source)) {
$linesOfCode = 1;

View File

@@ -22,7 +22,7 @@ final class Version
public static function id(): string
{
if (self::$version === null) {
self::$version = (new VersionId('9.2.13', dirname(__DIR__)))->getVersion();
self::$version = (new VersionId('9.2.15', dirname(__DIR__)))->getVersion();
}
return self::$version;