Skip to content

Commit 831ac87

Browse files
authored
Support php8 by removing safe library (#39)
* Add PHP8 to PHP matrix * Update Phan to ^4.0 for PHP8 support * Update PHPUnit to latest version for code coverage to work with PHP8 * Re-implement Safe methods and ignore them in code coverage, strenghten CI runs with PHPUnit and Infection and make sure 100% is minimum requirement * Run PHPUnit and Infection in one go so XML files are available to Infection * Inline Exceptions and remove static method and update PHP-CS-Fixer
1 parent 048dd4a commit 831ac87

23 files changed

+294
-56
lines changed

.github/workflows/actions.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
php:
1717
- 7.3
1818
- 7.4
19+
- 8.0
1920
suite:
2021
- php-cs-fixer-ci
2122
- phplint

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ coverage
66
.idea
77
.phpunit.result.cache
88
.phplint-cache
9-
.php_cs.cache
9+
.php_cs.cache
10+
code-climate.json
11+
infection.log

.php_cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ return PhpCsFixer\Config::create()
1515
'multiline_whitespace_before_semicolons' => [
1616
'strategy' => 'no_multi_line',
1717
],
18+
'global_namespace_import' => true,
1819
])
1920
->setFinder(PhpCsFixer\Finder::create()
2021
->exclude('vendor')

composer.json

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,20 @@
2727
}
2828
],
2929
"require": {
30-
"php": "^7.3",
30+
"php": "^7.3|^8.0",
3131
"ext-json": "*",
3232
"phlak/config": "^7.0",
33-
"symfony/console": "^4.0|^5.0",
34-
"thecodingmachine/safe": "^1.0"
33+
"symfony/console": "^4.0|^5.0"
3534
},
3635
"require-dev": {
3736
"friendsofphp/php-cs-fixer": "^2.16",
3837
"infection/infection": "^0.18.2",
3938
"overtrue/phplint": "^1.2",
40-
"phan/phan": "^2.4",
39+
"phan/phan": "^4.0",
4140
"phpstan/phpstan": "^0.12.7",
42-
"phpunit/phpunit": "^8.0",
43-
"rector/rector": "^0.6.13",
41+
"phpunit/phpunit": "^9.0",
4442
"rregeer/phpunit-coverage-check": "^0.3.1",
4543
"squizlabs/php_codesniffer": "^3.5",
46-
"thecodingmachine/phpstan-safe-rule": "^1.0",
4744
"vimeo/psalm": "^3.8"
4845
},
4946
"bin": [
@@ -61,8 +58,15 @@
6158
},
6259
"scripts": {
6360
"phpunit": "vendor/bin/phpunit",
64-
"infection": "vendor/bin/infection",
65-
"infection-ci": "XDEBUG_MODE=coverage vendor/bin/infection",
61+
"phpunit-ci": "vendor/bin/phpunit && vendor/bin/coverage-check build/coverage/clover.xml 100",
62+
"infection": [
63+
"phpunit",
64+
"vendor/bin/infection --coverage=build/coverage"
65+
],
66+
"infection-ci": [
67+
"phpunit",
68+
"XDEBUG_MODE=coverage vendor/bin/infection --coverage=build/coverage --min-msi=100 --min-covered-msi=100"
69+
],
6670
"phpstan": "vendor/bin/phpstan analyse src --level max",
6771
"psalm": "vendor/bin/psalm src",
6872
"phplint": "vendor/bin/phplint src",
@@ -71,7 +75,6 @@
7175
"php-cbf": "vendor/bin/phpcbf src --standard=PSR1,PSR2,PSR12",
7276
"php-cs": "vendor/bin/phpcs src --standard=PSR1,PSR2,PSR12",
7377
"phan": "vendor/bin/phan --allow-polyfill-parser src",
74-
"rector-safe": "vendor/bin/rector process src/ --config vendor/thecodingmachine/safe/rector-migrate-0.6.yml",
7578
"docker-build": "docker build -t converter ."
7679
},
7780
"config": {

phpunit.xml.dist

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="vendor/autoload.php"
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
bootstrap="vendor/autoload.php"
34
backupGlobals="false"
45
backupStaticAttributes="false"
56
colors="true"
@@ -8,15 +9,23 @@
89
convertNoticesToExceptions="true"
910
convertWarningsToExceptions="true"
1011
processIsolation="false"
11-
stopOnFailure="true">
12+
stopOnFailure="true"
13+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
14+
<coverage>
15+
<include>
16+
<directory suffix=".php">src/</directory>
17+
</include>
18+
<report>
19+
<xml outputDirectory="build/coverage/coverage-xml"/>
20+
<clover outputFile="build/coverage/clover.xml"/>
21+
</report>
22+
</coverage>
1223
<testsuites>
1324
<testsuite name="Test Suite">
1425
<directory>tests</directory>
1526
</testsuite>
1627
</testsuites>
17-
<filter>
18-
<whitelist>
19-
<directory suffix=".php">src/</directory>
20-
</whitelist>
21-
</filter>
28+
<logging>
29+
<junit outputFile="build/coverage/junit.xml"/>
30+
</logging>
2231
</phpunit>

src/AbstractConverter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use BeechIt\JsonToCodeClimateSubsetConverter\Interfaces\OutputInterface;
1313
use BeechIt\JsonToCodeClimateSubsetConverter\Interfaces\SafeMethodsInterface;
1414
use function debug_backtrace;
15+
use LogicException;
1516
use Safe\Exceptions\JsonException;
1617
use Safe\Exceptions\StringsException;
1718

@@ -53,7 +54,7 @@ public function __construct(
5354
$constructingClass = $backtrace[1]['class'];
5455

5556
if (ConverterFactory::class !== $constructingClass) {
56-
throw new \LogicException('Converter was not built via it\'s factory');
57+
throw new LogicException('Converter was not built via it\'s factory');
5758
}
5859

5960
$this->abstractJsonValidator = $abstractJsonValidator;

src/AbstractJsonValidator.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use BeechIt\JsonToCodeClimateSubsetConverter\Factories\ValidatorFactory;
99
use BeechIt\JsonToCodeClimateSubsetConverter\Interfaces\JsonValidatorInterface;
1010
use function debug_backtrace;
11+
use LogicException;
1112

1213
abstract class AbstractJsonValidator implements JsonValidatorInterface
1314
{
@@ -29,7 +30,7 @@ public function __construct($json)
2930
$constructingClass = $backtrace[1]['class'];
3031

3132
if (ValidatorFactory::class !== $constructingClass) {
32-
throw new \LogicException('Validator was not built via it\'s factory');
33+
throw new LogicException('Validator was not built via it\'s factory');
3334
}
3435

3536
$this->json = $json;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace BeechIt\JsonToCodeClimateSubsetConverter\Exceptions;
6+
7+
use ErrorException;
8+
9+
/**
10+
* @codeCoverageIgnore
11+
*/
12+
class FilesystemException extends ErrorException
13+
{
14+
}

src/Exceptions/InvalidJsonException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace BeechIt\JsonToCodeClimateSubsetConverter\Exceptions;
66

7-
class InvalidJsonException extends \Exception
7+
use Exception;
8+
9+
class InvalidJsonException extends Exception
810
{
911
}

src/Exceptions/JsonException.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace BeechIt\JsonToCodeClimateSubsetConverter\Exceptions;
6+
7+
use Exception;
8+
9+
/**
10+
* @codeCoverageIgnore
11+
*/
12+
class JsonException extends Exception
13+
{
14+
}

0 commit comments

Comments
 (0)