Skip to content

Commit

Permalink
Add rector
Browse files Browse the repository at this point in the history
  • Loading branch information
javihgil committed Apr 25, 2024
1 parent 94e87ef commit fa01778
Show file tree
Hide file tree
Showing 67 changed files with 265 additions and 134 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'@Symfony' => true,
'full_opening_tag' => false,
'phpdoc_separation' => false,
'global_namespace_import' => ['import_classes' => true]
])
->setFinder($finder)
;
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"google/cloud-storage": "^1.30",
"phpstan/phpstan": "^1.10.49",
"phpunit/phpunit": "^11.0",
"rector/rector": "^1.0",
"sensio/framework-extra-bundle": "^5.4|^6.2",
"softspring/user-bundle": "^5.2",
"symfony/css-selector": "^5.4|^6.0|^7.0",
Expand Down
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\Doctrine\Set\DoctrineSetList;
use Rector\Symfony\Set\SymfonySetList;
use Rector\Symfony\Set\SensiolabsSetList;

return RectorConfig::configure()
->withImportNames(removeUnusedImports: true)
->withPaths([
__DIR__ . '/src',
])
->withSets([
DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES,
SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES,
// SensiolabsSetList::ANNOTATIONS_TO_ATTRIBUTES,
// SymfonySetList::SYMFONY_62,
// SymfonySetList::SYMFONY_CODE_QUALITY,
// SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION,
]);
5 changes: 3 additions & 2 deletions src/Admin/Menu/AbstractContentMenuProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Softspring\CmsBundle\Admin\Menu;

