Skip to content

Commit 5b37223

Browse files
committedNov 12, 2024
refactor: apply standards for php-cs-fixer
1 parent 6f407df commit 5b37223

31 files changed

+147
-315
lines changed
 

‎.github/workflows/tests.yaml

+4-11
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@ jobs:
99
steps:
1010
- uses: actions/checkout@v4
1111
- uses: shivammathur/setup-php@v2
12-
- name: composer install
13-
run: |
14-
composer --working-dir=tools/php-cs-fixer install
12+
- run: composer install
1513
- name: php-cs-fixer
16-
run: |
17-
tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --dry-run --diff --show-progress=dots .
14+
run: vendor/bin/php-cs-fixer fix --dry-run --diff --show-progress=dots
1815
packages:
1916
runs-on: ubuntu-20.04
2017
needs: php-cs-fixer
@@ -67,9 +64,5 @@ jobs:
6764
# sparse-checkout: |
6865
# ${{ matrix.path }}
6966
- uses: shivammathur/setup-php@v2
70-
- name: composer install
71-
run: |
72-
composer install
73-
- name: vendor/bin/phpunit
74-
run: |
75-
vendor/bin/phpunit
67+
- run: composer install
68+
- run: vendor/bin/phpunit

‎.php-cs-fixer.dist.php

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
use PedroTroller\CS\Fixer\Fixers;
5+
use PedroTroller\CS\Fixer\RuleSetFactory;
6+
use PhpCsFixer\Config;
7+
use PhpCsFixer\Finder;
8+
9+
$finder = (new Finder())
10+
->in(__DIR__.'/src')
11+
->in(__DIR__.'/bin')
12+
->append([__FILE__])
13+
;
14+
15+
$rules = RuleSetFactory::create()
16+
->phpCsFixer(true)
17+
->php(8.1, true)
18+
->enable('PedroTroller/exceptions_punctuation')
19+
->enable('PedroTroller/useless_code_after_return')
20+
->disable('php_unit_strict')
21+
->disable('PedroTroller/line_break_between_method_arguments')
22+
->getRules()
23+
;
24+
25+
return (new Config())
26+
->setRiskyAllowed(true)
27+
->registerCustomFixers(new Fixers())
28+
->setRules($rules)
29+
->setFinder($finder)
30+
;

‎.php-cs-fixer.php

-184
This file was deleted.

‎bin/sync-composer.php

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?php
22

