Skip to content

Commit

Permalink
refactor: apply standards for php-cs-fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroTroller committed Nov 12, 2024
1 parent 6f407df commit 5b37223
Show file tree
Hide file tree
Showing 31 changed files with 147 additions and 315 deletions.
15 changes: 4 additions & 11 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
- name: composer install
run: |
composer --working-dir=tools/php-cs-fixer install
- run: composer install
- name: php-cs-fixer
run: |
tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --dry-run --diff --show-progress=dots .
run: vendor/bin/php-cs-fixer fix --dry-run --diff --show-progress=dots
packages:
runs-on: ubuntu-20.04
needs: php-cs-fixer
Expand Down Expand Up @@ -67,9 +64,5 @@ jobs:
# sparse-checkout: |
# ${{ matrix.path }}
- uses: shivammathur/setup-php@v2
- name: composer install
run: |
composer install
- name: vendor/bin/phpunit
run: |
vendor/bin/phpunit
- run: composer install
- run: vendor/bin/phpunit
30 changes: 30 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);
use PedroTroller\CS\Fixer\Fixers;
use PedroTroller\CS\Fixer\RuleSetFactory;
use PhpCsFixer\Config;
use PhpCsFixer\Finder;

$finder = (new Finder())
->in(__DIR__.'/src')
->in(__DIR__.'/bin')
->append([__FILE__])
;

$rules = RuleSetFactory::create()
->phpCsFixer(true)
->php(8.1, true)
->enable('PedroTroller/exceptions_punctuation')
->enable('PedroTroller/useless_code_after_return')
->disable('php_unit_strict')
->disable('PedroTroller/line_break_between_method_arguments')
->getRules()
;

return (new Config())
->setRiskyAllowed(true)
->registerCustomFixers(new Fixers())
->setRules($rules)
->setFinder($finder)
;
184 changes: 0 additions & 184 deletions .php-cs-fixer.php

This file was deleted.

18 changes: 10 additions & 8 deletions bin/sync-composer.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php

$global = \json_decode(
(string) \file_get_contents(__DIR__ . '/../composer.json'),
declare(strict_types=1);

$global = json_decode(
(string) file_get_contents(__DIR__.'/../composer.json'),
true,
flags: \JSON_THROW_ON_ERROR,
);
Expand All @@ -14,13 +16,13 @@
$replace = $global['replace'];

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

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

$json = \json_decode(
$json = json_decode(
$content,
true,
flags: \JSON_THROW_ON_ERROR,
Expand All @@ -33,16 +35,16 @@
}

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

$json[$part][$name] = $dependencies[$name];
}
}

$content = \file_put_contents(
$path . '/composer.json',
\json_encode(
$content = file_put_contents(
$path.'/composer.json',
json_encode(
$json,
flags: \JSON_PRETTY_PRINT | \JSON_THROW_ON_ERROR | \JSON_UNESCAPED_SLASHES,
),
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
"symfony/process": "^5.4|^6.4|^7.1"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.64",
"nyholm/psr7": "^1.8",
"pedrotroller/php-cs-custom-fixer": "^2.33",
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan": "^1.12",
"phpstan/phpstan-phpunit": "^1.4",
Expand Down
8 changes: 3 additions & 5 deletions src/Backend/Dompdf/DompdfAdapter.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace KNPLabs\Snappy\Backend\Dompdf;

use DOMDocument;
use Dompdf;
use KNPLabs\Snappy\Core\Backend\Adapter\DOMDocumentToPdf;
use KNPLabs\Snappy\Core\Backend\Adapter\HtmlFileToPdf;
Expand All @@ -13,7 +12,6 @@
use KNPLabs\Snappy\Core\Backend\Options;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\StreamInterface;
use SplFileInfo;

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

public function generateFromDOMDocument(DOMDocument $DOMDocument): StreamInterface
public function generateFromDOMDocument(\DOMDocument $DOMDocument): StreamInterface
{
$dompdf = $this->buildDompdf();
$dompdf->loadDOM($DOMDocument);

return $this->createStream($dompdf);
}

public function generateFromHtmlFile(SplFileInfo $file): StreamInterface
public function generateFromHtmlFile(\SplFileInfo $file): StreamInterface
{
$dompdf = $this->buildDompdf();
$dompdf->loadHtmlFile($file->getPath());
Expand Down
6 changes: 2 additions & 4 deletions src/Backend/Dompdf/DompdfFactory.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace KNPLabs\Snappy\Backend\Dompdf;

Expand All @@ -13,9 +13,7 @@
*/
final readonly class DompdfFactory implements Factory
{
public function __construct(private readonly StreamFactoryInterface $streamFactory)
{
}
public function __construct(private readonly StreamFactoryInterface $streamFactory) {}

public function create(Options $options): DompdfAdapter
{
Expand Down
8 changes: 3 additions & 5 deletions src/Backend/WkHtmlToPdf/WkHtmlToPdfAdapter.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace KNPLabs\Snappy\Backend\WkHtmlToPdf;

use KNPLabs\Snappy\Core\Backend\Adapter\HtmlFileToPdf;
use KNPLabs\Snappy\Core\Backend\Adapter\Reconfigurable;
use KNPLabs\Snappy\Core\Backend\Options;
use Psr\Http\Message\StreamInterface;
use SplFileInfo;
use Exception;

final class WkHtmlToPdfAdapter implements HtmlFileToPdf
{
Expand All @@ -32,8 +30,8 @@ public function __construct(
$this->options = $options;
}

public function generateFromHtmlFile(SplFileInfo $file): StreamInterface
public function generateFromHtmlFile(\SplFileInfo $file): StreamInterface
{
throw new Exception("Not implemented for {$this->binary} with timeout {$this->timeout}.");
throw new \Exception("Not implemented for {$this->binary} with timeout {$this->timeout}.");
}
}
Loading

0 comments on commit 5b37223

Please sign in to comment.