diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..71a80b6c --- /dev/null +++ b/.editorconfig @@ -0,0 +1,16 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# top-most EditorConfig file +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = false +insert_final_newline = true + +[*.{yaml,yml}] +indent_style = space +indent_size = 2 diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml deleted file mode 100644 index b696ac2c..00000000 --- a/.github/workflows/build.yaml +++ /dev/null @@ -1,107 +0,0 @@ -name: Build - -on: - pull_request: ~ - push: ~ - -jobs: - check: - runs-on: ubuntu-20.04 - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Setup PHP - uses: shivammathur/setup-php@v2 - - name: Validate composer.json - run: | - (cd src/Bundle && composer validate --strict --no-check-lock) - tests: - runs-on: ubuntu-20.04 - strategy: - fail-fast: false - matrix: - include: - - description: 'Symfony 6.3 DEV' - php: '8.2' - symfony: '6.3.*@dev' - - description: 'Symfony 6.2' - php: '8.2' - symfony: '6.2.*' - - description: 'Symfony 6.0' - php: '8.1' - symfony: '6.0.*' - - description: 'Symfony 5.4' - php: '7.3' - symfony: '5.4.*' - - description: 'Beta deps' - php: '7.2' - beta: true - name: PHP ${{ matrix.php }} tests (${{ matrix.description }}) - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Cache - uses: actions/cache@v3 - with: - path: ~/.composer/cache/files - key: composer-${{ matrix.php }}-${{ matrix.symfony }}-${{ matrix.composer_option }} - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - - run: | - sed -ri 's/"symfony\/(.+)": "(.+)"/"symfony\/\1": "'${{ matrix.symfony }}'"/' src/Bundle/composer.json; - if: matrix.symfony - - run: | - composer config minimum-stability dev - composer config prefer-stable true - if: matrix.beta - - run: | - (cd src/Bundle && composer update --prefer-dist --no-interaction --no-progress --ansi ${{ matrix.composer_option }}) - - run: | - (cd src/Bundle && vendor/bin/phpunit) - tests-windows: - runs-on: windows-2022 - strategy: - fail-fast: false - matrix: - include: - - description: 'Symfony 6.3 DEV' - php: '8.2' - symfony: '6.3.*@dev' - - description: 'Symfony 6.2' - php: '8.2' - symfony: '6.2.*' - - description: 'Symfony 6.0' - php: '8.1' - symfony: '6.0.*' - - description: 'Symfony 5.4' - php: '7.3' - symfony: '5.4.*' - - description: 'Beta deps' - php: '7.2' - beta: true - name: "[WINDOWS] PHP ${{ matrix.php }} tests (${{ matrix.description }})" - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Cache - uses: actions/cache@v3 - with: - path: ~/.composer/cache/files - key: composer-${{ matrix.php }}-${{ matrix.symfony }}-${{ matrix.composer_option }} - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - - run: | - (Get-Content composer.json) -replace '("symfony/[^"]+": )"[^"]+"', '$1"${{ matrix.symfony }}"' | Out-File -encoding ASCII src/Bundle/composer.json - if: matrix.symfony - - run: | - composer config minimum-stability dev - composer config prefer-stable true - if: matrix.beta - - run: | - {cd src/Bundle && composer update --prefer-dist --no-interaction --no-progress --ansi ${{ matrix.composer_option }}} - - run: | - {cd src/Bundle && vendor/bin/phpunit} diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 33956051..52341c17 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -1,12 +1,23 @@ name: Tests on: - pull_request: ~ push: ~ jobs: + php-cs-fixer: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v4 + - uses: shivammathur/setup-php@v2 + - name: composer install + run: | + composer --working-dir=tools/php-cs-fixer install + - name: php-cs-fixer + run: | + tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --dry-run --diff --show-progress=dots . packages: runs-on: ubuntu-20.04 + needs: php-cs-fixer outputs: packages: ${{ steps.script.outputs.result }} steps: @@ -52,10 +63,9 @@ jobs: working-directory: ${{ matrix.path }} steps: - uses: actions/checkout@v4 - with: - sparse-checkout: | - src/Core/ - ${{ matrix.path }} + # with: + # sparse-checkout: | + # ${{ matrix.path }} - uses: shivammathur/setup-php@v2 - name: composer install run: | diff --git a/.gitignore b/.gitignore index ff72e2d0..f05530d5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -/composer.lock -/vendor +**/composer.lock +**/vendor +**cache** diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 00000000..af4d0bf5 --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,184 @@ +setRiskyAllowed(true) + ->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers()) + ->setRules([ + '@PHP71Migration' => true, + '@PSR1' => true, + '@PSR2' => true, + 'array_indentation' => true, + 'array_syntax' => ['syntax' => 'short'], + 'align_multiline_comment' => [ + 'comment_type' => 'all_multiline', + ], + 'array_syntax' => [ + 'syntax' => 'short', + ], + 'binary_operator_spaces' => true, + 'blank_line_after_opening_tag' => true, + 'blank_line_before_statement' => true, + 'cast_spaces' => true, + 'class_attributes_separation' => true, + 'combine_consecutive_issets' => true, + 'combine_consecutive_unsets' => true, + 'compact_nullable_typehint' => true, + 'concat_space' => ['spacing' => 'one'], + 'date_time_immutable' => true, + 'declare_equal_normalize' => [ + 'space' => 'single', + ], + 'dir_constant' => true, + 'ereg_to_preg' => true, + 'escape_implicit_backslashes' => true, + 'explicit_indirect_variable' => true, + 'explicit_string_variable' => true, + 'fopen_flag_order' => true, + 'fopen_flags' => true, + 'fully_qualified_strict_types' => true, + 'function_to_constant' => [ + 'functions' => [ + 'get_class', + 'php_sapi_name', + 'phpversion', + 'pi', + ], + ], + 'function_typehint_space' => true, + 'global_namespace_import' => true, + 'heredoc_to_nowdoc' => true, + 'implode_call' => true, + 'include' => true, + 'is_null' => true, + 'linebreak_after_opening_tag' => true, + 'list_syntax' => [ + 'syntax' => 'long', + ], + 'logical_operators' => true, + 'lowercase_cast' => true, + 'lowercase_static_reference' => true, + 'magic_constant_casing' => true, + 'magic_method_casing' => true, + 'method_chaining_indentation' => true, + 'modernize_types_casting' => true, + 'multiline_comment_opening_closing' => true, + 'multiline_whitespace_before_semicolons' => [ + 'strategy' => 'new_line_for_chained_calls', + ], + 'native_constant_invocation' => [ + 'include' => ['@internal'], + 'scope' => 'all', + ], + 'native_function_casing' => true, + 'native_function_invocation' => ['include' => ['@all']], + 'native_function_type_declaration_casing' => true, + 'new_with_braces' => true, + 'no_alternative_syntax' => true, + 'no_binary_string' => true, + 'no_blank_lines_after_class_opening' => true, + 'no_blank_lines_after_phpdoc' => true, + 'no_empty_comment' => true, + 'no_empty_phpdoc' => true, + 'no_empty_statement' => true, + 'no_extra_blank_lines' => [ + 'tokens' => ['extra'], + ], + 'no_leading_import_slash' => true, + 'no_leading_namespace_whitespace' => true, + 'no_mixed_echo_print' => true, + 'no_multiline_whitespace_around_double_arrow' => true, + 'no_short_bool_cast' => true, + 'echo_tag_syntax' => ['format' => 'long'], + 'no_singleline_whitespace_before_semicolons' => true, + 'no_spaces_around_offset' => [ + 'positions' => ['inside', 'outside'], + ], + 'no_superfluous_elseif' => true, + 'no_superfluous_phpdoc_tags' => false, + 'no_trailing_comma_in_list_call' => true, + 'no_trailing_comma_in_singleline_array' => true, + 'no_unneeded_curly_braces' => true, + 'no_unused_imports' => true, + 'no_useless_else' => true, + 'no_useless_return' => true, + 'no_whitespace_before_comma_in_array' => true, + 'no_whitespace_in_blank_line' => true, + 'normalize_index_brace' => true, + 'object_operator_without_whitespace' => true, + 'ordered_class_elements' => [ + 'order' => [ + 'use_trait', + 'constant_public', + 'constant_protected', + 'constant_private', + 'property_public', + 'property_protected', + 'property_private', + 'construct', + 'destruct', + 'magic', + 'phpunit', + 'method_public', + 'method_protected', + 'method_private', + ], + ], + 'php_unit_construct' => [ + 'assertions' => [ + 'assertEquals', + 'assertSame', + 'assertNotEquals', + 'assertNotSame', + ], + ], + // Check on other phpunit stuff + 'phpdoc_align' => [ + 'align' => 'vertical', + ], + 'phpdoc_indent' => true, + 'general_phpdoc_tag_rename' => ['fix_inline' => true], + 'phpdoc_no_access' => true, + 'phpdoc_no_alias_tag' => true, + 'phpdoc_no_empty_return' => false, + 'phpdoc_no_package' => true, + 'phpdoc_no_useless_inheritdoc' => true, + 'phpdoc_order' => true, + 'phpdoc_return_self_reference' => true, + 'phpdoc_scalar' => true, + 'phpdoc_separation' => true, + 'phpdoc_single_line_var_spacing' => true, + 'phpdoc_summary' => true, + 'phpdoc_to_comment' => true, + 'phpdoc_trim' => true, + 'phpdoc_trim_consecutive_blank_line_separation' => true, + 'phpdoc_types' => true, + 'phpdoc_types_order' => true, + 'phpdoc_var_annotation_correct_order' => true, + 'phpdoc_var_without_name' => true, + 'return_assignment' => true, + 'return_type_declaration' => true, + 'semicolon_after_instruction' => true, + 'short_scalar_cast' => true, + 'single_blank_line_before_namespace' => true, + 'single_line_comment_style' => true, + 'single_line_throw' => true, + 'single_quote' => true, + 'single_trait_insert_per_statement' => true, + 'space_after_semicolon' => true, + 'standardize_increment' => true, + 'standardize_not_equals' => true, + 'strict_comparison' => true, + 'ternary_operator_spaces' => true, + 'trailing_comma_in_multiline' => ['elements' => ['arrays']], + 'trim_array_spaces' => true, + 'unary_operator_spaces' => true, + 'whitespace_after_comma_in_array' => true, + 'PedroTroller/exceptions_punctuation' => true, + 'PedroTroller/line_break_between_method_arguments' => [ + 'max-args' => 5, + ], + 'PedroTroller/useless_code_after_return' => true, + ]) +; diff --git a/.phpunit.result.cache b/.phpunit.result.cache deleted file mode 100644 index 7399b970..00000000 --- a/.phpunit.result.cache +++ /dev/null @@ -1 +0,0 @@ -{"version":1,"defects":{"KNPLabs\\Snappy\\Framework\\Symfony\\Tests\\DependencyInjection\\SnappyExtensionTest::testLoadEmptyConfiguration":8,"KNPLabs\\Snappy\\Framework\\Symfony\\Tests\\DependencyInjection\\SnappyExtensionTest::testConfigure":5,"KNPLabs\\Snappy\\Framework\\Symfony\\Tests\\DependencyInjection\\SnappyExtensionTest::testConfigureTmpDirectory":7,"KNPLabs\\Snappy\\Framework\\Symfony\\Tests\\DependencyInjection\\SnappyExtensionTest::testDompdfBackendConfiguration":8,"KNPLabs\\Snappy\\Core\\Tests\\Stream\\FileStreamTest::testTmpFileIsAutomaticalyRemoved":8},"times":{"KNPLabs\\Snappy\\Framework\\Symfony\\Tests\\DependencyInjection\\SnappyExtensionTest::testLoadEmptyConfiguration":0.008,"KNPLabs\\Snappy\\Framework\\Symfony\\Tests\\DependencyInjection\\SnappyExtensionTest::testConfigure":0,"KNPLabs\\Snappy\\Framework\\Symfony\\Tests\\DependencyInjection\\SnappyExtensionTest::testConfigureTmpDirectory":0,"KNPLabs\\Snappy\\Framework\\Symfony\\Tests\\DependencyInjection\\SnappyExtensionTest::testDompdfBackendConfiguration":0.015,"KNPLabs\\Snappy\\Core\\Tests\\Stream\\FileStreamTest::testTmpFileStream":0.005,"KNPLabs\\Snappy\\Core\\Tests\\Stream\\FileStreamTest::testTmpFileStreamCreateTemporaryFile":0.003,"KNPLabs\\Snappy\\Core\\Tests\\Stream\\FileStreamTest::testTmpFileStreamReadTheFile":0.004,"KNPLabs\\Snappy\\Core\\Tests\\Stream\\FileStreamTest::testTmpFileIsAutomaticalyRemoved":0.003}} \ No newline at end of file diff --git a/bin/sync-composer.php b/bin/sync-composer.php index 9e0cae15..835c3762 100755 --- a/bin/sync-composer.php +++ b/bin/sync-composer.php @@ -1,9 +1,9 @@ factory = $factory; $this->options = $options; } @@ -58,13 +54,13 @@ public function generateFromHtml(string $html): StreamInterface private function buildDompdf(): Dompdf\Dompdf { - return new Dompdf\Dompdf( $this->compileConstructOptions()); + return new Dompdf\Dompdf($this->compileConstructOptions()); } private function compileConstructOptions(): Dompdf\Options { $options = new Dompdf\Options( - is_array($this->options->extraOptions['construct']) + \is_array($this->options->extraOptions['construct']) ? $this->options->extraOptions['construct'] : null ); @@ -85,7 +81,7 @@ private function compileOutputOptions(): array { $options = $this->options->extraOptions['output']; - if (false === is_array($options)) { + if (false === \is_array($options)) { $options = []; } diff --git a/src/Backend/Dompdf/DompdfFactory.php b/src/Backend/Dompdf/DompdfFactory.php index 17b08f6b..b8e83b6b 100644 --- a/src/Backend/Dompdf/DompdfFactory.php +++ b/src/Backend/Dompdf/DompdfFactory.php @@ -1,12 +1,10 @@ binary} with timeout {$this->timeout}."); + throw new Exception("Not implemented for {$this->binary} with timeout {$this->timeout}."); } } diff --git a/src/Backend/WkHtmlToPdf/WkHtmlToPdfFactory.php b/src/Backend/WkHtmlToPdf/WkHtmlToPdfFactory.php index 77829e36..c73ba6a6 100644 --- a/src/Backend/WkHtmlToPdf/WkHtmlToPdfFactory.php +++ b/src/Backend/WkHtmlToPdf/WkHtmlToPdfFactory.php @@ -1,13 +1,12 @@ @@ -16,7 +15,7 @@ final class WkHtmlToPdfFactory implements Factory { /** * @param non-empty-string $binary - * @param positive-int $timeout + * @param positive-int $timeout */ public function __construct(private readonly string $binary, private readonly int $timeout) { diff --git a/src/Core/Backend/Adapter.php b/src/Core/Backend/Adapter.php index b06af24c..fad7207d 100644 --- a/src/Core/Backend/Adapter.php +++ b/src/Core/Backend/Adapter.php @@ -1,13 +1,13 @@ options); } diff --git a/src/Core/Backend/Adapter/UriToPdf.php b/src/Core/Backend/Adapter/UriToPdf.php index df2c21e1..e62f303d 100644 --- a/src/Core/Backend/Adapter/UriToPdf.php +++ b/src/Core/Backend/Adapter/UriToPdf.php @@ -1,6 +1,6 @@ $extraOptions */ - public function __construct( - public readonly ?PageOrientation $pageOrientation, - public readonly array $extraOptions - ) { + public function __construct(public readonly ?PageOrientation $pageOrientation, public readonly array $extraOptions) + { } public static function create(): self diff --git a/src/Core/Backend/Options/PageOrientation.php b/src/Core/Backend/Options/PageOrientation.php index 46d466ee..7556cfe9 100644 --- a/src/Core/Backend/Options/PageOrientation.php +++ b/src/Core/Backend/Options/PageOrientation.php @@ -1,12 +1,11 @@ getPathname()); + $html = \file_get_contents($file->getPathname()); if (false === $html) { - throw new \RuntimeException('Unable to read file.'); + throw new RuntimeException('Unable to read file.'); } return $this->adapter->generateFromHtml($html); @@ -31,6 +30,6 @@ public function generateFromHtmlFile(\SplFileInfo $file): StreamInterface public function withOptions(Options|callable $options): self { - return new self( $this->adapter->withOptions($options)); + return new self($this->adapter->withOptions($options)); } } diff --git a/src/Core/Bridge/FromHtmlToHtmlFileToPdf.php b/src/Core/Bridge/FromHtmlToHtmlFileToPdf.php index 03f2e397..faa3961b 100644 --- a/src/Core/Bridge/FromHtmlToHtmlFileToPdf.php +++ b/src/Core/Bridge/FromHtmlToHtmlFileToPdf.php @@ -1,30 +1,29 @@ streamFactory); - file_put_contents($temporary->file->getPathname(), $html); + \file_put_contents($temporary->file->getPathname(), $html); return $this->adapter->generateFromHtmlFile($temporary->file); } diff --git a/src/Core/Stream/FileStream.php b/src/Core/Stream/FileStream.php index 3e115434..5a8b4585 100644 --- a/src/Core/Stream/FileStream.php +++ b/src/Core/Stream/FileStream.php @@ -1,24 +1,30 @@ stream = $stream; + } + public static function createTmpFile(StreamFactoryInterface $streamFactory): self { - $stream = $streamFactory->createStreamFromResource(tmpFile()); + $stream = $streamFactory->createStreamFromResource(\tmpfile()); $filename = $stream->getMetadata('uri'); - if (false === is_string($filename)) { - throw new \UnexpectedValueException('Unable to retrieve the uri of the temporary file created.'); + if (false === \is_string($filename)) { + throw new UnexpectedValueException('Unable to retrieve the uri of the temporary file created.'); } return new self( @@ -26,9 +32,4 @@ public static function createTmpFile(StreamFactoryInterface $streamFactory): sel $stream ); } - - public function __construct(public readonly SplFileInfo $file, StreamInterface $stream) - { - $this->stream = $stream; - } } diff --git a/src/Core/Tests/Stream/FileStreamTest.php b/src/Core/Tests/Stream/FileStreamTest.php index f5d88ed4..58aeaa1a 100644 --- a/src/Core/Tests/Stream/FileStreamTest.php +++ b/src/Core/Tests/Stream/FileStreamTest.php @@ -1,6 +1,6 @@ stream = FileStream::createTmpFile( - new Psr17Factory, + new Psr17Factory(), ); } @@ -24,15 +24,15 @@ public function testTmpFileStreamCreateTemporaryFile(): void $file = $this->stream->file; $this->assertFileExists($file->getPathname()); - $this->assertFileIsReadable( $file->getPathname()); - $this->assertFileIsWritable( $file->getPathname()); + $this->assertFileIsReadable($file->getPathname()); + $this->assertFileIsWritable($file->getPathname()); } public function testTmpFileStreamReadTheFile(): void { $file = $this->stream->file; - file_put_contents($file->getPathname(), 'the content'); + \file_put_contents($file->getPathname(), 'the content'); $this->assertEquals( (string) $this->stream, diff --git a/src/Framework/Symfony/DependencyInjection/Configuration.php b/src/Framework/Symfony/DependencyInjection/Configuration.php index d5e5548c..f2705735 100644 --- a/src/Framework/Symfony/DependencyInjection/Configuration.php +++ b/src/Framework/Symfony/DependencyInjection/Configuration.php @@ -1,6 +1,6 @@ getRootNode(); + $rootNode = $treeBuilder->getRootNode(); $backendNodeBuilder = $rootNode ->children() ->arrayNode('backends') ->useAttributeAsKey('name') ->example( - array_merge( - ...array_map( - fn(BackendConfigurationFactory $factory): array => [ + \array_merge( + ...\array_map( + fn (BackendConfigurationFactory $factory): array => [ $factory->getKey() => [ 'pageOrientation' => PageOrientation::PORTRAIT->value, 'options' => [], - ...$factory->getExample() + ...$factory->getExample(), ], ], $this->factories @@ -49,7 +49,7 @@ public function getConfigTreeBuilder(): TreeBuilder ; foreach ($this->factories as $factory) { - $name = str_replace('-', '_', $factory->getKey()); + $name = \str_replace('-', '_', $factory->getKey()); $factoryNode = $backendNodeBuilder ->children() @@ -76,8 +76,8 @@ private function buildOptionsConfiguration(ArrayNodeDefinition $node): void ->children() ->enumNode('pageOrientation') ->values( - array_map( - fn(PageOrientation $pageOrientation): string => $pageOrientation->value, + \array_map( + fn (PageOrientation $pageOrientation): string => $pageOrientation->value, PageOrientation::cases(), ) ) diff --git a/src/Framework/Symfony/DependencyInjection/Configuration/BackendConfigurationFactory.php b/src/Framework/Symfony/DependencyInjection/Configuration/BackendConfigurationFactory.php index 39970846..e58b18a0 100644 --- a/src/Framework/Symfony/DependencyInjection/Configuration/BackendConfigurationFactory.php +++ b/src/Framework/Symfony/DependencyInjection/Configuration/BackendConfigurationFactory.php @@ -1,11 +1,10 @@ $configuration + * @param array $configuration * @param non-empty-string $backendId * @param non-empty-string $factoryId * @param non-empty-string $backendName */ - public function create(ContainerBuilder $container, array $configuration, string $backendId, string $backendName, string $factoryId, Definition $options): void; + public function create( + ContainerBuilder $container, + array $configuration, + string $backendId, + string $backendName, + string $factoryId, + Definition $options + ): void; public function addConfiguration(ArrayNodeDefinition $node): void; } diff --git a/src/Framework/Symfony/DependencyInjection/Configuration/DompdfConfigurationFactory.php b/src/Framework/Symfony/DependencyInjection/Configuration/DompdfConfigurationFactory.php index 100a605c..5a5dbcf4 100644 --- a/src/Framework/Symfony/DependencyInjection/Configuration/DompdfConfigurationFactory.php +++ b/src/Framework/Symfony/DependencyInjection/Configuration/DompdfConfigurationFactory.php @@ -1,17 +1,14 @@ setDefinition( - $factoryId, - new Definition( - DompdfFactory::class, - [ - '$streamFactory' => $container->getDefinition(StreamFactoryInterface::class) - ] - ), - ); + $factoryId, + new Definition( + DompdfFactory::class, + [ + '$streamFactory' => $container->getDefinition(StreamFactoryInterface::class), + ] + ), + ) + ; $container ->setDefinition( @@ -56,9 +60,9 @@ public function getExample(): array { return [ 'extraOptions' => [ - 'construct' => [], + 'construct' => [], 'output' => [], - ] + ], ]; } @@ -75,13 +79,13 @@ public function addConfiguration(ArrayNodeDefinition $node): void $extraOptionsNode ->children() ->variableNode('construct') - ->info(sprintf('Configuration passed to %s::__construct().', Dompdf::class)) + ->info(\sprintf('Configuration passed to %s::__construct().', Dompdf::class)) ; $extraOptionsNode ->children() ->variableNode('output') - ->info(sprintf('Configuration passed to %s::output().', Dompdf::class)) + ->info(\sprintf('Configuration passed to %s::output().', Dompdf::class)) ; } } diff --git a/src/Framework/Symfony/DependencyInjection/Configuration/WkHtmlToPdfConfigurationFactory.php b/src/Framework/Symfony/DependencyInjection/Configuration/WkHtmlToPdfConfigurationFactory.php index 96b61888..267b1b3a 100644 --- a/src/Framework/Symfony/DependencyInjection/Configuration/WkHtmlToPdfConfigurationFactory.php +++ b/src/Framework/Symfony/DependencyInjection/Configuration/WkHtmlToPdfConfigurationFactory.php @@ -1,17 +1,13 @@ setDefinition( - $factoryId, - new Definition( - WkHtmlToPdfFactory::class, - [ - '$streamFactory' => $container->getDefinition(StreamFactoryInterface::class), - '$binary' => $configuration['binary'], - '$timeout' => $configuration['timeout'], - ] - ), - ); + $factoryId, + new Definition( + WkHtmlToPdfFactory::class, + [ + '$streamFactory' => $container->getDefinition(StreamFactoryInterface::class), + '$binary' => $configuration['binary'], + '$timeout' => $configuration['timeout'], + ] + ), + ) + ; $container ->setDefinition( diff --git a/src/Framework/Symfony/DependencyInjection/SnappyExtension.php b/src/Framework/Symfony/DependencyInjection/SnappyExtension.php index 7e138013..cdd9f59a 100644 --- a/src/Framework/Symfony/DependencyInjection/SnappyExtension.php +++ b/src/Framework/Symfony/DependencyInjection/SnappyExtension.php @@ -1,13 +1,11 @@ [$factory->getKey() => $factory], + $factories = \array_merge( + ...\array_map( + static fn (BackendConfigurationFactory $factory): array => [$factory->getKey() => $factory], $this->getFactories(), ), ); @@ -65,10 +63,10 @@ public function getConfiguration(array $configuration, ContainerBuilder $contain */ private function getFactories(): array { - return array_filter( + return \array_filter( [ - new DompdfConfigurationFactory, - new WkHtmlToPdfConfigurationFactory, + new DompdfConfigurationFactory(), + new WkHtmlToPdfConfigurationFactory(), ], static fn (BackendConfigurationFactory $factory): bool => $factory->isAvailable(), ); @@ -79,7 +77,7 @@ private function getFactories(): array */ private function buildBackendServiceId(string $name): string { - return "snappy.backend.$name"; + return "snappy.backend.{$name}"; } /** @@ -87,7 +85,7 @@ private function buildBackendServiceId(string $name): string */ private function buildFactoryServiceId(string $name): string { - return "snappy.backend.$name.factory"; + return "snappy.backend.{$name}.factory"; } /** @@ -101,35 +99,21 @@ private function buildOptions(string $backendName, string $backendType, array $c ]; if (isset($configuration['pageOrientation'])) { - if (false === is_string($configuration['pageOrientation'])) { - throw new InvalidConfigurationException( - sprintf( - 'Invalid “%s” type for “snappy.backends.%s.%s.options.pageOrientation”. The expected type is “string”.', - $backendName, - $backendType, - gettype($configuration['pageOrientation']) - ), - ); + if (false === \is_string($configuration['pageOrientation'])) { + throw new InvalidConfigurationException(\sprintf('Invalid “%s” type for “snappy.backends.%s.%s.options.pageOrientation”. The expected type is “string”.', $backendName, $backendType, \gettype($configuration['pageOrientation'])), ); } - $arguments[ '$pageOrientation'] = PageOrientation::from($configuration['pageOrientation']); + $arguments['$pageOrientation'] = PageOrientation::from($configuration['pageOrientation']); } if (isset($configuration['extraOptions'])) { - if (false === is_array($configuration['extraOptions'])) { - throw new InvalidConfigurationException( - sprintf( - 'Invalid “%s” type for “snappy.backends.%s.%s.options.extraOptions”. The expected type is “array”.', - $backendName, - $backendType, - gettype($configuration['extraOptions']) - ), - ); + if (false === \is_array($configuration['extraOptions'])) { + throw new InvalidConfigurationException(\sprintf('Invalid “%s” type for “snappy.backends.%s.%s.options.extraOptions”. The expected type is “array”.', $backendName, $backendType, \gettype($configuration['extraOptions'])), ); } - $arguments[ '$extraOptions'] = $configuration['extraOptions']; + $arguments['$extraOptions'] = $configuration['extraOptions']; } - return new Definition( Options::class, $arguments); + return new Definition(Options::class, $arguments); } } diff --git a/src/Framework/Symfony/SnappyBundle.php b/src/Framework/Symfony/SnappyBundle.php index e5f0de9f..bbc57ffb 100644 --- a/src/Framework/Symfony/SnappyBundle.php +++ b/src/Framework/Symfony/SnappyBundle.php @@ -1,17 +1,16 @@ extension = new SnappyExtension; - $this->container = new ContainerBuilder; + $this->extension = new SnappyExtension(); + $this->container = new ContainerBuilder(); $this->container->setDefinition( StreamFactoryInterface::class, @@ -45,7 +42,7 @@ public function testLoadEmptyConfiguration(): void ); $this->assertEquals( - array_keys($this->container->getDefinitions()), + \array_keys($this->container->getDefinitions()), [ 'service_container', StreamFactoryInterface::class, @@ -69,18 +66,18 @@ public function testDompdfBackendConfiguration(): void 'output' => [ 'compress' => '1', ], - ] - ] - ] - ] - ] + ], + ], + ], + ], + ], ], ]; $this->extension->load($configuration, $this->container); $this->assertEquals( - array_keys($this->container->getDefinitions()), + \array_keys($this->container->getDefinitions()), [ 'service_container', StreamFactoryInterface::class, @@ -107,7 +104,7 @@ public function testDompdfBackendConfiguration(): void $this->assertEquals( $factory, new DompdfFactory($streamFactory), - ) ; + ); $this->assertEquals( $backend, diff --git a/tools/php-cs-fixer/composer.json b/tools/php-cs-fixer/composer.json new file mode 100644 index 00000000..6bd14d7e --- /dev/null +++ b/tools/php-cs-fixer/composer.json @@ -0,0 +1,6 @@ +{ + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.64", + "pedrotroller/php-cs-custom-fixer": "^2.33" + } +}