Skip to content

Commit 65ad8d4

Browse files
Merge branch '9.2'
2 parents 6659d74 + ba4df04 commit 65ad8d4

File tree

6 files changed

+73
-2
lines changed

6 files changed

+73
-2
lines changed

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
2525
### Fixed
2626

2727
* [#971](https://github.com/sebastianbergmann/php-code-coverage/issues/971): PHP report does not handle serialized code coverage data larger than 2 GB
28+
* [#974](https://github.com/sebastianbergmann/php-code-coverage/issues/974): Executable line analysis fails for declarations with enumerations and unions
2829

2930
## [9.2.22] - 2022-12-18
3031

src/StaticAnalysis/ExecutableLinesFindingVisitor.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public function enterNode(Node $node): void
8585
if ($node instanceof Node\Stmt\Declare_ ||
8686
$node instanceof Node\Stmt\DeclareDeclare ||
8787
$node instanceof Node\Stmt\Else_ ||
88+
$node instanceof Node\Stmt\EnumCase ||
8889
$node instanceof Node\Stmt\Finally_ ||
8990
$node instanceof Node\Stmt\Interface_ ||
9091
$node instanceof Node\Stmt\Label ||
@@ -96,6 +97,7 @@ public function enterNode(Node $node): void
9697
$node instanceof Node\Stmt\UseUse ||
9798
$node instanceof Node\Expr\Match_ ||
9899
$node instanceof Node\Expr\Variable ||
100+
$node instanceof Node\ComplexType ||
99101
$node instanceof Node\Const_ ||
100102
$node instanceof Node\Identifier ||
101103
$node instanceof Node\Name ||
@@ -110,12 +112,13 @@ public function enterNode(Node $node): void
110112
return;
111113
}
112114

113-
if ($node instanceof Node\Stmt\Function_ ||
115+
if ($node instanceof Node\Stmt\Enum_ ||
116+
$node instanceof Node\Stmt\Function_ ||
114117
$node instanceof Node\Stmt\Class_ ||
115118
$node instanceof Node\Stmt\ClassMethod ||
116119
$node instanceof Node\Expr\Closure ||
117120
$node instanceof Node\Stmt\Trait_) {
118-
$isConcreteClassLike = $node instanceof Node\Stmt\Class_ || $node instanceof Node\Stmt\Trait_;
121+
$isConcreteClassLike = $node instanceof Node\Stmt\Enum_ || $node instanceof Node\Stmt\Class_ || $node instanceof Node\Stmt\Trait_;
119122

120123
if (null !== $node->stmts) {
121124
foreach ($node->stmts as $stmt) {

tests/_files/source_for_branched_exec_lines_php80.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,10 @@
3333
// Nullsafe Operator
3434
$ymd = $date?->format('Ymd'); // +1
3535
++$var; // +1
36+
37+
// Union types
38+
interface MyUnion
39+
{
40+
public function getNameIdentifier(): ?string;
41+
public function hasClaim(bool|string $type, mixed $value): bool;
42+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
// Enum
4+
enum BasicSuit
5+
{
6+
case Hearts;
7+
case Diamonds;
8+
case Clubs;
9+
case Spades;
10+
11+
public function shape(): string
12+
{
13+
return "Rectangle"; // +1
14+
}
15+
}
16+
17+
enum BackedSuit: string
18+
{
19+
case Hearts = 'H';
20+
case Diamonds = 'D';
21+
case Clubs = 'C';
22+
case Spades = 'S';
23+
}
24+
25+
BasicSuit::Diamonds->shape(); // +1
26+
BackedSuit::Clubs; // +1
27+
28+
29+
// Intersection types
30+
interface MyIntersection
31+
{
32+
public function check(MyIntOne&MyIntTwo $intersection);
33+
public function neverReturn(): never;
34+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
// Disjunctive Normal Form (DNF)
4+
class MyDnf
5+
{
6+
public function bar((A&B)|null $entity)
7+
{
8+
return $entity; // +1
9+
}
10+
}

tests/tests/StaticAnalysis/ExecutableLinesFindingVisitorTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,22 @@ public function testExecutableLinesAreGroupedByBranchPhp80(): void
4444
$this->doTestSelfDescribingAsset(TEST_FILES_PATH . 'source_for_branched_exec_lines_php80.php');
4545
}
4646

47+
/**
48+
* @requires PHP 8.1
49+
*/
50+
public function testExecutableLinesAreGroupedByBranchPhp81(): void
51+
{
52+
$this->doTestSelfDescribingAsset(TEST_FILES_PATH . 'source_for_branched_exec_lines_php81.php');
53+
}
54+
55+
/**
56+
* @requires PHP 8.2
57+
*/
58+
public function testExecutableLinesAreGroupedByBranchPhp82(): void
59+
{
60+
$this->doTestSelfDescribingAsset(TEST_FILES_PATH . 'source_for_branched_exec_lines_php82.php');
61+
}
62+
4763
private function doTestSelfDescribingAsset(string $filename): void
4864
{
4965
$source = file_get_contents($filename);

0 commit comments

Comments
 (0)