Skip to content

Commit

Permalink
build: rectorization (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
priyadi committed Sep 16, 2024
1 parent 5f00a3d commit 7bde8f4
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ vendor/
.phpunit.cache
tools
.php-cs-fixer.cache
var
var
rector.log
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
phive install php-cs-fixer

.PHONY: rector
rector:
$(PHP) vendor/bin/rector process > rector.log
make php-cs-fixer
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

class Configuration implements ConfigurationInterface
{
#[\Override]
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('rekalogika_gotenberg_pdf');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

class RekalogikaGotenbergPdfExtension extends Extension
{
#[\Override]
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new PhpFileLoader(
Expand Down
8 changes: 4 additions & 4 deletions packages/gotenberg-pdf-bundle/src/GotenbergPdfGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

class RekalogikaGotenbergPdfBundle extends Bundle
{
#[\Override]
public function getPath(): string
{
return \dirname(__DIR__);
Expand Down
16 changes: 11 additions & 5 deletions packages/print/src/PageLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public static function inMm(
$pageOrientation,
);
}

return new self(
$a / 1000,
$b / 1000,
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions packages/print/src/Paper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
58 changes: 58 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector;
use Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector;
use Rector\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector;
use Rector\CodingStyle\Rector\Use_\SeparateMultiUseImportsRector;
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\Assign\RemoveUnusedVariableAssignRector;
use Rector\DeadCode\Rector\Node\RemoveNonExistingVarAnnotationRector;
use Rector\Php83\Rector\ClassMethod\AddOverrideAttributeToOverriddenMethodsRector;
use Rector\Strict\Rector\Ternary\DisallowedShortTernaryRuleFixerRector;
use Rector\ValueObject\PhpVersion;

return RectorConfig::configure()
->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,
]);

0 comments on commit 7bde8f4

Please sign in to comment.