Skip to content

Commit

Permalink
feat(rector): Add rector checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ragusa87 committed May 25, 2024
1 parent 9fd3f20 commit c1b9a6e
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 29 deletions.
10 changes: 10 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,22 @@
"Composer\\Config::disableProcessTimeout",
"env XDEBUG_MODE=off ./vendor/bin/php-cs-fixer fix ./src -vv --verbose --config=.php-cs-fixer.dist.php"
],
"test-rector": [
"Composer\\Config::disableProcessTimeout",
"env XDEBUG_MODE=off ./vendor/bin/rector --dry-run"
],
"rector": [
"Composer\\Config::disableProcessTimeout",
"env XDEBUG_MODE=off ./vendor/bin/rector"
],
"test-phpunit": [
"Composer\\Config::disableProcessTimeout",
"env XDEBUG_MODE=off ./vendor/bin/phpunit --colors=always"
],
"test": [
"@test-phpcs",
"@test-phpstan",
"@test-rector",
"mkdir -p data",
"rm -f data/database.sqlite",
"touch data/database.sqlite",
Expand Down Expand Up @@ -158,6 +167,7 @@
"phpstan/phpstan-strict-rules": "^1.0",
"phpstan/phpstan-symfony": "^1.2",
"phpunit/phpunit": "^9.5",
"rector/rector": "^1.1",
"roave/security-advisories": "dev-latest",
"symfony/browser-kit": "^6.2",
"symfony/css-selector": "^6.2",
Expand Down
61 changes: 60 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/config',
__DIR__ . '/public',
__DIR__ . '/src',
__DIR__ . '/tests',
])
->withRules([
AddVoidReturnTypeWhereNoReturnRector::class,
])
->withImportNames(true, true, false, true)
->withSkip([
'**/config/bundles.php',
]);
1 change: 0 additions & 1 deletion src/Command/BooksExtractCoverCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Command;

use App\Entity\Book;
use App\Repository\BookRepository;
use App\Service\BookFileSystemManager;
use Doctrine\ORM\EntityManagerInterface;
Expand Down
5 changes: 3 additions & 2 deletions src/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController as BaseAbstractController;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Response;
use Twig\Environment;

