Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Rector configuration #1057

Merged
merged 2 commits into from
May 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
24 changes: 24 additions & 0 deletions .github/workflows/qa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,27 @@ 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
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"phpunit/phpunit": "^9.5.13",
"psalm/plugin-phpunit": "^0.16",
"psalm/plugin-symfony": "^3.0",
"rector/rector": "dev-main",
jordisala1991 marked this conversation as resolved.
Show resolved Hide resolved
"sonata-project/doctrine-extensions": "^1.10.1",
"symfony/browser-kit": "^4.4 || ^5.3 || ^6.0",
"symfony/debug": "^4.4 || ^5.3 || ^6.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 <[email protected]>
*
* 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,
]);
};
7 changes: 2 additions & 5 deletions src/Block/BlockContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@

final class BlockContext implements BlockContextInterface
{
/**
* @var BlockInterface
*/
private $block;
private BlockInterface $block;

/**
* @var array<string, mixed>
*/
private $settings;
private array $settings;

/**
* @param array<string, mixed> $settings
Expand Down
16 changes: 5 additions & 11 deletions src/Block/BlockContextManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,27 @@

final class BlockContextManager implements BlockContextManagerInterface
{
/**
* @var BlockLoaderInterface
*/
private $blockLoader;
private BlockLoaderInterface $blockLoader;

/**
* @var BlockServiceManagerInterface
*/
private $blockService;
private BlockServiceManagerInterface $blockService;

/**
* @var array<string, array<string, mixed>>
*/
private $settingsByType = [];
private array $settingsByType = [];

/**
* @var array<string, array<string, mixed>>
* @phpstan-var array<class-string, array<string, mixed>>
*/
private $settingsByClass = [];
private array $settingsByClass = [];

/**
* NEXT_MAJOR: remove.
*
* @var array{by_class: array<class-string, string>, by_type: array<string, string>}
*/
private $cacheBlocks = ['by_class' => [], 'by_type' => []];
private array $cacheBlocks = ['by_class' => [], 'by_type' => []];

/**
* @var LoggerInterface
Expand Down
2 changes: 1 addition & 1 deletion src/Block/BlockLoaderChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class BlockLoaderChain implements BlockLoaderInterface
/**
* @var BlockLoaderInterface[]
*/
private $loaders;
private array $loaders;

/**
* @param BlockLoaderInterface[] $loaders
Expand Down
19 changes: 4 additions & 15 deletions src/Block/BlockRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,17 @@
*/
final class BlockRenderer implements BlockRendererInterface
{
/**
* @var BlockServiceManagerInterface
*/
private $blockServiceManager;
private BlockServiceManagerInterface $blockServiceManager;

/**
* @var StrategyManagerInterface
*/
private $exceptionStrategyManager;
private StrategyManagerInterface $exceptionStrategyManager;

/**
* @var LoggerInterface|null
*/
private $logger;
private ?LoggerInterface $logger;

/**
* This property hold the last response available from the child or sibling block
* The cacheable attributes must be cascaded to the parent.
*
* @var Response|null
*/
private $lastResponse;
private ?Response $lastResponse = null;

/**
* @param BlockServiceManagerInterface $blockServiceManager Block service manager
Expand Down
16 changes: 5 additions & 11 deletions src/Block/BlockServiceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,21 @@ final class BlockServiceManager implements BlockServiceManagerInterface
/**
* @var array<string, string|BlockServiceInterface>
*/
private $services;
private array $services;

/**
* @var ContainerInterface
*/
private $container;
private ContainerInterface $container;

/**
* @var bool
*/
private $inValidate = false;
private bool $inValidate = false;

/**
* @var array<string, string[]>
*/
private $contexts;
private array $contexts;

/**
* @var string[]
*/
private $containerTypes;
private array $containerTypes;

/**
* NEXT_MAJOR: make $containerTypes not nullable.
Expand Down
2 changes: 1 addition & 1 deletion src/Block/Loader/ServiceLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class ServiceLoader implements BlockLoaderInterface
/**
* @var string[]
*/
private $types;
private array $types;

/**
* @param string[] $types
Expand Down
7 changes: 2 additions & 5 deletions src/Block/Service/AbstractBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
*/
abstract class AbstractBlockService implements BlockServiceInterface
{
/**
* @var Environment
*/
private $twig;
private Environment $twig;

public function __construct(Environment $twig)
{
Expand All @@ -41,7 +38,7 @@ public function __construct(Environment $twig)
*/
public function renderResponse(string $view, array $parameters = [], ?Response $response = null): Response
{
$response = $response ?? new Response();
$response ??= new Response();

$response->setContent($this->twig->render($view, $parameters));

Expand Down
10 changes: 2 additions & 8 deletions src/Block/Service/MenuBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,9 @@
*/
class MenuBlockService extends AbstractBlockService implements EditableBlockService
{
/**
* @var MenuProviderInterface
*/
private $menuProvider;
private MenuProviderInterface $menuProvider;

/**
* @var MenuRegistryInterface
*/
private $menuRegistry;
private MenuRegistryInterface $menuRegistry;

public function __construct(
Environment $twig,
Expand Down
5 changes: 1 addition & 4 deletions src/Cache/HttpCacheHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
*/
final class HttpCacheHandler implements HttpCacheHandlerInterface
{
/**
* @var int|null
*/
private $currentTtl;
private ?int $currentTtl = null;

public function alterResponse(Response $response): void
{
Expand Down
7 changes: 2 additions & 5 deletions src/Command/DebugBlocksCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ final class DebugBlocksCommand extends Command
{
protected static $defaultName = 'debug:sonata:block';

/**
* @var BlockServiceManagerInterface
*/
private $blockManager;
private BlockServiceManagerInterface $blockManager;

public function __construct(BlockServiceManagerInterface $blockManager)
{
Expand Down Expand Up @@ -68,7 +65,7 @@ public function execute(InputInterface $input, OutputInterface $output): int

try {
foreach ($resolver->resolve() as $key => $val) {
$output->writeln(sprintf(' %-30s%s', $key, json_encode($val)));
$output->writeln(sprintf(' %-30s%s', $key, json_encode($val, \JSON_THROW_ON_ERROR)));
}
} catch (MissingOptionsException $e) {
foreach ($resolver->getDefinedOptions() as $option) {
Expand Down
6 changes: 2 additions & 4 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@ final class Configuration implements ConfigurationInterface
/**
* @var array<string, string>
*/
private $defaultContainerTemplates;
private array $defaultContainerTemplates;

/**
* NEXT_MAJOR: remove this member.
*
* @var bool
*/
private $httpCacheDisabled = false;
private bool $httpCacheDisabled = false;

/**
* @param array<string, string> $defaultContainerTemplates
Expand Down
4 changes: 2 additions & 2 deletions src/Event/BlockEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ final class BlockEvent extends Event
/**
* @var array<string, mixed>
*/
private $settings;
private array $settings;

/**
* @var BlockInterface[]
*/
private $blocks = [];
private array $blocks = [];

/**
* @param array<string, mixed> $settings
Expand Down
5 changes: 1 addition & 4 deletions src/Exception/Filter/DebugOnlyFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
*/
final class DebugOnlyFilter implements FilterInterface
{
/**
* @var bool
*/
private $debug;
private bool $debug;

public function __construct(bool $debug)
{
Expand Down
5 changes: 1 addition & 4 deletions src/Exception/Filter/IgnoreClassFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
*/
final class IgnoreClassFilter implements FilterInterface
{
/**
* @var string
*/
private $class;
private string $class;

public function __construct(string $class)
{
Expand Down
Loading