-
-
Notifications
You must be signed in to change notification settings - Fork 384
Represent CoverageData in objects #1105
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
Merged
Merged
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
f93eba4
Represent FunctionCover in objects
staabm c3209a2
Update ProcessedFunctionCoverageData.php
staabm b95f448
simplify doctypes
staabm 99a5605
Update ProcessedCodeCoverageDataTest.php
staabm 1cf165c
cs
staabm 96e1931
cs
staabm 08df026
fix
staabm 025f24f
Update ProcessedCodeCoverageDataTest.php
staabm 8a65e00
fix
staabm 508985a
Update File.php
staabm f11d346
optimize
staabm b7dc2a7
Update ProcessedPathCoverageData.php
staabm f9233ae
Update ProcessedFunctionCoverageData.php
staabm 7f2f62c
cs
staabm 0832798
fix
staabm 518e0af
Update TestCase.php
staabm b7fd722
cs
staabm 8f03d58
Update File.php
staabm 283022e
Update ProcessedFunctionCoverageData.php
staabm 2cad824
new classes are internal
staabm 0cf0772
fix cs
staabm 18fcbc1
Update ProcessedFunctionCoverageData.php
staabm 9586250
use traditional properties
staabm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| <?php declare(strict_types=1); | ||
| /* | ||
| * This file is part of phpunit/php-code-coverage. | ||
| * | ||
| * (c) Sebastian Bergmann <sebastian@phpunit.de> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
| namespace SebastianBergmann\CodeCoverage\Data; | ||
|
|
||
| use function array_merge; | ||
| use function array_unique; | ||
| use NoDiscard; | ||
| use SebastianBergmann\CodeCoverage\Driver\XdebugDriver; | ||
|
|
||
| /** | ||
| * @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage | ||
| * | ||
| * @phpstan-import-type TestIdType from ProcessedCodeCoverageData | ||
| * @phpstan-import-type XdebugBranchCoverageType from XdebugDriver | ||
| */ | ||
| final class ProcessedBranchCoverageData | ||
| { | ||
| /** | ||
| * @param XdebugBranchCoverageType $xdebugCoverageData | ||
| */ | ||
| public static function fromXdebugCoverage(array $xdebugCoverageData): self | ||
| { | ||
| return new self( | ||
| $xdebugCoverageData['op_start'], | ||
| $xdebugCoverageData['op_end'], | ||
| $xdebugCoverageData['line_start'], | ||
| $xdebugCoverageData['line_end'], | ||
| [], | ||
| $xdebugCoverageData['out'], | ||
| $xdebugCoverageData['out_hit'], | ||
| ); | ||
| } | ||
|
|
||
| public function __construct( | ||
| public readonly int $op_start, | ||
| public readonly int $op_end, | ||
| public readonly int $line_start, | ||
| public readonly int $line_end, | ||
| /** @var list<TestIdType> */ | ||
| public array $hit, | ||
| /** @var array<int, int> */ | ||
| public readonly array $out, | ||
| /** @var array<int, int> */ | ||
| public readonly array $out_hit, | ||
| ) { | ||
| } | ||
|
|
||
| #[NoDiscard] | ||
| public function merge(self $data): self | ||
| { | ||
| if ($data->hit === []) { | ||
| return $this; | ||
| } | ||
|
|
||
| return new self( | ||
| $this->op_start, | ||
| $this->op_end, | ||
| $this->line_start, | ||
| $this->line_end, | ||
| array_unique(array_merge($this->hit, $data->hit)), | ||
| $this->out, | ||
| $this->out_hit, | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @param TestIdType $testCaseId | ||
| */ | ||
| public function recordHit(string $testCaseId): void | ||
| { | ||
| $this->hit[] = $testCaseId; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| <?php declare(strict_types=1); | ||
| /* | ||
| * This file is part of phpunit/php-code-coverage. | ||
| * | ||
| * (c) Sebastian Bergmann <sebastian@phpunit.de> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
| namespace SebastianBergmann\CodeCoverage\Data; | ||
|
|
||
| use SebastianBergmann\CodeCoverage\Driver\XdebugDriver; | ||
|
|
||
| /** | ||
| * @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage | ||
| * | ||
| * @phpstan-import-type TestIdType from ProcessedCodeCoverageData | ||
| * @phpstan-import-type XdebugFunctionCoverageType from XdebugDriver | ||
| */ | ||
| final readonly class ProcessedFunctionCoverageData | ||
| { | ||
| /** | ||
| * @param XdebugFunctionCoverageType $xdebugCoverageData | ||
| */ | ||
| public static function fromXdebugCoverage(array $xdebugCoverageData): self | ||
| { | ||
| $branches = []; | ||
|
|
||
| foreach ($xdebugCoverageData['branches'] as $branchId => $branch) { | ||
| $branches[$branchId] = ProcessedBranchCoverageData::fromXdebugCoverage($branch); | ||
| } | ||
| $paths = []; | ||
|
|
||
| foreach ($xdebugCoverageData['paths'] as $pathId => $path) { | ||
| $paths[$pathId] = ProcessedPathCoverageData::fromXdebugCoverage($path); | ||
| } | ||
|
|
||
| return new self( | ||
| $branches, | ||
| $paths, | ||
| ); | ||
| } | ||
|
|
||
| public function __construct( | ||
| /** @var array<int, ProcessedBranchCoverageData> */ | ||
| public array $branches, | ||
| /** @var array<int, ProcessedPathCoverageData> */ | ||
| public array $paths, | ||
| ) { | ||
| } | ||
|
|
||
| public function merge(self $data): self | ||
| { | ||
| $branches = null; | ||
|
|
||
| if ($data->branches !== $this->branches) { | ||
| $branches = $this->branches; | ||
|
|
||
| foreach ($data->branches as $branchId => $branch) { | ||
| if (!isset($branches[$branchId])) { | ||
| $branches[$branchId] = $branch; | ||
| } else { | ||
| $branches[$branchId] = $branches[$branchId]->merge($branch); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| $paths = null; | ||
|
|
||
| if ($data->paths !== $this->paths) { | ||
| $paths = $this->paths; | ||
|
|
||
| foreach ($data->paths as $pathId => $path) { | ||
| if (!isset($paths[$pathId])) { | ||
| $paths[$pathId] = $path; | ||
| } else { | ||
| $paths[$pathId] = $paths[$pathId]->merge($path); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if ($branches === null && $paths === null) { | ||
| return $this; | ||
| } | ||
|
|
||
| return new self( | ||
| $branches ?? $this->branches, | ||
| $paths ?? $this->paths, | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @param TestIdType $testCaseId | ||
| */ | ||
| public function recordBranchHit(int $branchId, string $testCaseId): void | ||
| { | ||
| $this->branches[$branchId]->recordHit($testCaseId); | ||
| } | ||
|
|
||
| /** | ||
| * @param TestIdType $testCaseId | ||
| */ | ||
| public function recordPathHit(int $pathId, string $testCaseId): void | ||
| { | ||
| $this->paths[$pathId]->recordHit($testCaseId); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| <?php declare(strict_types=1); | ||
| /* | ||
| * This file is part of phpunit/php-code-coverage. | ||
| * | ||
| * (c) Sebastian Bergmann <sebastian@phpunit.de> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
| namespace SebastianBergmann\CodeCoverage\Data; | ||
|
|
||
| use function array_merge; | ||
| use function array_unique; | ||
| use NoDiscard; | ||
| use SebastianBergmann\CodeCoverage\Driver\XdebugDriver; | ||
|
|
||
| /** | ||
| * @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage | ||
| * | ||
| * @phpstan-import-type TestIdType from ProcessedCodeCoverageData | ||
| * @phpstan-import-type XdebugPathCoverageType from XdebugDriver | ||
| */ | ||
| final class ProcessedPathCoverageData | ||
| { | ||
| /** | ||
| * @param XdebugPathCoverageType $xdebugCoverageData | ||
| */ | ||
| public static function fromXdebugCoverage(array $xdebugCoverageData): self | ||
| { | ||
| return new self( | ||
| $xdebugCoverageData['path'], | ||
| [], | ||
| ); | ||
| } | ||
|
|
||
| public function __construct( | ||
| /** @var array<int, int> */ | ||
| public readonly array $path, | ||
| /** @var list<TestIdType> */ | ||
| public array $hit, | ||
| ) { | ||
| } | ||
|
|
||
| #[NoDiscard] | ||
| public function merge(self $data): self | ||
| { | ||
| if ($data->hit === []) { | ||
| return $this; | ||
| } | ||
|
|
||
| return new self( | ||
| $this->path, | ||
| array_unique(array_merge($this->hit, $data->hit)), | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @param TestIdType $testCaseId | ||
| */ | ||
| public function recordHit(string $testCaseId): void | ||
| { | ||
| $this->hit[] = $testCaseId; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.