Skip to content

Commit 9578dac

Browse files
More fix-ups pre open source (#14)
Co-authored-by: Martin Georgiev <[email protected]>
1 parent 329caf2 commit 9578dac

9 files changed

+33
-40
lines changed

Diff for: .php-cs-fixer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
declare(strict_types=1);
44

55
$finder = (new PhpCsFixer\Finder())
6-
->in(['lib', 'tests']);
6+
->in(['src', 'tests']);
77

88
return (new PhpCsFixer\Config())
99
->setRules([

Diff for: composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
],
1212
"autoload": {
1313
"psr-4": {
14-
"Lendable\\Json\\": "lib/"
14+
"Lendable\\Json\\": "src/"
1515
}
1616
},
1717
"autoload-dev": {
@@ -49,14 +49,14 @@
4949
"PHP_CS_FIXER_FUTURE_MODE=1 php-cs-fixer fix --dry-run --diff --ansi --using-cache=no"
5050
],
5151
"lint:php": [
52-
"parallel-lint lib",
52+
"parallel-lint src",
5353
"parallel-lint tests"
5454
],
5555
"lint": [
5656
"@lint:php"
5757
],
5858
"phpstan": [
59-
"phpstan analyse --memory-limit=-1 lib/ tests/ --ansi --no-progress"
59+
"phpstan analyse --memory-limit=-1 src/ tests/ --ansi --no-progress"
6060
],
6161
"rector:check": [
6262
"rector --dry-run --ansi --no-progress-bar"

Diff for: phpunit.xml.dist

+10-17
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit colors="true"
3-
convertErrorsToExceptions="true"
4-
convertNoticesToExceptions="true"
5-
convertWarningsToExceptions="true"
6-
processIsolation="false"
7-
stopOnFailure="false"
8-
bootstrap="vendor/autoload.php">
9-
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
colors="true"
4+
bootstrap="vendor/autoload.php"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
6+
<coverage>
7+
<include>
8+
<directory>./src/</directory>
9+
</include>
10+
</coverage>
1011
<php>
11-
<ini name="error_reporting" value="E_ALL" />
12+
<ini name="error_reporting" value="E_ALL"/>
1213
</php>
13-
1414
<testsuites>
1515
<testsuite name="unit">
1616
<directory>./tests/unit/</directory>
1717
</testsuite>
1818
</testsuites>
19-
20-
<filter>
21-
<whitelist>
22-
<directory>./lib/</directory>
23-
</whitelist>
24-
</filter>
25-
2619
</phpunit>

Diff for: rector.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
return static function (ContainerConfigurator $containerConfigurator): void {
1212
$parameters = $containerConfigurator->parameters();
13-
$parameters->set(Option::PATHS, [__DIR__.'/lib', __DIR__.'/tests']);
13+
$parameters->set(Option::PATHS, [__DIR__.'/src', __DIR__.'/tests']);
1414
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_74);
1515
$parameters->set(Option::PHPSTAN_FOR_RECTOR_PATH, __DIR__.'/phpstan.neon');
1616
$parameters->set(Option::SKIP, [

Diff for: lib/DeserializationFailed.php renamed to src/DeserializationFailed.php

+8-5
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@
66

77
final class DeserializationFailed extends \RuntimeException implements Failure
88
{
9-
public function __construct(int $errorCode, string $errorMessage, ?\Throwable $previous = null)
9+
public function __construct(\JsonException $cause)
1010
{
11+
$causeCode = $cause->getCode();
12+
\assert(\is_int($causeCode));
13+
1114
parent::__construct(
1215
\sprintf(
1316
'Failed to deserialize data from JSON. Error code: %d, error message: %s.',
14-
$errorCode,
15-
$errorMessage
17+
$causeCode,
18+
$cause->getMessage(),
1619
),
17-
$errorCode,
18-
$previous
20+
$causeCode,
21+
$cause,
1922
);
2023
}
2124
}

Diff for: lib/Failure.php renamed to src/Failure.php

File renamed without changes.
File renamed without changes.

Diff for: lib/SerializationFailed.php renamed to src/SerializationFailed.php

+8-5
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@
66

77
final class SerializationFailed extends \RuntimeException implements Failure
88
{
9-
public function __construct(int $errorCode, string $errorMessage, ?\Throwable $previous = null)
9+
public function __construct(\JsonException $cause)
1010
{
11+
$causeCode = $cause->getCode();
12+
\assert(\is_int($causeCode));
13+
1114
parent::__construct(
1215
\sprintf(
1316
'Failed to serialize data to JSON. Error code: %d, error message: %s.',
14-
$errorCode,
15-
$errorMessage
17+
$causeCode,
18+
$cause->getMessage(),
1619
),
17-
$errorCode,
18-
$previous
20+
$causeCode,
21+
$cause,
1922
);
2023
}
2124
}

Diff for: lib/Serializer.php renamed to src/Serializer.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ public function serialize(array $data): string
1616
try {
1717
$serialized = \json_encode($data, \JSON_THROW_ON_ERROR | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE);
1818
} catch (\JsonException $exception) {
19-
$errorCode = $exception->getCode();
20-
\assert(\is_int($errorCode));
21-
22-
throw new SerializationFailed($errorCode, $exception->getMessage(), $exception);
19+
throw new SerializationFailed($exception);
2320
}
2421

2522
return $serialized;
@@ -36,10 +33,7 @@ public function deserialize(string $json): array
3633
try {
3734
$data = \json_decode($json, true, 512, \JSON_THROW_ON_ERROR);
3835
} catch (\JsonException $exception) {
39-
$errorCode = $exception->getCode();
40-
\assert(\is_int($errorCode));
41-
42-
throw new DeserializationFailed($errorCode, $exception->getMessage(), $exception);
36+
throw new DeserializationFailed($exception);
4337
}
4438

4539
if (!\is_array($data)) {

0 commit comments

Comments
 (0)