Skip to content

Commit

Permalink
Add rector (#1546)
Browse files Browse the repository at this point in the history
* Add rector

* Fix rector
  • Loading branch information
jordisala1991 authored Jun 25, 2022
1 parent a94a63b commit 6ec6c42
Show file tree
Hide file tree
Showing 21 changed files with 112 additions and 28 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ docs export-ignore
Makefile export-ignore
phpunit.xml.dist export-ignore
bin/console export-ignore
rector.php export-ignore
phpstan.neon.dist export-ignore
phpstan-baseline.neon export-ignore
phpstan-console-application.php export-ignore
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/qa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,28 @@ jobs:

- name: Psalm
run: vendor/bin/psalm --no-progress --show-info=false --stats --output-format=github --threads=$(nproc) --shepherd --php-version=8.1

rector:
name: Rector

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
coverage: none
tools: composer:v2

- name: Install Composer dependencies (highest)
uses: ramsey/composer-install@v2
with:
dependency-versions: highest
composer-options: --prefer-dist --prefer-stable

- name: Rector
run: vendor/bin/rector --no-progress-bar --dry-run
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,7 @@ phpstan:
psalm:
vendor/bin/psalm --php-version=8.1
.PHONY: psalm

rector:
vendor/bin/rector
.PHONY: rector
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@
"phpstan/phpstan-strict-rules": "^1.0",
"phpstan/phpstan-symfony": "^1.0",
"phpunit/phpunit": "^9.5",
"psalm/plugin-phpunit": "^0.16",
"psalm/plugin-phpunit": "^0.17",
"psalm/plugin-symfony": "^3.0",
"rector/rector": "^0.13",
"sonata-project/admin-bundle": "^4.9",
"sonata-project/block-bundle": "^4.11",
"sonata-project/doctrine-orm-admin-bundle": "^4.0",
Expand Down
41 changes: 41 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

/*
* DO NOT EDIT THIS FILE!
*
* It's auto-generated by sonata-project/dev-kit package.
*/

use Rector\Config\RectorConfig;
use Rector\Php70\Rector\FunctionLike\ExceptionHandlerTypehintRector;
use Rector\Php71\Rector\FuncCall\CountOnNullRector;
use Rector\Set\ValueObject\LevelSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__.'/src',
__DIR__.'/tests',
]);

$rectorConfig->sets([
LevelSetList::UP_TO_PHP_74,
]);

$rectorConfig->importNames();
$rectorConfig->disableImportShortClasses();
$rectorConfig->skip([
CountOnNullRector::class,
ExceptionHandlerTypehintRector::class,
]);
};
10 changes: 6 additions & 4 deletions src/Admin/Model/UserAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Show\ShowMapper;
use Sonata\UserBundle\Form\Type\RolesMatrixType;
use Sonata\UserBundle\Model\UserInterface;
use Sonata\UserBundle\Model\UserManagerInterface;
use Symfony\Component\Form\Extension\Core\Type\TextType;

/**
* @phpstan-extends AbstractAdmin<\Sonata\UserBundle\Model\UserInterface>
* @phpstan-extends AbstractAdmin<UserInterface>
*/
class UserAdmin extends AbstractAdmin
{
Expand Down Expand Up @@ -108,8 +109,9 @@ protected function configureFormFields(FormMapper $form): void
protected function configureExportFields(): array
{
// Avoid sensitive properties to be exported.
return array_filter(parent::configureExportFields(), static function (string $v): bool {
return !\in_array($v, ['password', 'salt'], true);
});
return array_filter(
parent::configureExportFields(),
static fn (string $v): bool => !\in_array($v, ['password', 'salt'], true)
);
}
}
5 changes: 3 additions & 2 deletions src/Form/Type/ResettingFormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Sonata\UserBundle\Form\Type;

