Skip to content

Commit f82e2d0

Browse files
authored
Merge pull request #8 from Aeliot-Tm/extend_compatibility
Add compatibility with PHP 7.1
2 parents 2d931a2 + 7aecb4e commit f82e2d0

20 files changed

+215
-60
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ jobs:
1414
fail-fast: false
1515
matrix:
1616
php-version:
17+
- '7.1'
1718
- '7.4'
1819
- '8.0'
1920
- '8.1'
2021
include:
22+
- php-version: '7.1'
2123
- php-version: '7.4'
2224
- php-version: '8.0'
2325
- php-version: '8.1'

bin/pccb_clover_compare

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ if ($isVerbose) {
4848
]);
4949

5050
$rows = $results->getRows();
51-
array_walk($rows, static fn (ComparingRow $x) => $table->addComparingRow($x));
51+
array_walk($rows, static function (ComparingRow $x) use ($table) {
52+
$table->addComparingRow($x);
53+
});
5254

5355
echo $table->getContent();
5456
}

composer.json

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,11 @@
33
"type": "library",
44
"description": "Script for the comparing of current code coverage with baseline.",
55
"license": "MIT",
6-
"keywords": ["phpunit", "clover", "baseline"],
7-
"require": {
8-
"php": "^7.4|^8.0",
9-
"ext-simplexml": "*",
10-
"ext-json": "*"
11-
},
12-
"require-dev": {
13-
"phpunit/phpunit": "^9.5",
14-
"dg/bypass-finals": "^1.4",
15-
"phpstan/phpstan": "^1.9",
16-
"phpstan/phpstan-phpunit": "^1.3",
17-
"phpstan/extension-installer": "^1.2"
18-
},
6+
"keywords": [
7+
"phpunit",
8+
"clover",
9+
"baseline"
10+
],
1911
"autoload": {
2012
"psr-4": {
2113
"Aeliot\\PHPUnitCodeCoverageBaseline\\": "src/"
@@ -30,13 +22,26 @@
3022
"bin/pccb_clover_build_baseline",
3123
"bin/pccb_clover_compare"
3224
],
33-
"scripts": {
34-
"test": "vendor/bin/phpunit",
35-
"phpstan-analise": "vendor/bin/phpstan analyse"
36-
},
3725
"config": {
3826
"allow-plugins": {
3927
"phpstan/extension-installer": true
40-
}
28+
},
29+
"sort-packages": true
30+
},
31+
"require": {
32+
"php": "^7.1|^8.0",
33+
"ext-json": "*",
34+
"ext-simplexml": "*"
35+
},
36+
"require-dev": {
37+
"dg/bypass-finals": "^1.4",
38+
"phpstan/extension-installer": "*",
39+
"phpstan/phpstan": "*",
40+
"phpstan/phpstan-phpunit": "*",
41+
"phpunit/phpunit": "*"
42+
},
43+
"scripts": {
44+
"test": "vendor/bin/phpunit",
45+
"phpstan-analise": "vendor/bin/phpstan analyse"
4146
}
4247
}

phpstan-baseline.neon

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
parameters:
22
ignoreErrors:
3+
-
4+
message: "#^Method Aeliot\\\\PHPUnitCodeCoverageBaseline\\\\Enum\\\\SupportedType\\:\\:getCoveredTypes\\(\\) should return array\\<string, string\\> but returns array\\<string, string\\>\\|false\\.$#"
5+
count: 1
6+
path: src/Enum/SupportedType.php
7+
38
-
49
message: "#^Return type of call to method PHPUnit\\\\Framework\\\\TestCase\\:\\:createMock\\(\\) contains unresolvable type\\.$#"
510
count: 2
@@ -19,3 +24,19 @@ parameters:
1924
message: "#^Return type of call to method PHPUnit\\\\Framework\\\\TestCase\\:\\:createMock\\(\\) contains unresolvable type\\.$#"
2025
count: 1
2126
path: tests/Unit/Model/ConsoleTableTest.php
27+
28+
-
29+
message: "#^Call to an undefined static method PHPUnit\\\\Framework\\\\TestCase\\:\\:expectExceptionMessageMatches\\(\\)\\.$#"
30+
count: 1
31+
path: tests/Unit/UnitTestCase.php
32+
33+
-
34+
message: "#^Call to an undefined static method PHPUnit\\\\Framework\\\\TestCase\\:\\:expectWarning\\(\\)\\.$#"
35+
count: 1
36+
path: tests/Unit/UnitTestCase.php
37+
38+
-
39+
message: "#^Call to an undefined static method PHPUnit\\\\Framework\\\\TestCase\\:\\:expectWarningMessageMatches\\(\\)\\.$#"
40+
count: 1
41+
path: tests/Unit/UnitTestCase.php
42+

