diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 52341c17..b92ba318 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -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 @@ -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 diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 00000000..83f32dc6 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,29 @@ +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('PedroTroller/line_break_between_method_arguments') + ->getRules() +; + +return (new Config()) + ->setRiskyAllowed(true) + ->registerCustomFixers(new Fixers()) + ->setRules($rules) + ->setFinder($finder) +; diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php deleted file mode 100644 index af4d0bf5..00000000 --- a/.php-cs-fixer.php +++ /dev/null @@ -1,184 +0,0 @@ -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/bin/sync-composer.php b/bin/sync-composer.php index 835c3762..a24f94ba 100755 --- a/bin/sync-composer.php +++ b/bin/sync-composer.php @@ -1,7 +1,9 @@ options = $options; } - public function generateFromDOMDocument(DOMDocument $DOMDocument): StreamInterface + public function generateFromDOMDocument(\DOMDocument $DOMDocument): StreamInterface { $dompdf = $this->buildDompdf(); $dompdf->loadDOM($DOMDocument); @@ -36,7 +34,7 @@ public function generateFromDOMDocument(DOMDocument $DOMDocument): StreamInterfa return $this->createStream($dompdf); } - public function generateFromHtmlFile(SplFileInfo $file): StreamInterface + public function generateFromHtmlFile(\SplFileInfo $file): StreamInterface { $dompdf = $this->buildDompdf(); $dompdf->loadHtmlFile($file->getPath()); diff --git a/src/Backend/Dompdf/DompdfFactory.php b/src/Backend/Dompdf/DompdfFactory.php index b8e83b6b..6482eec7 100644 --- a/src/Backend/Dompdf/DompdfFactory.php +++ b/src/Backend/Dompdf/DompdfFactory.php @@ -1,6 +1,6 @@ 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}."); } } diff --git a/src/Backend/WkHtmlToPdf/WkHtmlToPdfFactory.php b/src/Backend/WkHtmlToPdf/WkHtmlToPdfFactory.php index c73ba6a6..634cd93f 100644 --- a/src/Backend/WkHtmlToPdf/WkHtmlToPdfFactory.php +++ b/src/Backend/WkHtmlToPdf/WkHtmlToPdfFactory.php @@ -1,6 +1,6 @@ options); diff --git a/src/Core/Backend/Adapter/UriToPdf.php b/src/Core/Backend/Adapter/UriToPdf.php index e62f303d..df2c21e1 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 7556cfe9..c1e64b5e 100644 --- a/src/Core/Backend/Options/PageOrientation.php +++ b/src/Core/Backend/Options/PageOrientation.php @@ -1,6 +1,6 @@ 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); } - public function withOptions(Options|callable $options): self + public function withOptions(callable|Options $options): self { return new self($this->adapter->withOptions($options)); } diff --git a/src/Core/Bridge/FromHtmlToHtmlFileToPdf.php b/src/Core/Bridge/FromHtmlToHtmlFileToPdf.php index faa3961b..b33935f6 100644 --- a/src/Core/Bridge/FromHtmlToHtmlFileToPdf.php +++ b/src/Core/Bridge/FromHtmlToHtmlFileToPdf.php @@ -1,6 +1,6 @@ streamFactory); - \file_put_contents($temporary->file->getPathname(), $html); + file_put_contents($temporary->file->getPathname(), $html); return $this->adapter->generateFromHtmlFile($temporary->file); } - public function withOptions(Options|callable $options): self + public function withOptions(callable|Options $options): self { return new self( $this->adapter->withOptions($options), diff --git a/src/Core/Stream/FileStream.php b/src/Core/Stream/FileStream.php index 5a8b4585..c2491347 100644 --- a/src/Core/Stream/FileStream.php +++ b/src/Core/Stream/FileStream.php @@ -1,34 +1,32 @@ 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.'); + throw new \UnexpectedValueException('Unable to retrieve the uri of the temporary file created.'); } return new self( - new SplFileInfo($filename), + new \SplFileInfo($filename), $stream ); } diff --git a/src/Core/Stream/StreamWrapper.php b/src/Core/Stream/StreamWrapper.php index efc85e70..5240412e 100644 --- a/src/Core/Stream/StreamWrapper.php +++ b/src/Core/Stream/StreamWrapper.php @@ -1,5 +1,7 @@ stream = FileStream::createTmpFile( new Psr17Factory(), @@ -23,18 +28,18 @@ public function testTmpFileStreamCreateTemporaryFile(): void { $file = $this->stream->file; - $this->assertFileExists($file->getPathname()); - $this->assertFileIsReadable($file->getPathname()); - $this->assertFileIsWritable($file->getPathname()); + self::assertFileExists($file->getPathname()); + self::assertFileIsReadable($file->getPathname()); + self::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( + self::assertSame( (string) $this->stream, 'the content', ); @@ -44,10 +49,10 @@ public function testTmpFileIsAutomaticalyRemoved(): void { $file = $this->stream->file; - $this->assertFileExists($file->getPathname()); + self::assertFileExists($file->getPathname()); - unset($this->stream); + $this->stream = null; - $this->assertFileDoesNotExist($file->getPathname()); + self::assertFileDoesNotExist($file->getPathname()); } } diff --git a/src/Framework/Symfony/DependencyInjection/Configuration.php b/src/Framework/Symfony/DependencyInjection/Configuration.php index f2705735..7349a483 100644 --- a/src/Framework/Symfony/DependencyInjection/Configuration.php +++ b/src/Framework/Symfony/DependencyInjection/Configuration.php @@ -1,14 +1,14 @@ arrayNode('backends') ->useAttributeAsKey('name') ->example( - \array_merge( - ...\array_map( - fn (BackendConfigurationFactory $factory): array => [ + array_merge( + ...array_map( + static fn (BackendConfigurationFactory $factory): array => [ $factory->getKey() => [ 'pageOrientation' => PageOrientation::PORTRAIT->value, 'options' => [], @@ -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( + static 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 e58b18a0..06b0ce4e 100644 --- a/src/Framework/Symfony/DependencyInjection/Configuration/BackendConfigurationFactory.php +++ b/src/Framework/Symfony/DependencyInjection/Configuration/BackendConfigurationFactory.php @@ -1,6 +1,6 @@ [$factory->getKey() => $factory], $this->getFactories(), ), @@ -63,7 +63,7 @@ public function getConfiguration(array $configuration, ContainerBuilder $contain */ private function getFactories(): array { - return \array_filter( + return array_filter( [ new DompdfConfigurationFactory(), new WkHtmlToPdfConfigurationFactory(), @@ -100,7 +100,7 @@ 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'])), ); + 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']); @@ -108,7 +108,7 @@ private function buildOptions(string $backendName, string $backendType, array $c 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'])), ); + 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']; diff --git a/src/Framework/Symfony/SnappyBundle.php b/src/Framework/Symfony/SnappyBundle.php index bbc57ffb..eabd7da0 100644 --- a/src/Framework/Symfony/SnappyBundle.php +++ b/src/Framework/Symfony/SnappyBundle.php @@ -1,6 +1,6 @@ extension = new SnappyExtension(); $this->container = new ContainerBuilder(); @@ -41,8 +46,8 @@ public function testLoadEmptyConfiguration(): void $this->container, ); - $this->assertEquals( - \array_keys($this->container->getDefinitions()), + self::assertSame( + array_keys($this->container->getDefinitions()), [ 'service_container', StreamFactoryInterface::class, @@ -76,8 +81,8 @@ public function testDompdfBackendConfiguration(): void $this->extension->load($configuration, $this->container); - $this->assertEquals( - \array_keys($this->container->getDefinitions()), + self::assertSame( + array_keys($this->container->getDefinitions()), [ 'service_container', StreamFactoryInterface::class, @@ -88,25 +93,25 @@ public function testDompdfBackendConfiguration(): void $streamFactory = $this->container->get(StreamFactoryInterface::class); - $this->assertInstanceOf(StreamFactoryInterface::class, $streamFactory); + self::assertInstanceOf(StreamFactoryInterface::class, $streamFactory); $factory = $this->container->get('snappy.backend.myBackend.factory'); - $this->assertInstanceOf(DompdfFactory::class, $factory); - $this->assertEquals( + self::assertInstanceOf(DompdfFactory::class, $factory); + self::assertSame( $factory, new DompdfFactory($streamFactory) ); $backend = $this->container->get('snappy.backend.myBackend'); - $this->assertInstanceOf(DompdfAdapter::class, $backend); - $this->assertEquals( + self::assertInstanceOf(DompdfAdapter::class, $backend); + self::assertSame( $factory, new DompdfFactory($streamFactory), ); - $this->assertEquals( + self::assertSame( $backend, new DompdfAdapter( $factory, diff --git a/tools/php-cs-fixer/composer.json b/tools/php-cs-fixer/composer.json deleted file mode 100644 index 6bd14d7e..00000000 --- a/tools/php-cs-fixer/composer.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "require-dev": { - "friendsofphp/php-cs-fixer": "^3.64", - "pedrotroller/php-cs-custom-fixer": "^2.33" - } -}