Skip to content

Commit 15b823b

Browse files
authored
Use shipmonk/coding-standard (#41)
1 parent 9b07322 commit 15b823b

File tree

9 files changed

+71
-439
lines changed

9 files changed

+71
-439
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
"phpstan/phpstan-phpunit": "2.0.6",
2424
"phpstan/phpstan-strict-rules": "2.0.4",
2525
"phpunit/phpunit": "9.6.23",
26+
"shipmonk/coding-standard": "^0.1.3",
2627
"shipmonk/composer-dependency-analyser": "1.8.3",
2728
"shipmonk/dead-code-detector": "^0.11.0",
2829
"shipmonk/name-collision-detector": "2.1.1",
29-
"shipmonk/phpstan-rules": "4.1.2",
30-
"slevomat/coding-standard": "8.18.0"
30+
"shipmonk/phpstan-rules": "4.1.2"
3131
},
3232
"autoload": {
3333
"psr-4": {

phpcs.xml.dist

Lines changed: 6 additions & 422 deletions
Large diffs are not rendered by default.

src/BaselinePerIdentifierFormatter.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ class BaselinePerIdentifierFormatter implements ErrorFormatter
2929

3030
private string $indent;
3131

32-
public function __construct(?string $baselinesDir, string $indent)
32+
public function __construct(
33+
?string $baselinesDir,
34+
string $indent
35+
)
3336
{
3437
if ($baselinesDir === null) {
3538
throw new LogicException('Baselines directory must be set, please set up \'parameters.shipmonkBaselinePerIdentifier.directory\' in your phpstan configuration file');
@@ -133,7 +136,10 @@ public function formatErrors(
133136
return 0;
134137
}
135138

136-
private function getPathDifference(string $from, string $to): string
139+
private function getPathDifference(
140+
string $from,
141+
string $to
142+
): string
137143
{
138144
$fromParts = explode(DIRECTORY_SEPARATOR, $from);
139145
$toParts = explode(DIRECTORY_SEPARATOR, $to);

src/BaselineSplitter.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@ class BaselineSplitter
2222

2323
private bool $includeCount;
2424

25-
public function __construct(string $indent, bool $includeCount)
25+
public function __construct(
26+
string $indent,
27+
bool $includeCount
28+
)
2629
{
2730
$this->indent = $indent;
2831
$this->includeCount = $includeCount;
2932
}
3033

3134
/**
3235
* @return array<string, int|null>
36+
*
3337
* @throws ErrorException
3438
*/
3539
public function split(string $loaderFilePath): array
@@ -66,7 +70,7 @@ public function split(string $loaderFilePath): array
6670
foreach ($groupedErrors as $identifier => $errors) {
6771
$fileName = $identifier . '.' . $extension;
6872
$filePath = $folder . '/' . $fileName;
69-
$errorsCount = array_reduce($errors, static fn(int $carry, array $item): int => $carry + $item['count'], 0);
73+
$errorsCount = array_reduce($errors, static fn (int $carry, array $item): int => $carry + $item['count'], 0);
7074
$totalErrorCount += $errorsCount;
7175

7276
$outputInfo[$filePath] = $errorsCount;
@@ -92,9 +96,13 @@ public function split(string $loaderFilePath): array
9296
/**
9397
* @param array<mixed> $errors
9498
* @return array<string, list<array{message: string, count: int, path: string}>>
99+
*
95100
* @throws ErrorException
96101
*/
97-
private function groupErrorsByIdentifier(array $errors, string $folder): array
102+
private function groupErrorsByIdentifier(
103+
array $errors,
104+
string $folder
105+
): array
98106
{
99107
$groupedErrors = [];
100108

@@ -147,7 +155,10 @@ private function groupErrorsByIdentifier(array $errors, string $folder): array
147155
/**
148156
* @throws ErrorException
149157
*/
150-
private function writeFile(string $filePath, string $contents): void
158+
private function writeFile(
159+
string $filePath,
160+
string $contents
161+
): void
151162
{
152163
$written = file_put_contents($filePath, $contents);
153164

src/Exception/ErrorException.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
class ErrorException extends RuntimeException
99
{
1010

11-
public function __construct(string $message, ?Throwable $previous = null)
11+
public function __construct(
12+
string $message,
13+
?Throwable $previous = null
14+
)
1215
{
1316
parent::__construct($message, 0, $previous);
1417
}

src/Handler/BaselineHandler.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,27 @@ interface BaselineHandler
99

1010
/**
1111
* @return array<mixed>
12+
*
1213
* @throws ErrorException
1314
*/
1415
public function decodeBaseline(string $filepath): array;
1516

1617
/**
1718
* @param list<array{message: string, count: int, path: string}> $errors
1819
*/
19-
public function encodeBaseline(?string $comment, array $errors, string $indent): string;
20+
public function encodeBaseline(
21+
?string $comment,
22+
array $errors,
23+
string $indent
24+
): string;
2025

2126
/**
2227
* @param list<string> $filePaths
2328
*/
24-
public function encodeBaselineLoader(?string $comment, array $filePaths, string $indent): string;
29+
public function encodeBaselineLoader(
30+
?string $comment,
31+
array $filePaths,
32+
string $indent
33+
): string;
2534

2635
}

src/Handler/NeonBaselineHandler.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,21 @@ public function decodeBaseline(string $filepath): array
2929
}
3030
}
3131

32-
public function encodeBaseline(?string $comment, array $errors, string $indent): string
32+
public function encodeBaseline(
33+
?string $comment,
34+
array $errors,
35+
string $indent
36+
): string
3337
{
3438
$prefix = $comment !== null ? "# $comment\n\n" : '';
3539
return $prefix . NeonHelper::encode(['parameters' => ['ignoreErrors' => $errors]], $indent);
3640
}
3741

38-
public function encodeBaselineLoader(?string $comment, array $filePaths, string $indent): string
42+
public function encodeBaselineLoader(
43+
?string $comment,
44+
array $filePaths,
45+
string $indent
46+
): string
3947
{
4048
$prefix = $comment !== null ? "# $comment\n" : '';
4149
return $prefix . NeonHelper::encode(['includes' => $filePaths], $indent);

src/Handler/PhpBaselineHandler.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class PhpBaselineHandler implements BaselineHandler
1515
public function decodeBaseline(string $filepath): array
1616
{
1717
try {
18-
$decoded = (static fn() => require $filepath)();
18+
$decoded = (static fn () => require $filepath)();
1919

2020
if (!is_array($decoded)) {
2121
throw new ErrorException("File '$filepath' must return array, " . gettype($decoded) . ' given');
@@ -28,7 +28,11 @@ public function decodeBaseline(string $filepath): array
2828
}
2929
}
3030

31-
public function encodeBaseline(?string $comment, array $errors, string $indent): string
31+
public function encodeBaseline(
32+
?string $comment,
33+
array $errors,
34+
string $indent
35+
): string
3236
{
3337
$php = '<?php declare(strict_types = 1);';
3438

@@ -56,7 +60,11 @@ public function encodeBaseline(?string $comment, array $errors, string $indent):
5660
return $php;
5761
}
5862

59-
public function encodeBaselineLoader(?string $comment, array $filePaths, string $indent): string
63+
public function encodeBaselineLoader(
64+
?string $comment,
65+
array $filePaths,
66+
string $indent
67+
): string
6068
{
6169
$php = "<?php declare(strict_types = 1);\n\n";
6270

src/NeonHelper.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ class NeonHelper
1313
/**
1414
* @param mixed $data
1515
*/
16-
public static function encode($data, string $indent): string
16+
public static function encode(
17+
$data,
18+
string $indent
19+
): string
1720
{
1821
return trim(Neon::encode($data, true, $indent)) . "\n";
1922
}

0 commit comments

Comments
 (0)