phpunit.xml.dist

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,16 @@
2727
<crap4j outputFile="build/coverage/crap4j.xml" threshold="50"/>
2828
</report>
2929
</coverage>
30+
31+
<!-- >>>: Code coverage report for old versions of PHPUnit -->
32+
<filter>
33+
<whitelist processUncoveredFilesFromWhitelist="true">
34+
<directory suffix=".php">src</directory>
35+
</whitelist>
36+
</filter>
37+
<logging>
38+
<log type="coverage-html" target="build/coverage"/>
39+
<log type="coverage-clover" target="build/coverage/clover.xml"/>
40+
</logging>
41+
<!-- <<<: Code coverage report for old versions of PHPUnit -->
3042
</phpunit>

src/BaselineBuilder.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@
99

1010
final class BaselineBuilder
1111
{
12-
private BaselineWriter $baselineWriter;
13-
private CloverReader $cloverReader;
12+
/**
13+
* @var BaselineWriter
14+
*/
15+
private $baselineWriter;
16+
17+
/**
18+
* @var CloverReader
19+
*/
20+
private $cloverReader;
1421

1522
public function __construct(BaselineWriter $baselineWriter, CloverReader $cloverReader)
1623
{

src/Comparator.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@
1212

1313
final class Comparator
1414
{
15-
private BaselineReader $baselineReader;
16-
private CloverReader $cloverReader;
15+
/**
16+
* @var BaselineReader
17+
*/
18+
private $baselineReader;
19+
20+
/**
21+
* @var CloverReader
22+
*/
23+
private $cloverReader;
1724

1825
public function __construct(BaselineReader $baselineReader, CloverReader $cloverReader)
1926
{

src/Console/OptionsConfig.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ final class OptionsConfig
99
/**
1010
* @var array<string,string>
1111
*/
12-
private array $aliases = [];
12+
private $aliases = [];
1313

1414
/**
1515
* @var array<string,array{ longName: string, shortName: string, defaultValue: string|null }>
1616
*/
17-
private array $options = [];
17+
private $options = [];
1818

1919
public function add(
2020
string $longName,
@@ -70,7 +70,9 @@ public function prepareShortOptions(): string
7070
*/
7171
private function mapToRequired(array $keys): array
7272
{
73-
return array_map(static fn (string $x): string => "$x:", $keys);
73+
return array_map(static function (string $x): string {
74+
return "$x:";
75+
}, $keys);
7476
}
7577

7678
private function validateNames(string $longName, string $shortName): void

src/Console/OptionsReader.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@
66

77
final class OptionsReader
88
{
9-
private OptionsConfig $config;
10-
private GetOpt $getOpt;
9+
/**
10+
* @var OptionsConfig
11+
*/
12+
private $config;
13+
14+
/**
15+
* @var GetOpt
16+
*/
17+
private $getOpt;
1118

1219
public function __construct(OptionsConfig $config, GetOpt $getOpt)
1320
{
@@ -33,10 +40,10 @@ public function read(): array
3340
*/
3441
private function checkOnDuplicates(array $data): void
3542
{
36-
$duplicates = [
37-
...$this->filterArrayValues($data),
38-
...$this->filterDefinedByBothNames($data),
39-
];
43+
$duplicates = array_merge(
44+
$this->filterArrayValues($data),
45+
$this->filterDefinedByBothNames($data)
46+
);
4047

4148
if ($duplicates) {
4249
$duplicates = array_unique($duplicates);
@@ -56,7 +63,9 @@ private function filterArrayValues(array $data): array
5663
{
5764
$duplicates = [];
5865
$aliases = $this->config->getAliases();
59-
$arrays = array_filter($data, static fn ($x): bool => \is_array($x));
66+
$arrays = array_filter($data, static function ($x): bool {
67+
return \is_array($x);
68+
});
6069
foreach (array_keys($arrays) as $optionName) {
6170
$duplicates[] = $aliases[$optionName] ?? $optionName;
6271
}
@@ -90,7 +99,7 @@ private function setDefaults(array $data): array
9099
{
91100
$options = $this->config->getOptions();
92101
foreach ($this->config->getAliases() as $longName) {
93-
if(isset($data[$longName])){
102+
if (isset($data[$longName])) {
94103
continue;
95104
}
96105

src/Enum/SupportedType.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public static function getSupportedTypes(): array
5353
*/
5454
private static function mapCoveredTypes(array $supportedTypes): array
5555
{
56-
return array_map(static fn (string $x): string => 'covered' . $x, $supportedTypes);
56+
return array_map(static function (string $x): string {
57+
return 'covered' . $x;
58+
}, $supportedTypes);
5759
}
5860
}

src/Model/ComparingResult.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@
66

77
final class ComparingResult
88
{
9-
private bool $hasImprovement = false;
9+
/**
10+
* @var bool
11+
*/
12+
private $hasImprovement = false;
1013

1114
/**
1215
* @var ComparingRow[]
1316
*/
14-
private array $rows = [];
17+
private $rows = [];
1518

1619
/**
1720
* @var string[]
1821
*/
19-
private array $regressedNames = [];
22+
private $regressedNames = [];
2023

2124
public function addRow(ComparingRow $row): void
2225
{

src/Model/ComparingRow.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,25 @@
66

77
final class ComparingRow
88
{
9-
private string $name;
10-
private float $old;
11-
private float $new;
12-
private float $progress;
9+
/**
10+
* @var string
11+
*/
12+
private $name;
13+
14+
/**
15+
* @var float
16+
*/
17+
private $old;
18+
19+
/**
20+
* @var float
21+
*/
22+
private $new;
23+
24+
/**
25+
* @var float
26+
*/
27+
private $progress;
1328

1429
public function __construct(string $name, float $old, float $new)
1530
{

src/Model/ConsoleTable.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,27 @@ final class ConsoleTable
99
/**
1010
* @var string[]
1111
*/
12-
private array $columns;
12+
private $columns;
1313

14-
private int $columnsCount;
14+
/**
15+
* @var int
16+
*/
17+
private $columnsCount;
1518

1619
/**
1720
* @var array<int,int|string>
1821
*/
19-
private array $columnsKeys;
22+
private $columnsKeys;
2023

2124
/**
2225
* @var array<int,int>
2326
*/
24-
private array $columnsWidth;
27+
private $columnsWidth;
2528

2629
/**
2730
* @var array<int,array<string>>
2831
*/
29-
private array $values = [];
32+
private $values = [];
3033

3134
/**
3235
* @param string[] $columns

src/Reader/BaselineReader.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88

99
final class BaselineReader
1010
{
11-
private string $path;
11+
/**
12+
* @var string
13+
*/
14+
private $path;
1215

1316
public function __construct(string $path)
1417
{
@@ -26,7 +29,10 @@ public function read(): array
2629
throw new \DomainException('Empty baseline');
2730
}
2831

29-
if (array_filter($baseline, static fn ($x) => !\is_int($x))) {
32+
$notIntValues = array_filter($baseline, static function ($x): bool {
33+
return !\is_int($x);
34+
});
35+
if ($notIntValues) {
3036
throw new \DomainException('Invalid baseline data');
3137
}
3238

@@ -42,7 +48,10 @@ private function getBaseline(): array
4248
throw new \RuntimeException(sprintf('Code coverage baseline "%s" does not exist.', $this->path));
4349
}
4450

45-
$baseline = json_decode((string) file_get_contents($this->path), true, 512, JSON_THROW_ON_ERROR);
51+
$baseline = json_decode((string) file_get_contents($this->path), true);
52+
if (json_last_error()) {
53+
throw new \LogicException(json_last_error_msg());
54+
}
4655
if (!\is_array($baseline)) {
4756
throw new \DomainException('Cannot read baseline');
4857
}

src/Reader/CloverReader.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88

99
final class CloverReader
1010
{
11-
private string $path;
11+
/**
12+
* @var string
13+
*/
14+
private $path;
1215

1316
public function __construct(string $path)
1417
{

0 commit comments

Comments
 (0)