Skip to content

Commit c90d6ae

Browse files
committed
cs
1 parent 466072b commit c90d6ae

File tree

5 files changed

+113
-102
lines changed

5 files changed

+113
-102
lines changed

src/Data/ProcessedBranchCoverageData.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
*/
1010
namespace SebastianBergmann\CodeCoverage\Data;
1111

12+
use function array_merge;
13+
use function array_unique;
1214
use SebastianBergmann\CodeCoverage\Driver\XdebugDriver;
1315

1416
/**
@@ -17,26 +19,10 @@
1719
*/
1820
final readonly class ProcessedBranchCoverageData
1921
{
20-
public function __construct(
21-
public int $op_start,
22-
public int $op_end,
23-
public int $line_start,
24-
public int $line_end,
25-
/** @var list<TestIdType> */
26-
public array $hit,
27-
/** @var array<int, int> */
28-
public array $out,
29-
/** @var array<int, int> */
30-
public array $out_hit,
31-
32-
)
33-
{
34-
}
35-
3622
/**
3723
* @param XdebugBranchCoverageType $xdebugCoverageData
3824
*/
39-
static public function fromXdebugCoverage(array $xdebugCoverageData): self
25+
public static function fromXdebugCoverage(array $xdebugCoverageData): self
4026
{
4127
return new self(
4228
$xdebugCoverageData['op_start'],
@@ -49,6 +35,20 @@ static public function fromXdebugCoverage(array $xdebugCoverageData): self
4935
);
5036
}
5137

38+
public function __construct(
39+
public int $op_start,
40+
public int $op_end,
41+
public int $line_start,
42+
public int $line_end,
43+
/** @var list<TestIdType> */
44+
public array $hit,
45+
/** @var array<int, int> */
46+
public array $out,
47+
/** @var array<int, int> */
48+
public array $out_hit,
49+
) {
50+
}
51+
5252
public function merge(self $data): self
5353
{
5454
return new self(
@@ -65,8 +65,9 @@ public function merge(self $data): self
6565
/**
6666
* @param TestIdType $testCaseId
6767
*/
68-
public function recordHit(string $testCaseId): self {
69-
$hit = $this->hit;
68+
public function recordHit(string $testCaseId): self
69+
{
70+
$hit = $this->hit;
7071
$hit[] = $testCaseId;
7172

7273
return new self(
@@ -78,6 +79,5 @@ public function recordHit(string $testCaseId): self {
7879
$this->out,
7980
$this->out_hit,
8081
);
81-
8282
}
83-
}
83+
}

src/Data/ProcessedCodeCoverageData.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ private function priorityForLine(array $data, int $line): int
236236
*
237237
* @param ProcessedFunctionCoverageData|XdebugFunctionCoverageType $functionData
238238
*/
239-
private function initPreviouslyUnseenFunction(string $file, string $functionName, ProcessedFunctionCoverageData|array $functionData): void
239+
private function initPreviouslyUnseenFunction(string $file, string $functionName, array|ProcessedFunctionCoverageData $functionData): void
240240
{
241241
if (is_array($functionData)) {
242242
$functionData = ProcessedFunctionCoverageData::fromXdebugCoverage($functionData);
@@ -252,14 +252,14 @@ private function initPreviouslyUnseenFunction(string $file, string $functionName
252252
*
253253
* @param ProcessedFunctionCoverageData|XdebugFunctionCoverageType $functionData
254254
*/
255-
private function initPreviouslySeenFunction(string $file, string $functionName, ProcessedFunctionCoverageData|array $functionData): void
255+
private function initPreviouslySeenFunction(string $file, string $functionName, array|ProcessedFunctionCoverageData $functionData): void
256256
{
257257
if (is_array($functionData)) {
258258
$functionData = ProcessedFunctionCoverageData::fromXdebugCoverage($functionData);
259259
}
260260

261261
$this->functionCoverage[$file][$functionName] = $this->functionCoverage[$file][$functionName]->merge(
262-
$functionData
262+
$functionData,
263263
);
264264
}
265265
}

src/Data/ProcessedFunctionCoverageData.php

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,43 @@
1515
* @phpstan-import-type TestIdType from ProcessedCodeCoverageData
1616
* @phpstan-import-type XdebugFunctionCoverageType from XdebugDriver
1717
*/
18-
final class ProcessedFunctionCoverageData {
19-
public function __construct(
20-
/** @var array<int, ProcessedBranchCoverageData> */
21-
public array $branches,
22-
/** @var array<int, ProcessedPathCoverageData> */
23-
public array $paths,
24-
25-
) {}
26-
18+
final class ProcessedFunctionCoverageData
19+
{
2720
/**
2821
* @param XdebugFunctionCoverageType $xdebugCoverageData
2922
*/
30-
static public function fromXdebugCoverage(array $xdebugCoverageData): self
23+
public static function fromXdebugCoverage(array $xdebugCoverageData): self
3124
{
3225
$branches = [];
33-
foreach($xdebugCoverageData['branches'] as $branchId => $branch) {
26+
27+
foreach ($xdebugCoverageData['branches'] as $branchId => $branch) {
3428
$branches[$branchId] = ProcessedBranchCoverageData::fromXdebugCoverage($branch);
3529
}
3630
$paths = [];
37-
foreach($xdebugCoverageData['paths'] as $pathId => $path) {
31+
32+
foreach ($xdebugCoverageData['paths'] as $pathId => $path) {
3833
$paths[$pathId] = ProcessedPathCoverageData::fromXdebugCoverage($path);
3934
}
4035

4136
return new self(
4237
$branches,
43-
$paths
38+
$paths,
4439
);
4540
}
4641

42+
public function __construct(
43+
/** @var array<int, ProcessedBranchCoverageData> */
44+
public array $branches,
45+
/** @var array<int, ProcessedPathCoverageData> */
46+
public array $paths,
47+
) {
48+
}
49+
4750
public function merge(self $data): self
4851
{
4952
$branches = $this->branches;
50-
foreach($data->branches as $branchId => $branch) {
53+
54+
foreach ($data->branches as $branchId => $branch) {
5155
if (!isset($branches[$branchId])) {
5256
$branches[$branchId] = $branch;
5357
} else {
@@ -56,7 +60,8 @@ public function merge(self $data): self
5660
}
5761

5862
$paths = $this->paths;
59-
foreach($data->paths as $pathId => $path) {
63+
64+
foreach ($data->paths as $pathId => $path) {
6065
if (!isset($paths[$pathId])) {
6166
$paths[$pathId] = $path;
6267
} else {
@@ -66,18 +71,20 @@ public function merge(self $data): self
6671

6772
return new self(
6873
$branches,
69-
$paths
74+
$paths,
7075
);
7176
}
7277

7378
/**
7479
* @param TestIdType $testCaseId
7580
*/
76-
public function recordBranchHit(int $branchId, string $testCaseId): void {
81+
public function recordBranchHit(int $branchId, string $testCaseId): void
82+
{
7783
$this->branches[$branchId]->recordHit($testCaseId);
7884
}
7985

80-
public function recordPathHit(int $pathId, string $testCaseId): void {
86+
public function recordPathHit(int $pathId, string $testCaseId): void
87+
{
8188
$this->paths[$pathId]->recordHit($testCaseId);
8289
}
8390
}

src/Data/ProcessedPathCoverageData.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,35 @@
99
*/
1010
namespace SebastianBergmann\CodeCoverage\Data;
1111

12+
use function array_merge;
13+
use function array_unique;
1214
use SebastianBergmann\CodeCoverage\Driver\XdebugDriver;
1315

1416
/**
1517
* @phpstan-import-type TestIdType from ProcessedCodeCoverageData
1618
* @phpstan-import-type XdebugPathCoverageType from XdebugDriver
1719
*/
18-
final readonly class ProcessedPathCoverageData {
19-
public function __construct(
20-
/** @var array<int, int> */
21-
public array $path,
22-
/** @var list<TestIdType> */
23-
public array $hit,
24-
) {}
25-
20+
final readonly class ProcessedPathCoverageData
21+
{
2622
/**
2723
* @param XdebugPathCoverageType $xdebugCoverageData
2824
*/
29-
static public function fromXdebugCoverage(array $xdebugCoverageData): self
25+
public static function fromXdebugCoverage(array $xdebugCoverageData): self
3026
{
3127
return new self(
3228
$xdebugCoverageData['path'],
3329
[],
3430
);
3531
}
3632

33+
public function __construct(
34+
/** @var array<int, int> */
35+
public array $path,
36+
/** @var list<TestIdType> */
37+
public array $hit,
38+
) {
39+
}
40+
3741
public function merge(self $data): self
3842
{
3943
return new self(
@@ -47,13 +51,12 @@ public function merge(self $data): self
4751
*/
4852
public function recordHit(string $testCaseId): self
4953
{
50-
$hit = $this->hit;
54+
$hit = $this->hit;
5155
$hit[] = $testCaseId;
5256

5357
return new self(
5458
$this->path,
55-
$hit
59+
$hit,
5660
);
5761
}
58-
5962
}

tests/tests/Data/ProcessedCodeCoverageDataTest.php

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -75,28 +75,29 @@ public function testMergeDoesNotCrashWhenFileContentsHaveChanged(): void
7575
$coverage->setFunctionCoverage(
7676
[
7777
'/some/path/SomeClass.php' => [
78-
'SomeClass->firstFunction' =>
79-
new ProcessedFunctionCoverageData(
80-
[
81-
new ProcessedBranchCoverageData(
82-
0,
83-
14,
84-
20,
85-
25,
86-
[],
87-
[],
88-
[]
89-
)
90-
],
91-
[
92-
new ProcessedPathCoverageData(
93-
[
94-
0 => 0,
95-
],
96-
[],
97-
),
98-
]
99-
),
78+
'SomeClass->firstFunction' => [
79+
new ProcessedFunctionCoverageData(
80+
[
81+
new ProcessedBranchCoverageData(
82+
0,
83+
14,
84+
20,
85+
25,
86+
[],
87+
[],
88+
[],
89+
),
90+
],
91+
[
92+
new ProcessedPathCoverageData(
93+
[
94+
0 => 0,
95+
],
96+
[],
97+
),
98+
],
99+
),
100+
],
100101
],
101102
],
102103
);
@@ -105,7 +106,7 @@ public function testMergeDoesNotCrashWhenFileContentsHaveChanged(): void
105106
$newCoverage->setFunctionCoverage(
106107
[
107108
'/some/path/SomeClass.php' => [
108-
'SomeClass->firstFunction' => new ProcessedFunctionCoverageData(
109+
'SomeClass->firstFunction' => [new ProcessedFunctionCoverageData(
109110
[
110111
new ProcessedBranchCoverageData(
111112
0,
@@ -114,7 +115,7 @@ public function testMergeDoesNotCrashWhenFileContentsHaveChanged(): void
114115
25,
115116
[],
116117
[],
117-
[]
118+
[],
118119
),
119120
new ProcessedBranchCoverageData(
120121
15,
@@ -123,45 +124,45 @@ public function testMergeDoesNotCrashWhenFileContentsHaveChanged(): void
123124
27,
124125
[],
125126
[],
126-
[]
127-
)
127+
[],
128+
),
128129
],
129130
[
130131
new ProcessedPathCoverageData(
131132
[
132133
0 => 0,
133134
],
134-
[]
135+
[],
135136
),
136137
new ProcessedPathCoverageData(
137138
[
138139
0 => 1,
139140
],
140-
[]
141-
),
142-
]
143-
),
144-
'SomeClass->secondFunction' => new ProcessedFunctionCoverageData(
145-
[
146-
new ProcessedBranchCoverageData(
147-
0,
148-
24,
149-
30,
150-
35,
151-
[],
152141
[],
153-
[]
154142
),
155143
],
156-
[
157-
new ProcessedPathCoverageData(
158-
[
159-
0 => 0,
160-
],
161-
[]
162-
),
163-
]
164144
),
145+
'SomeClass->secondFunction' => new ProcessedFunctionCoverageData(
146+
[
147+
new ProcessedBranchCoverageData(
148+
0,
149+
24,
150+
30,
151+
35,
152+
[],
153+
[],
154+
[],
155+
),
156+
],
157+
[
158+
new ProcessedPathCoverageData(
159+
[
160+
0 => 0,
161+
],
162+
[],
163+
),
164+
],
165+
)],
165166
],
166167
],
167168
);

0 commit comments

Comments
 (0)