use RuntimeException;
use Softspring\CmsBundle\Config\CmsConfig;
use Softspring\CmsBundle\Config\Exception\InvalidContentException;
use Softspring\CmsBundle\Manager\ContentManagerInterface;
Expand Down Expand Up @@ -34,12 +35,12 @@ protected function getMenuItem(string $id, string $current, ContentInterface $co

/**
* @throws InvalidContentException
* @throws \RuntimeException
* @throws RuntimeException
*/
protected function getContent(array $context): array
{
if (!isset($context['content']) || !$context['content'] instanceof ContentInterface) {
throw new \RuntimeException('ContentMenuProvider requires a content instance in context');
throw new RuntimeException('ContentMenuProvider requires a content instance in context');
}

$content = $context['content'];
Expand Down
4 changes: 3 additions & 1 deletion src/Config/Exception/DisabledModuleException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Softspring\CmsBundle\Config\Exception;

class DisabledModuleException extends \Exception
use Exception;

class DisabledModuleException extends Exception
{
public function __construct(string $module)
{
Expand Down
4 changes: 3 additions & 1 deletion src/Config/Exception/InvalidBlockException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Softspring\CmsBundle\Config\Exception;

class InvalidBlockException extends \Exception
use Exception;

class InvalidBlockException extends Exception
{
public function __construct(string $block, array $blocksConfig)
{
Expand Down
4 changes: 3 additions & 1 deletion src/Config/Exception/InvalidContentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Softspring\CmsBundle\Config\Exception;

class InvalidContentException extends \Exception
use Exception;

class InvalidContentException extends Exception
{
public function __construct(protected string $contentType, array $contentsConfig)
{
Expand Down
4 changes: 3 additions & 1 deletion src/Config/Exception/InvalidLayoutException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Softspring\CmsBundle\Config\Exception;

class InvalidLayoutException extends \Exception
use Exception;

class InvalidLayoutException extends Exception
{
public function __construct(string $layout, array $layoutsConfig)
{
Expand Down
4 changes: 3 additions & 1 deletion src/Config/Exception/InvalidMenuException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Softspring\CmsBundle\Config\Exception;

class InvalidMenuException extends \Exception
use Exception;

class InvalidMenuException extends Exception
{
public function __construct(string $menu, array $menusConfig)
{
Expand Down
4 changes: 3 additions & 1 deletion src/Config/Exception/InvalidModuleException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Softspring\CmsBundle\Config\Exception;

class InvalidModuleException extends \Exception
use Exception;

class InvalidModuleException extends Exception
{
public function __construct(string $module, array $modulesConfig)
{
Expand Down
4 changes: 3 additions & 1 deletion src/Config/Exception/InvalidSiteException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Softspring\CmsBundle\Config\Exception;

class InvalidSiteException extends \Exception
use Exception;

class InvalidSiteException extends Exception
{
public function __construct(string $site, array $sitesConfig)
{
Expand Down
4 changes: 3 additions & 1 deletion src/Config/Exception/MissingContentTypeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Softspring\CmsBundle\Config\Exception;

class MissingContentTypeException extends \Exception
use Exception;

class MissingContentTypeException extends Exception
{
}
4 changes: 3 additions & 1 deletion src/Config/Exception/MissingLayoutsException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Softspring\CmsBundle\Config\Exception;

class MissingLayoutsException extends \Exception
use Exception;

class MissingLayoutsException extends Exception
{
}
7 changes: 4 additions & 3 deletions src/Controller/BlockController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Softspring\CmsBundle\Controller;

use Doctrine\ORM\EntityManagerInterface;
use Exception;
use Psr\Log\LoggerInterface;
use Softspring\CmsBundle\Config\CmsConfig;
use Softspring\CmsBundle\Manager\BlockManagerInterface;
Expand Down Expand Up @@ -62,7 +63,7 @@ public function renderByType(string $type, Request $request): Response
}

return $response;
} catch (\Exception $e) {
} catch (Exception $e) {
return $this->renderBlockException("An exception has occurred rendering a block by type '$type'", $e);
}
}
Expand Down Expand Up @@ -97,12 +98,12 @@ public function renderById(string $id, Request $request): Response
}

return $response;
} catch (\Exception $e) {
} catch (Exception $e) {
return $this->renderBlockException("An exception has occurred rendering a block with id '$id'", $e);
}
}

protected function renderBlockException(string $message, \Exception $exception): Response
protected function renderBlockException(string $message, Exception $exception): Response
{
$this->cmsLogger && $this->cmsLogger->critical(sprintf('%s: %s', $message, $exception->getMessage()));

Expand Down
3 changes: 2 additions & 1 deletion src/Controller/MenuController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Softspring\CmsBundle\Controller;

use Exception;
use Psr\Log\LoggerInterface;
use Softspring\CmsBundle\Config\CmsConfig;
use Softspring\CmsBundle\Manager\MenuManagerInterface;
Expand Down Expand Up @@ -48,7 +49,7 @@ public function renderByType(string $type, Request $request): Response
}

return $response;
} catch (\Exception $e) {
} catch (Exception $e) {
$this->cmsLogger && $this->cmsLogger->critical(sprintf('Error rendering menu %s: %s', $type, $e->getMessage()));

return new Response('<!-- error rendering menu, see logs -->');
Expand Down
5 changes: 3 additions & 2 deletions src/Data/DataExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Softspring\CmsBundle\Data;

use Exception;
use Google\Cloud\Storage\StorageClient;
use Softspring\CmsBundle\Data\EntityTransformer\ContentEntityTransformerInterface;
use Softspring\CmsBundle\Data\EntityTransformer\EntityTransformerInterface;
Expand Down Expand Up @@ -101,12 +102,12 @@ public function exportContent(ContentInterface $content, ?ContentVersionInterfac
break;

default:
throw new \Exception('Not yet implemented');
throw new Exception('Not yet implemented');
}
break;

default:
throw new \Exception('Not yet implemented');
throw new Exception('Not yet implemented');
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/Data/DataImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Softspring\CmsBundle\Data;

use Doctrine\ORM\EntityManagerInterface;
use Exception;
use Psr\Log\LoggerInterface;
use Softspring\CmsBundle\Config\CmsConfig;
use Softspring\CmsBundle\Data\EntityTransformer\ContentEntityTransformerInterface;
Expand Down Expand Up @@ -107,7 +108,7 @@ public function importVersion(string $type, ContentInterface $content, array $ve
$transformer = $this->getDataTransformer($type);

if (!$transformer instanceof ContentEntityTransformerInterface) {
throw new \Exception('Invalid entity transformer, check configuration');
throw new Exception('Invalid entity transformer, check configuration');
}

foreach ($zipData['media'] as $id => $mediaData) {
Expand Down
5 changes: 3 additions & 2 deletions src/Data/EntityTransformer/BlockEntityTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Softspring\CmsBundle\Data\EntityTransformer;

use DateTime;
use Softspring\CmsBundle\Data\DataTransformer;
use Softspring\CmsBundle\Data\Exception\InvalidElementException;
use Softspring\CmsBundle\Data\Exception\ReferenceNotFoundException;
Expand Down Expand Up @@ -76,8 +77,8 @@ public function import(array $data, ReferencesRepository $referencesRepository,

$block->setName($data['block']['name']);
$block->setData($data['block']['data']);
$block->setPublishStartDate($data['block']['publish_start_date'] ? new \DateTime($data['block']['publish_start_date']) : null);
$block->setPublishEndDate($data['block']['publish_end_date'] ? new \DateTime($data['block']['publish_end_date']) : null);
$block->setPublishStartDate($data['block']['publish_start_date'] ? new DateTime($data['block']['publish_start_date']) : null);
$block->setPublishEndDate($data['block']['publish_end_date'] ? new DateTime($data['block']['publish_end_date']) : null);

return $block;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Data/EntityTransformer/RouteEntityTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Softspring\CmsBundle\Data\EntityTransformer;

use Exception;
use Softspring\CmsBundle\Data\Exception\InvalidElementException;
use Softspring\CmsBundle\Data\Exception\ReferenceNotFoundException;
use Softspring\CmsBundle\Data\Exception\RunPreloadBeforeImportException;
Expand Down Expand Up @@ -129,7 +130,7 @@ public function import(array $data, ReferencesRepository $referencesRepository,
break;

default:
throw new \Exception(sprintf('Route type %u not yet implemented', $routeData['type']));
throw new Exception(sprintf('Route type %u not yet implemented', $routeData['type']));
}

// store valid type
Expand Down
7 changes: 5 additions & 2 deletions src/Data/Exception/DataTransformerNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

namespace Softspring\CmsBundle\Data\Exception;

use Exception;
use Throwable;

/**
* @deprecated this class is deprecated, and will be removed on 6.0 version, when fixtures will be refactored to use serializer
*/
class DataTransformerNotFoundException extends \Exception
class DataTransformerNotFoundException extends Exception
{
public function __construct(string $type, int $code = 0, ?\Throwable $previous = null)
public function __construct(string $type, int $code = 0, ?Throwable $previous = null)
{
parent::__construct("Data transformer not found for '$type' elements", $code, $previous);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Data/Exception/InvalidElementException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace Softspring\CmsBundle\Data\Exception;

use Exception;

/**
* @deprecated this class is deprecated, and will be removed on 6.0 version, when fixtures will be refactored to use serializer
*/
class InvalidElementException extends \Exception
class InvalidElementException extends Exception
{
}
4 changes: 3 additions & 1 deletion src/Data/Exception/ReferenceNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace Softspring\CmsBundle\Data\Exception;

use Exception;

/**
* @deprecated this class is deprecated, and will be removed on 6.0 version, when fixtures will be refactored to use serializer
*/
class ReferenceNotFoundException extends \Exception
class ReferenceNotFoundException extends Exception
{
}
4 changes: 3 additions & 1 deletion src/Data/Exception/RunPreloadBeforeImportException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace Softspring\CmsBundle\Data\Exception;

use Exception;

/**
* @deprecated this class is deprecated, and will be removed on 6.0 version, when fixtures will be refactored to use serializer
*/
class RunPreloadBeforeImportException extends \Exception
class RunPreloadBeforeImportException extends Exception
{
}
3 changes: 2 additions & 1 deletion src/DataCollector/ContentDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\HttpKernel\HttpCache\Esi;
use Symfony\Component\HttpKernel\Profiler\Profiler;
use Symfony\Contracts\Translation\TranslatorInterface;
use Throwable;

class ContentDataCollector extends DataCollector
{
Expand All @@ -40,7 +41,7 @@ public function __construct(BlockRenderer $blockRenderer, MenuRenderer $menuRend
$this->httpCacheEnabled = (bool) $httpCache;
}

public function collect(Request $request, Response $response, ?\Throwable $exception = null): void
public function collect(Request $request, Response $response, ?Throwable $exception = null): void
{
if (!$this->profilerEnabled) {
return; // DO NOT COLLECT DATA IF PROFILER IS NOT ENABLED
Expand Down
3 changes: 2 additions & 1 deletion src/DataCollector/TwigDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Softspring\CmsBundle\DataCollector;

use ReflectionClass;
use Symfony\Bridge\Twig\DataCollector\TwigDataCollector as BaseTwigDataCollector;

class TwigDataCollector extends BaseTwigDataCollector
Expand All @@ -11,7 +12,7 @@ public function reset(): void
// do not remove data, to prevent overriding on _fragments or subrequests

// $this->computed = null; the following code sets null on computed private variable
$reflection = new \ReflectionClass(BaseTwigDataCollector::class);
$reflection = new ReflectionClass(BaseTwigDataCollector::class);
$computedPrivateProperty = $reflection->getProperty('computed');
$computedPrivateProperty->setAccessible(true);
$computedPrivateProperty->setValue($this, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Softspring\CmsBundle\DependencyInjection\Compiler;

use SplFileInfo;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Finder\Exception\DirectoryNotFoundException;
Expand All @@ -24,7 +25,7 @@ public function process(ContainerBuilder $container): void
$finder = Finder::create()
->followLinks()
->files()
->filter(function (\SplFileInfo $file) {
->filter(function (SplFileInfo $file) {
return 2 <= substr_count($file->getBasename(), '.') && preg_match('/\.\w+$/', $file->getBasename());
})
->in($translationsPath)
Expand Down
Loading

0 comments on commit fa01778

Please sign in to comment.