use Sonata\UserBundle\Model\UserInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
Expand All @@ -22,12 +23,12 @@
final class ResettingFormType extends AbstractType
{
/**
* @phpstan-var class-string<\Sonata\UserBundle\Model\UserInterface>
* @phpstan-var class-string<UserInterface>
*/
private string $class;

/**
* @phpstan-param class-string<\Sonata\UserBundle\Model\UserInterface> $class
* @phpstan-param class-string<UserInterface> $class
*/
public function __construct(string $class)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Model/UserManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Sonata\Doctrine\Model\ManagerInterface;

/**
* @phpstan-extends ManagerInterface<\Sonata\UserBundle\Model\UserInterface>
* @phpstan-extends ManagerInterface<UserInterface>
*/
interface UserManagerInterface extends ManagerInterface
{
Expand Down
12 changes: 6 additions & 6 deletions tests/Action/LoginActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ public function testUnauthenticated(string $lastUsername, ?AuthenticationExcepti
];
$session
->method('get')
->willReturnCallback(static function (string $key) use ($sessionParameters) {
return $sessionParameters[$key] ?? null;
});
->willReturnCallback(
static fn (string $key) => $sessionParameters[$key] ?? null
);
$session
->method('has')
->willReturnCallback(static function (string $key) use ($sessionParameters): bool {
return isset($sessionParameters[$key]);
});
->willReturnCallback(
static fn (string $key): bool => isset($sessionParameters[$key])
);
$request = new Request();
$request->setSession($session);

Expand Down
4 changes: 1 addition & 3 deletions tests/Action/ResetActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,7 @@ public function testPostedReset(): void

$this->translator
->method('trans')
->willReturnCallback(static function (string $message): string {
return $message;
});
->willReturnCallback(static fn (string $message): string => $message);

$this->userManager
->method('findUserByConfirmationToken')
Expand Down
3 changes: 2 additions & 1 deletion tests/Functional/Action/LoginActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Sonata\UserBundle\Tests\App\AppKernel;
use Sonata\UserBundle\Tests\App\Entity\User;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpKernel\KernelInterface;

final class LoginActionTest extends WebTestCase
{
Expand Down Expand Up @@ -65,7 +66,7 @@ public function testItSubmitsLoginFormWithDisabledUser(): void
}

/**
* @return class-string<\Symfony\Component\HttpKernel\KernelInterface>
* @return class-string<KernelInterface>
*/
protected static function getKernelClass(): string
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Functional/Action/LogoutActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Sonata\UserBundle\Tests\App\AppKernel;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpKernel\KernelInterface;

final class LogoutActionTest extends WebTestCase
{
Expand All @@ -28,7 +29,7 @@ public function testItLogouts(): void
}

/**
* @return class-string<\Symfony\Component\HttpKernel\KernelInterface>
* @return class-string<KernelInterface>
*/
protected static function getKernelClass(): string
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Functional/Action/RequestActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Sonata\UserBundle\Tests\App\AppKernel;
use Sonata\UserBundle\Tests\App\Entity\User;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpKernel\KernelInterface;

final class RequestActionTest extends WebTestCase
{
Expand Down Expand Up @@ -89,7 +90,7 @@ public function itSubmitsResetPasswordRequest(): void
}

/**
* @return class-string<\Symfony\Component\HttpKernel\KernelInterface>
* @return class-string<KernelInterface>
*/
protected static function getKernelClass(): string
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Functional/Action/ResetActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Sonata\UserBundle\Tests\App\AppKernel;
use Sonata\UserBundle\Tests\App\Entity\User;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpKernel\KernelInterface;

final class ResetActionTest extends WebTestCase
{
Expand Down Expand Up @@ -84,7 +85,7 @@ public function testItResetsPassword(): void
}

/**
* @return class-string<\Symfony\Component\HttpKernel\KernelInterface>
* @return class-string<KernelInterface>
*/
protected static function getKernelClass(): string
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Functional/Admin/UserAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Sonata\UserBundle\Tests\App\AppKernel;
use Sonata\UserBundle\Tests\App\Entity\User;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpKernel\KernelInterface;

final class UserAdminTest extends WebTestCase
{
Expand Down Expand Up @@ -113,7 +114,7 @@ public function testUpdatePassword(): void
}

/**
* @return class-string<\Symfony\Component\HttpKernel\KernelInterface>
* @return class-string<KernelInterface>
*/
protected static function getKernelClass(): string
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Functional/Command/ActivateUserCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\HttpKernel\KernelInterface;

class ActivateUserCommandTest extends KernelTestCase
{
Expand Down Expand Up @@ -65,7 +66,7 @@ public function testActivatesUser(): void
}

/**
* @return class-string<\Symfony\Component\HttpKernel\KernelInterface>
* @return class-string<KernelInterface>
*/
protected static function getKernelClass(): string
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Functional/Command/ChangePasswordCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\HttpKernel\KernelInterface;

class ChangePasswordCommandTest extends KernelTestCase
{
Expand Down Expand Up @@ -62,7 +63,7 @@ public function testChangesUserPassword(): void
}

/**
* @return class-string<\Symfony\Component\HttpKernel\KernelInterface>
* @return class-string<KernelInterface>
*/
protected static function getKernelClass(): string
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Functional/Command/CreateUserCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\HttpKernel\KernelInterface;

class CreateUserCommandTest extends KernelTestCase
{
Expand Down Expand Up @@ -79,7 +80,7 @@ public function testCreatesAnSuperAdminUser(): void
}

/**
* @return class-string<\Symfony\Component\HttpKernel\KernelInterface>
* @return class-string<KernelInterface>
*/
protected static function getKernelClass(): string
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Functional/Command/DeactivateUserCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\HttpKernel\KernelInterface;

class DeactivateUserCommandTest extends KernelTestCase
{
Expand Down Expand Up @@ -65,7 +66,7 @@ public function testDeactivatesUser(): void
}

/**
* @return class-string<\Symfony\Component\HttpKernel\KernelInterface>
* @return class-string<KernelInterface>
*/
protected static function getKernelClass(): string
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Functional/Command/DemoteUserCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\HttpKernel\KernelInterface;

class DemoteUserCommandTest extends KernelTestCase
{
Expand Down Expand Up @@ -114,7 +115,7 @@ public function testBecomeNormalUser(): void
}

/**
* @return class-string<\Symfony\Component\HttpKernel\KernelInterface>
* @return class-string<KernelInterface>
*/
protected static function getKernelClass(): string
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Functional/Command/PromoteUserCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\HttpKernel\KernelInterface;

class PromoteUserCommandTest extends KernelTestCase
{
Expand Down Expand Up @@ -114,7 +115,7 @@ public function testBecomeSuperAdmin(): void
}

/**
* @return class-string<\Symfony\Component\HttpKernel\KernelInterface>
* @return class-string<KernelInterface>
*/
protected static function getKernelClass(): string
{
Expand Down

0 comments on commit 6ec6c42

Please sign in to comment.