3-
$global = \json_decode(
4-
(string) \file_get_contents(__DIR__ . '/../composer.json'),
3+
declare(strict_types=1);
4+
5+
$global = json_decode(
6+
(string) file_get_contents(__DIR__.'/../composer.json'),
57
true,
68
flags: \JSON_THROW_ON_ERROR,
79
);
@@ -14,13 +16,13 @@
1416
$replace = $global['replace'];
1517

1618
foreach ($global['autoload']['psr-4'] as $path) {
17-
$content = \file_get_contents($path . '/composer.json');
19+
$content = file_get_contents($path.'/composer.json');
1820

1921
if (false === $content) {
2022
throw new Exception("File {$path}/composer.json not found.");
2123
}
2224

23-
$json = \json_decode(
25+
$json = json_decode(
2426
$content,
2527
true,
2628
flags: \JSON_THROW_ON_ERROR,
@@ -33,16 +35,16 @@
3335
}
3436

3537
if (false === isset($dependencies[$name])) {
36-
throw new Exception(\sprintf('Dependency "%s" not found in %s/composer.json.', $name, __DIR__, ));
38+
throw new Exception(sprintf('Dependency "%s" not found in %s/composer.json.', $name, __DIR__));
3739
}
3840

3941
$json[$part][$name] = $dependencies[$name];
4042
}
4143
}
4244

43-
$content = \file_put_contents(
44-
$path . '/composer.json',
45-
\json_encode(
45+
$content = file_put_contents(
46+
$path.'/composer.json',
47+
json_encode(
4648
$json,
4749
flags: \JSON_PRETTY_PRINT | \JSON_THROW_ON_ERROR | \JSON_UNESCAPED_SLASHES,
4850
),

‎composer.json

+2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
"symfony/process": "^5.4|^6.4|^7.1"
3636
},
3737
"require-dev": {
38+
"friendsofphp/php-cs-fixer": "^3.64",
3839
"nyholm/psr7": "^1.8",
40+
"pedrotroller/php-cs-custom-fixer": "^2.33",
3941
"phpstan/extension-installer": "^1.4",
4042
"phpstan/phpstan": "^1.12",
4143
"phpstan/phpstan-phpunit": "^1.4",

‎src/Backend/Dompdf/DompdfAdapter.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
<?php
22

3-
declare(strict_types = 1);
3+
declare(strict_types=1);
44

55
namespace KNPLabs\Snappy\Backend\Dompdf;
66

7-
use DOMDocument;
87
use Dompdf;
98
use KNPLabs\Snappy\Core\Backend\Adapter\DOMDocumentToPdf;
109
use KNPLabs\Snappy\Core\Backend\Adapter\HtmlFileToPdf;
@@ -13,7 +12,6 @@
1312
use KNPLabs\Snappy\Core\Backend\Options;
1413
use Psr\Http\Message\StreamFactoryInterface;
1514
use Psr\Http\Message\StreamInterface;
16-
use SplFileInfo;
1715

1816
final readonly class DompdfAdapter implements DOMDocumentToPdf, HtmlFileToPdf, HtmlToPdf
1917
{
@@ -28,15 +26,15 @@ public function __construct(DompdfFactory $factory, Options $options, private St
2826
$this->options = $options;
2927
}
3028

31-
public function generateFromDOMDocument(DOMDocument $DOMDocument): StreamInterface
29+
public function generateFromDOMDocument(\DOMDocument $DOMDocument): StreamInterface
3230
{
3331
$dompdf = $this->buildDompdf();
3432
$dompdf->loadDOM($DOMDocument);
3533

3634
return $this->createStream($dompdf);
3735
}
3836

39-
public function generateFromHtmlFile(SplFileInfo $file): StreamInterface
37+
public function generateFromHtmlFile(\SplFileInfo $file): StreamInterface
4038
{
4139
$dompdf = $this->buildDompdf();
4240
$dompdf->loadHtmlFile($file->getPath());

‎src/Backend/Dompdf/DompdfFactory.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
declare(strict_types = 1);
3+
declare(strict_types=1);
44

55
namespace KNPLabs\Snappy\Backend\Dompdf;
66

@@ -13,9 +13,7 @@
1313
*/
1414
final readonly class DompdfFactory implements Factory
1515
{
16-
public function __construct(private readonly StreamFactoryInterface $streamFactory)
17-
{
18-
}
16+
public function __construct(private readonly StreamFactoryInterface $streamFactory) {}
1917

2018
public function create(Options $options): DompdfAdapter
2119
{

‎src/Backend/WkHtmlToPdf/WkHtmlToPdfAdapter.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
<?php
22

3-
declare(strict_types = 1);
3+
declare(strict_types=1);
44

55
namespace KNPLabs\Snappy\Backend\WkHtmlToPdf;
66

77
use KNPLabs\Snappy\Core\Backend\Adapter\HtmlFileToPdf;
88
use KNPLabs\Snappy\Core\Backend\Adapter\Reconfigurable;
99
use KNPLabs\Snappy\Core\Backend\Options;
1010
use Psr\Http\Message\StreamInterface;
11-
use SplFileInfo;
12-
use Exception;
1311

1412
final class WkHtmlToPdfAdapter implements HtmlFileToPdf
1513
{
@@ -32,8 +30,8 @@ public function __construct(
3230
$this->options = $options;
3331
}
3432

35-
public function generateFromHtmlFile(SplFileInfo $file): StreamInterface
33+
public function generateFromHtmlFile(\SplFileInfo $file): StreamInterface
3634
{
37-
throw new Exception("Not implemented for {$this->binary} with timeout {$this->timeout}.");
35+
throw new \Exception("Not implemented for {$this->binary} with timeout {$this->timeout}.");
3836
}
3937
}

0 commit comments

Comments
 (0)