Skip to content

Commit

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

* Fix rector
  • Loading branch information
jordisala1991 committed Jun 25, 2022
1 parent c36a71d commit 4ee80c0
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Expand Up @@ -7,6 +7,7 @@
tests export-ignore
docs export-ignore
Makefile export-ignore
rector.php export-ignore
phpunit.xml.dist export-ignore
phpstan.neon.dist export-ignore
phpstan-baseline.neon export-ignore
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/qa.yaml
Expand Up @@ -66,3 +66,25 @@ 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 (locked)
uses: ramsey/composer-install@v2

- name: Rector
run: vendor/bin/rector --no-progress-bar --dry-run
4 changes: 4 additions & 0 deletions Makefile
Expand Up @@ -100,3 +100,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
Expand Up @@ -43,7 +43,8 @@
"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",
"rector/rector": "^0.13",
"symfony/console": "^4.4 || ^5.4 || ^6.0",
"symfony/filesystem": "^4.4 || ^5.4 || ^6.0",
"symfony/finder": "^4.4 || ^5.4 || ^6.0",
Expand Down
35 changes: 35 additions & 0 deletions rector.php
@@ -0,0 +1,35 @@
<?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.
*/

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,
]);
};
20 changes: 10 additions & 10 deletions src/DependencyInjection/SonataSeoExtension.php
Expand Up @@ -18,7 +18,7 @@
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

Expand All @@ -36,7 +36,7 @@ public function load(array $configs, ContainerBuilder $container): void
/** @var array<string, mixed> $bundles */
$bundles = $container->getParameter('kernel.bundles');

$loader = new Loader\PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));

if (isset($bundles['SonataBlockBundle'], $bundles['KnpMenuBundle'])) {
$loader->load('blocks.php');
Expand Down Expand Up @@ -118,12 +118,12 @@ private function configureSitemap(array $config, ContainerBuilder $container): v
private function fixConfiguration(array $config): array
{
foreach ($config['sitemap']['doctrine_orm'] as $pos => $sitemap) {
$sitemap['group'] = $sitemap['group'] ?? false;
$sitemap['types'] = $sitemap['types'] ?? [];
$sitemap['connection'] = $sitemap['connection'] ?? 'doctrine.dbal.default_connection';
$sitemap['route'] = $sitemap['route'] ?? false;
$sitemap['parameters'] = $sitemap['parameters'] ?? false;
$sitemap['query'] = $sitemap['query'] ?? false;
$sitemap['group'] ??= false;
$sitemap['types'] ??= [];
$sitemap['connection'] ??= 'doctrine.dbal.default_connection';
$sitemap['route'] ??= false;
$sitemap['parameters'] ??= false;
$sitemap['query'] ??= false;

if (false === $sitemap['route']) {
throw new \RuntimeException('Route cannot be empty, please review the sonata_seo.sitemap configuration');
Expand All @@ -148,8 +148,8 @@ private function fixConfiguration(array $config): array
'id' => $sitemap,
];
} else {
$sitemap['group'] = $sitemap['group'] ?? false;
$sitemap['types'] = $sitemap['types'] ?? [];
$sitemap['group'] ??= false;
$sitemap['types'] ??= [];

if (!isset($sitemap['id'])) {
throw new \RuntimeException('Service id must to be defined, please review the sonata_seo.sitemap configuration');
Expand Down
Expand Up @@ -21,20 +21,11 @@

final class BreadcrumbBlockServicesCompilerPassTest extends TestCase
{
/**
* @var ContainerBuilder
*/
private $containerBuilder;
private ContainerBuilder $containerBuilder;

/**
* @var Definition
*/
private $listener;
private Definition $listener;

/**
* @var BreadcrumbBlockServicesCompilerPass
*/
private $compilerPass;
private BreadcrumbBlockServicesCompilerPass $compilerPass;

protected function setUp(): void
{
Expand Down Expand Up @@ -107,9 +98,7 @@ private function getCalledServices(): array
{
$methodCalls = $this->listener->getMethodCalls();

return array_map(static function ($call) {
return $call[1][0];
}, $methodCalls);
return array_map(static fn ($call) => $call[1][0], $methodCalls);
}

private function process(): void
Expand Down

0 comments on commit 4ee80c0

Please sign in to comment.