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 11, 2024
1 parent 6f407df commit 66dd097
Show file tree
Hide file tree
Showing 30 changed files with 132 additions and 302 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
28 changes: 28 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?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')
->append([__FILE__])
;

$rules = RuleSetFactory::create()
->phpCsFixer(true)
->php(8.1, true)
->enable('PedroTroller/exceptions_punctuation')
->enable('PedroTroller/line_break_between_method_arguments', ['max-args' => 5])
->enable('PedroTroller/useless_code_after_return')
->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.

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}.");
}
}
7 changes: 2 additions & 5 deletions src/Backend/WkHtmlToPdf/WkHtmlToPdfFactory.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\WkHtmlToPdf;

Expand All @@ -17,10 +17,7 @@ final class WkHtmlToPdfFactory implements Factory
* @param non-empty-string $binary
* @param positive-int $timeout
*/
public function __construct(private readonly string $binary, private readonly int $timeout)
{

}
public function __construct(private readonly string $binary, private readonly int $timeout) {}

public function create(Options $options): Adapter
{
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Backend/Adapter.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\Core\Backend;

Expand All @@ -9,5 +9,5 @@ interface Adapter
/**
* @param (callable(Options $options): Options)|Options $options
*/
public function withOptions(Options|callable $options): static;
public function withOptions(callable|Options $options): static;
}
5 changes: 2 additions & 3 deletions src/Core/Backend/Adapter/DOMDocumentToPdf.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?php

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

namespace KNPLabs\Snappy\Core\Backend\Adapter;

use KNPLabs\Snappy\Core\Backend\Adapter;
use Psr\Http\Message\StreamInterface;
use DOMDocument;

interface DOMDocumentToPdf extends Adapter
{
public function generateFromDOMDocument(DOMDocument $DOMDocument): StreamInterface;
public function generateFromDOMDocument(\DOMDocument $DOMDocument): StreamInterface;
}
Loading

0 comments on commit 66dd097

Please sign in to comment.