diff --git a/.gitignore b/.gitignore index 2fe6060..20efee7 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ vendor/ .phpunit.cache tools .php-cs-fixer.cache -var \ No newline at end of file +var +rector.log \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index a36d7da..85f768a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * test: update phpstan and psalm * chore: update coding style * feat: support Symfony 7 & PHP 8.4 +* build: rectorization ## 1.1.0 diff --git a/Makefile b/Makefile index 4ff0dc8..ca8ccce 100644 --- a/Makefile +++ b/Makefile @@ -30,4 +30,9 @@ php-cs-fixer: tools/php-cs-fixer .PHONY: tools/php-cs-fixer tools/php-cs-fixer: - phive install php-cs-fixer \ No newline at end of file + phive install php-cs-fixer + +.PHONY: rector +rector: + $(PHP) vendor/bin/rector process > rector.log + make php-cs-fixer \ No newline at end of file diff --git a/composer.json b/composer.json index d0923ba..17655d4 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,8 @@ "phpunit/phpunit": "^10.5", "psalm/plugin-phpunit": "^0.18.4", "symplify/monorepo-builder": "^11.2", - "vimeo/psalm": "^5.26" + "vimeo/psalm": "^5.26", + "rector/rector": "^1.2" }, "replace": { "rekalogika/gotenberg-pdf-bundle": "1.1.0", diff --git a/packages/gotenberg-pdf-bundle/src/DependencyInjection/Configuration.php b/packages/gotenberg-pdf-bundle/src/DependencyInjection/Configuration.php index 369a0dc..ac155dc 100644 --- a/packages/gotenberg-pdf-bundle/src/DependencyInjection/Configuration.php +++ b/packages/gotenberg-pdf-bundle/src/DependencyInjection/Configuration.php @@ -18,6 +18,7 @@ class Configuration implements ConfigurationInterface { + #[\Override] public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('rekalogika_gotenberg_pdf'); diff --git a/packages/gotenberg-pdf-bundle/src/DependencyInjection/RekalogikaGotenbergPdfExtension.php b/packages/gotenberg-pdf-bundle/src/DependencyInjection/RekalogikaGotenbergPdfExtension.php index ed4b6cb..dfe8d93 100644 --- a/packages/gotenberg-pdf-bundle/src/DependencyInjection/RekalogikaGotenbergPdfExtension.php +++ b/packages/gotenberg-pdf-bundle/src/DependencyInjection/RekalogikaGotenbergPdfExtension.php @@ -21,6 +21,7 @@ class RekalogikaGotenbergPdfExtension extends Extension { + #[\Override] public function load(array $configs, ContainerBuilder $container): void { $loader = new PhpFileLoader( diff --git a/packages/gotenberg-pdf-bundle/src/GotenbergPdfGenerator.php b/packages/gotenberg-pdf-bundle/src/GotenbergPdfGenerator.php index 36f55b8..c65eb70 100644 --- a/packages/gotenberg-pdf-bundle/src/GotenbergPdfGenerator.php +++ b/packages/gotenberg-pdf-bundle/src/GotenbergPdfGenerator.php @@ -25,10 +25,11 @@ class GotenbergPdfGenerator implements PdfGeneratorInterface { public function __construct( - private ClientInterface $httpClient, - private string $gotenbergUrl = 'http://localhost:3000', + private readonly ClientInterface $httpClient, + private readonly string $gotenbergUrl = 'http://localhost:3000', ) {} + #[\Override] public function generatePdfFromHtml( string $htmlContent, PaperInterface $paper, @@ -63,8 +64,7 @@ public function generatePdfFromHtml( $request = $chromium->html(Stream::string('index.html', $htmlContent)); $response = $this->httpClient->sendRequest($request); - $stream = $response->getBody(); - return $stream; + return $response->getBody(); } } diff --git a/packages/gotenberg-pdf-bundle/src/RekalogikaGotenbergPdfBundle.php b/packages/gotenberg-pdf-bundle/src/RekalogikaGotenbergPdfBundle.php index 34c4bbd..0f042f1 100644 --- a/packages/gotenberg-pdf-bundle/src/RekalogikaGotenbergPdfBundle.php +++ b/packages/gotenberg-pdf-bundle/src/RekalogikaGotenbergPdfBundle.php @@ -17,6 +17,7 @@ class RekalogikaGotenbergPdfBundle extends Bundle { + #[\Override] public function getPath(): string { return \dirname(__DIR__); diff --git a/packages/print/src/PageLayout.php b/packages/print/src/PageLayout.php index cc65787..a39da5b 100644 --- a/packages/print/src/PageLayout.php +++ b/packages/print/src/PageLayout.php @@ -50,6 +50,7 @@ public static function inMm( $pageOrientation, ); } + return new self( $a / 1000, $b / 1000, @@ -77,33 +78,38 @@ public static function inInches( } private function __construct( - private float $topMargin, - private float $rightMargin, - private float $bottomMargin, - private float $leftMargin, - private PageOrientation $pageOrientation, + private readonly float $topMargin, + private readonly float $rightMargin, + private readonly float $bottomMargin, + private readonly float $leftMargin, + private readonly PageOrientation $pageOrientation, ) {} + #[\Override] public function getTopMargin(): float { return $this->topMargin; } + #[\Override] public function getRightMargin(): float { return $this->rightMargin; } + #[\Override] public function getBottomMargin(): float { return $this->bottomMargin; } + #[\Override] public function getLeftMargin(): float { return $this->leftMargin; } + #[\Override] public function getPageOrientation(): PageOrientation { return $this->pageOrientation; diff --git a/packages/print/src/Paper.php b/packages/print/src/Paper.php index c6b76a5..c4fc7eb 100644 --- a/packages/print/src/Paper.php +++ b/packages/print/src/Paper.php @@ -204,15 +204,17 @@ public static function tabloid(): self } private function __construct( - private float $width, - private float $height, + private readonly float $width, + private readonly float $height, ) {} + #[\Override] public function getWidth(): float { return $this->width; } + #[\Override] public function getHeight(): float { return $this->height; diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..81e7850 --- /dev/null +++ b/rector.php @@ -0,0 +1,58 @@ +withPhpVersion(PhpVersion::PHP_83) + ->withPaths([ + __DIR__ . '/packages', + __DIR__ . '/tests', + ]) + ->withPreparedSets( + deadCode: true, + codeQuality: true, + codingStyle: true, + typeDeclarations: true, + privatization: true, + instanceOf: true, + strictBooleans: true, + symfonyCodeQuality: true, + doctrineCodeQuality: true, + ) + ->withPhpSets(php81: true) + ->withRules([ + AddOverrideAttributeToOverriddenMethodsRector::class, + ]) + ->withSkip([ + // static analysis tools don't like this + RemoveNonExistingVarAnnotationRector::class, + + // static analysis tools don't like this + RemoveUnusedVariableAssignRector::class, + + // cognitive burden to many people + SimplifyIfElseToTernaryRector::class, + + // potential cognitive burden + FlipTypeControlToUseExclusiveTypeRector::class, + + // results in too long variables + CatchExceptionNameMatchingTypeRector::class, + + // makes code unreadable + DisallowedShortTernaryRuleFixerRector::class, + + // unsafe + SeparateMultiUseImportsRector::class, + ]);