Skip to content

Commit 7aecb4e

Browse files
committed
Add compatibility with PHP 7.1
1 parent 698a8b2 commit 7aecb4e

20 files changed

+197
-47
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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@
2929
"sort-packages": true
3030
},
3131
"require": {
32-
"php": "^7.4|^8.0",
32+
"php": "^7.1|^8.0",
3333
"ext-json": "*",
3434
"ext-simplexml": "*"
3535
},
3636
"require-dev": {
3737
"dg/bypass-finals": "^1.4",
38-
"phpstan/extension-installer": "^1.2",
39-
"phpstan/phpstan": "^1.9",
40-
"phpstan/phpstan-phpunit": "^1.3",
41-
"phpunit/phpunit": "^9.5"
38+
"phpstan/extension-installer": "*",
39+
"phpstan/phpstan": "*",
40+
"phpstan/phpstan-phpunit": "*",
41+
"phpunit/phpunit": "*"
4242
},
4343
"scripts": {
4444
"test": "vendor/bin/phpunit",

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
{

src/Writer/BaselineWriter.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
*/
1010
final class BaselineWriter
1111
{
12-
private string $path;
12+
/**
13+
* @var string
14+
*/
15+
private $path;
1316

1417
public function __construct(string $path)
1518
{
@@ -21,6 +24,10 @@ public function __construct(string $path)
2124
*/
2225
public function write(array $baseline): void
2326
{
24-
file_put_contents($this->path, json_encode($baseline, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT));
27+
$content = json_encode($baseline, JSON_PRETTY_PRINT);
28+
if (json_last_error()) {
29+
throw new \LogicException(json_last_error_msg());
30+
}
31+
file_put_contents($this->path, $content);
2532
}
2633
}

tests/Unit/Model/ConsoleTableTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
use Aeliot\PHPUnitCodeCoverageBaseline\Model\ComparingRow;
88
use Aeliot\PHPUnitCodeCoverageBaseline\Model\ConsoleTable;
9-
use PHPUnit\Framework\TestCase;
9+
use Aeliot\PHPUnitCodeCoverageBaseline\Test\Unit\UnitTestCase;
1010

11-
final class ConsoleTableTest extends TestCase
11+
final class ConsoleTableTest extends UnitTestCase
1212
{
1313
/**
1414
* @dataProvider getDataForTestAddComparingPositiveFlow

0 commit comments

Comments
 (0)