abstract class AbstractController extends BaseAbstractController
{
Expand All @@ -19,7 +20,7 @@ private function prefixView(string $view): string
return $view;
}
$twig = $this->container->get('twig');
if (!$twig instanceof \Twig\Environment) {
if (!$twig instanceof Environment) {
return $view;
}
if ($twig->getLoader()->exists($theme.'/'.$view)) {
Expand All @@ -44,7 +45,7 @@ private function doRenderView(string $view, ?string $block, array $parameters, s
}

$twig = $this->container->get('twig');
if (!$twig instanceof \Twig\Environment) {
if (!$twig instanceof Environment) {
return $view;
}

Expand Down
40 changes: 22 additions & 18 deletions src/Form/BookFilterType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
use App\Entity\User;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\SearchType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Routing\RouterInterface;
Expand All @@ -23,7 +27,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->setMethod('GET');

$builder->add('title', Type\SearchType::class, [
$builder->add('title', SearchType::class, [
'required' => false,
'target_callback' => function (QueryBuilder $qb, ?string $searchValue): void {
if ($searchValue !== null) {
Expand All @@ -33,7 +37,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
},
]);

$builder->add('serieIndexGTE', Type\SearchType::class, [
$builder->add('serieIndexGTE', SearchType::class, [
'required' => false,
'mapped' => false,
'label' => 'Index >=',
Expand All @@ -45,7 +49,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
},
]);

$builder->add('serieIndexLTE', Type\SearchType::class, [
$builder->add('serieIndexLTE', SearchType::class, [
'required' => false,
'mapped' => false,
'label' => 'Index <=',
Expand All @@ -57,7 +61,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
},
]);

$builder->add('authors', Type\TextType::class, [
$builder->add('authors', TextType::class, [
'autocomplete' => true,
'tom_select_options' => [
'create' => false,
Expand All @@ -82,7 +86,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
},
]);

$builder->add('authorsNot', Type\TextType::class, [
$builder->add('authorsNot', TextType::class, [
'autocomplete' => true,
'tom_select_options' => [
'create' => false,
Expand All @@ -108,7 +112,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
},
]);

$builder->add('tags', Type\TextType::class, [
$builder->add('tags', TextType::class, [
'autocomplete' => true,
'tom_select_options' => [
'create' => false,
Expand Down Expand Up @@ -137,7 +141,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
},
]);

$builder->add('serie', Type\TextType::class, [
$builder->add('serie', TextType::class, [
'autocomplete' => true,
'tom_select_options' => [
'create' => false,
Expand Down Expand Up @@ -166,7 +170,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
},
]);

$builder->add('publisher', Type\TextType::class, [
$builder->add('publisher', TextType::class, [
'autocomplete' => true,
'tom_select_options' => [
'create' => false,
Expand Down Expand Up @@ -195,7 +199,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
},
]);

$builder->add('read', Type\ChoiceType::class, [
$builder->add('read', ChoiceType::class, [
'choices' => [
'Any' => '',
'Read' => 'read',
Expand All @@ -215,7 +219,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
},
]);

$builder->add('extension', Type\ChoiceType::class, [
$builder->add('extension', ChoiceType::class, [
'choices' => [
'Any' => '',
'epub' => 'epub',
Expand All @@ -233,7 +237,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
},
]);

$builder->add('age', Type\ChoiceType::class, [
$builder->add('age', ChoiceType::class, [
'choices' => User::AGE_CATEGORIES + ['Not set' => 'null'],
'required' => false,
'mapped' => false,
Expand All @@ -249,7 +253,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
},
]);

$builder->add('favorite', Type\ChoiceType::class, [
$builder->add('favorite', ChoiceType::class, [
'choices' => [
'Any' => '',
'Favorite' => 'favorite',
Expand All @@ -269,7 +273,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
},
]);

$builder->add('verified', Type\ChoiceType::class, [
$builder->add('verified', ChoiceType::class, [
'choices' => [
'Any' => '',
'Verified' => 'verified',
Expand All @@ -289,7 +293,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
},
]);

$builder->add('picture', Type\ChoiceType::class, [
$builder->add('picture', ChoiceType::class, [
'choices' => [
'Any' => '',
'Has picture' => 'with',
Expand All @@ -309,7 +313,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
},
]);

$builder->add('orderBy', Type\ChoiceType::class, [
$builder->add('orderBy', ChoiceType::class, [
'choices' => [
'created (ASC)' => 'created-asc',
'created (DESC)' => 'created-desc',
Expand Down Expand Up @@ -346,14 +350,14 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
},
]);

$builder->add('displayMode', Type\HiddenType::class, [
$builder->add('displayMode', HiddenType::class, [
'data' => 'list',
'mapped' => false,
'target_callback' => function (QueryBuilder $qb, ?string $orderByValue): void {
},
]);

$builder->add('submit', Type\SubmitType::class, [
$builder->add('submit', SubmitType::class, [
'label' => 'Filter',
'attr' => [
'class' => 'btn btn-primary',
Expand Down
5 changes: 3 additions & 2 deletions src/Repository/ShelfRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Entity\Kobo;
use App\Entity\Shelf;
use App\Kobo\SyncToken;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\Persistence\ManagerRegistry;
Expand Down Expand Up @@ -83,10 +84,10 @@ public function findByKoboAndName(Kobo $kobo, mixed $name): ?Shelf

/**
* @param Kobo $kobo
* @param \App\Kobo\SyncToken $syncToken
* @param SyncToken $syncToken
* @return array<Shelf>
*/
public function getShelvesToSync(Kobo $kobo, \App\Kobo\SyncToken $syncToken): array
public function getShelvesToSync(Kobo $kobo, SyncToken $syncToken): array
{
$qb = $this->createQueryBuilder('shelf')
->select('shelf')
Expand Down
1 change: 0 additions & 1 deletion tests/Contraints/JSONIsValidSyncResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Tests\Contraints;

use PHPUnit\Framework\Constraint\ArrayHasKey;
use PHPUnit\Framework\Constraint\Constraint;
use PHPUnit\Framework\Constraint\IsIdentical;

Expand Down
2 changes: 0 additions & 2 deletions tests/Controller/AbstractKoboControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
use App\DataFixtures\BookFixture;
use App\Entity\Book;
use App\Entity\Kobo;
use App\Entity\User;
use App\Service\BookFileSystemManager;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Bundle\SecurityBundle\Security;
Expand Down
1 change: 0 additions & 1 deletion tests/Controller/KoboTagControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\DataFixtures\ShelfFixture;
use App\Entity\Shelf;
use Doctrine\ORM\EntityManager;

class KoboTagControllerTest extends AbstractKoboControllerTest
{
Expand Down
1 change: 0 additions & 1 deletion tests/Kobo/Request/ReadingStateDeserializeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Tests\Kobo\Request;

use App\Kobo\Request\Bookmark;
use App\Kobo\Request\ReadingState;
use App\Kobo\Request\ReadingStates;
use App\Kobo\Request\ReadingStateStatusInfo;
use JMS\Serializer\SerializerInterface;
Expand Down

0 comments on commit c1b9a6e

Please sign in to comment.