Skip to content

Commit

Permalink
Build/rector (#126)
Browse files Browse the repository at this point in the history
* build: rector

* rector config

* apply php7.4 rule

* apply php80 rule

* apply php81 rule

* apply php82 rule

* type coverage level 3

* type coverage level 45

* dead code level 15

* dead code level 17

* exclude pageableinterface from RemoveUselessReturnTagRector

* deadcode level 20

* code fixes

* dead code 30

* dead code 41

* dead code level 44

* codequality level 3

* code quality level 7

* codequality level 17

* code quality 21

* codequality 22

* code quality 30

* code quality 35

* code quality 50

* code quality 57

* code quality 59

* code quality 70

* NewlineAfterStatementRector

* codingstyle

* strict booleans

* instanceof, privatization

* sets

* cleanup

* add ci

* remove ci
  • Loading branch information
priyadi authored Jul 17, 2024
1 parent d149bf3 commit abfa174
Show file tree
Hide file tree
Showing 72 changed files with 281 additions and 201 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ jobs:
- name: Validate monorepo
run: vendor/bin/monorepo-builder validate

# - name: Rector
# run: vendor/bin/rector process --no-progress-bar --no-diffs --dry-run --no-ansi

- name: Load fixtures
run: make fixtures

Expand Down
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
.vscode
.vscode
rector.log
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ phpunit:
lint:
$(PHP) tests/bin/console lint:container

.PHONY: rector
rector:
$(PHP) vendor/bin/rector process > rector.log
make php-cs-fixer

.PHONY: php-cs-fixer
php-cs-fixer: tools/php-cs-fixer
$(PHP) $< fix --config=.php-cs-fixer.dist.php --verbose --allow-risky=yes
Expand Down Expand Up @@ -74,4 +79,4 @@ sqlite:

.PHONY: dump
dump:
$(PHP) tests/bin/console server:dump
$(PHP) tests/bin/console server:dump
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"psalm/plugin-symfony": "^5.1",
"psr/log": "^2.0 || ^3.0",
"ramsey/uuid": "^4.7",
"rector/rector": "^1.2",
"rekalogika/doctrine-collections-decorator": "^2.3",
"symfony/asset": "^6.4 || ^7.0",
"symfony/asset-mapper": "^6.4 || ^7.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class ApiPageUrlGenerator implements PageUrlGeneratorInterface

public function __construct(
string $iri,
private string $pageParameterName,
private int $urlGenerationStrategy,
private readonly string $pageParameterName,
private readonly int $urlGenerationStrategy,
) {
$this->parsed = IriHelper::parseIri($iri, $this->pageParameterName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
* @template T of object
* @implements QueryResultCollectionExtensionInterface<T>
*/
final class RekapagerExtension implements QueryResultCollectionExtensionInterface
final readonly class RekapagerExtension implements QueryResultCollectionExtensionInterface
{
public function __construct(
private readonly PagerFactory $pagerFactory,
private readonly Pagination $pagination,
private PagerFactory $pagerFactory,
private Pagination $pagination,
) {
}

Expand Down Expand Up @@ -91,8 +91,7 @@ public function getResult(
array $context = []
): iterable {
$pageable = new KeysetPageable(new QueryBuilderAdapter($queryBuilder));
$pager = $this->pagerFactory->createPager($pageable, $operation, $context);

return $pager;
return $this->pagerFactory->createPager($pageable, $operation, $context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@
class RekapagerOpenApiFactoryDecorator implements OpenApiFactoryInterface
{
public function __construct(
private OpenApiFactoryInterface $decorated,
private readonly OpenApiFactoryInterface $decorated,
) {
}

/**
* @param array<array-key,mixed> $context
* @return OpenApi
*/
public function __invoke(array $context = []): OpenApi
{
Expand Down
3 changes: 2 additions & 1 deletion packages/rekapager-api-platform/src/Util/IriHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public static function createIri(array $parts, array $parameters, ?string $pageP
} else {
$scheme = 'http';
}
$url .= UrlGeneratorInterface::NET_PATH === $urlGenerationStrategy ? '//' : "$scheme://";

$url .= UrlGeneratorInterface::NET_PATH === $urlGenerationStrategy ? '//' : $scheme . '://';

if (isset($parts['user'])) {
$url .= $parts['user'];
Expand Down
8 changes: 4 additions & 4 deletions packages/rekapager-bundle/src/PagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ public function createPager(

try {
/** @psalm-suppress NoValue */
foreach ($pager->getCurrentPage() as $i);
foreach ($pager->getCurrentPage() as $i) {
// noop
}
} catch (ContractsOutOfBoundsException $e) {
throw new OutOfBoundsException($e, $pager, $options);
}
Expand All @@ -142,9 +144,7 @@ private function getPageIdentifier(
return null;
}

$pageIdentifier = $this->pageIdentifierEncoderResolver
return $this->pageIdentifierEncoderResolver
->decode($pageable, $pageIdentifier);

return $pageIdentifier;
}
}
1 change: 0 additions & 1 deletion packages/rekapager-bundle/src/Twig/RekapagerRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public function __construct(
/**
* @param PagerInterface<array-key,mixed> $pager
* @param int<0,max>|null $proximity
* @return string
*/
public function renderPager(
PagerInterface $pager,
Expand Down
1 change: 0 additions & 1 deletion packages/rekapager-core/src/Batch/BatchProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ final class BatchProcess

/**
* @param PageableInterface<TKey,T> $pageable
* @param PageIdentifierEncoderResolverInterface $pageableIdentifierResolver
* @param BatchProcessorInterface<TKey,T> $batchProcessor
*/
public function __construct(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ abstract class BatchProcessorDecorator implements BatchProcessorInterface
/**
* @param BatchProcessorInterface<TKey,T> $decorated
*/
public function __construct(private BatchProcessorInterface $decorated)
public function __construct(private readonly BatchProcessorInterface $decorated)
{
}

Expand Down
4 changes: 2 additions & 2 deletions packages/rekapager-core/src/Batch/Event/AfterPageEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
* @template TKey of array-key
* @template T
*/
final class AfterPageEvent
final readonly class AfterPageEvent
{
/**
* @param BeforePageEvent<TKey,T> $beforePageEvent
*/
public function __construct(
private readonly BeforePageEvent $beforePageEvent,
private BeforePageEvent $beforePageEvent,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions packages/rekapager-core/src/Batch/Event/AfterProcessEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
* @template TKey of array-key
* @template T
*/
final class AfterProcessEvent
final readonly class AfterProcessEvent
{
/**
* @param PageableInterface<TKey,T> $pageable
*/
public function __construct(
private readonly PageableInterface $pageable,
private PageableInterface $pageable,
) {
}

Expand Down
7 changes: 3 additions & 4 deletions packages/rekapager-core/src/Batch/Event/BeforePageEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@
* @template TKey of array-key
* @template T
*/
final class BeforePageEvent
final readonly class BeforePageEvent
{
/**
* @param PageInterface<TKey,T> $page
* @param string $encodedPageIdentifier
*/
public function __construct(
private readonly PageInterface $page,
private readonly string $encodedPageIdentifier,
private PageInterface $page,
private string $encodedPageIdentifier,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
* @template TKey of array-key
* @template T
*/
final class BeforeProcessEvent
final readonly class BeforeProcessEvent
{
/**
* @param PageableInterface<TKey,T> $pageable
*/
public function __construct(
private readonly PageableInterface $pageable,
private readonly ?string $startPageIdentifier,
private PageableInterface $pageable,
private ?string $startPageIdentifier,
) {
}

Expand Down
6 changes: 3 additions & 3 deletions packages/rekapager-core/src/Batch/Event/InterruptEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
* @template TKey of array-key
* @template T
*/
final class InterruptEvent
final readonly class InterruptEvent
{
/**
* @param PageableInterface<TKey,T> $pageable
*/
public function __construct(
private readonly PageableInterface $pageable,
private readonly ?string $nextPageIdentifier,
private PageableInterface $pageable,
private ?string $nextPageIdentifier,
) {
}

Expand Down
6 changes: 3 additions & 3 deletions packages/rekapager-core/src/Batch/Event/ItemEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
* @template TKey of array-key
* @template T
*/
final class ItemEvent
final readonly class ItemEvent
{
/**
* @param TKey $key
* @param T $item
*/
public function __construct(
private readonly int|string $key,
private readonly mixed $item,
private int|string $key,
private mixed $item,
) {
}

Expand Down
6 changes: 3 additions & 3 deletions packages/rekapager-core/src/Batch/Event/TimeLimitEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
* @template TKey of array-key
* @template T
*/
final class TimeLimitEvent
final readonly class TimeLimitEvent
{
/**
* @param PageableInterface<TKey,T> $pageable
*/
public function __construct(
private readonly PageableInterface $pageable,
private readonly ?string $nextPageIdentifier,
private PageableInterface $pageable,
private ?string $nextPageIdentifier,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
use Rekalogika\Rekapager\Batch\BatchProcessorInterface;
use Rekalogika\Rekapager\Contracts\PageIdentifierEncoderResolverInterface;

final class DefaultBatchProcessFactory implements BatchProcessFactoryInterface
final readonly class DefaultBatchProcessFactory implements BatchProcessFactoryInterface
{
public function __construct(
private readonly PageIdentifierEncoderResolverInterface $pageableIdentifierResolver,
private PageIdentifierEncoderResolverInterface $pageableIdentifierResolver,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class PageIdentifierEncoderResolver implements PageIdentifierEncoderResolverInterface
{
public function __construct(
private PageIdentifierEncoderLocatorInterface $locator
private readonly PageIdentifierEncoderLocatorInterface $locator
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
* @implements \IteratorAggregate<TKey,T>
* @internal
*/
final class NullPageDecorator implements NullPageInterface, \IteratorAggregate
final readonly class NullPageDecorator implements NullPageInterface, \IteratorAggregate
{
/**
* @param PageInterface<TKey,T> $page
*/
public function __construct(
private readonly PageInterface $page,
private PageInterface $page,
) {
}

Expand All @@ -47,7 +47,7 @@ public function getPageNumber(): ?int

public function withPageNumber(?int $pageNumber): static
{
return new static($this->page->withPageNumber($pageNumber));
return new self($this->page->withPageNumber($pageNumber));
}

public function getPageable(): PageableInterface
Expand Down
2 changes: 1 addition & 1 deletion packages/rekapager-core/src/Pager/Internal/PagerItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*
* @internal
*/
final class PagerItem implements PagerItemInterface, \IteratorAggregate
final readonly class PagerItem implements PagerItemInterface, \IteratorAggregate
{
private int|null|NullPageNumber $pageNumber;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ interface PagerUrlGeneratorInterface
* @template TKey of array-key
* @template T
* @param PageInterface<TKey,T> $page
* @return string|null
*/
public function generateUrl(PageInterface $page): ?string;
}
Loading

0 comments on commit abfa174

Please sign in to comment.