Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@
"pamil/phpspec-skip-example-extension": "^4.2",
"phpspec/phpspec": "^7.5",
"phpspec/prophecy-phpunit": "^2.2",
"phpstan/phpstan": "^1.12",
"phpstan/phpstan-phpunit": "^1.4",
"phpstan/phpstan-webmozart-assert": "^1.2",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"phpstan/phpstan-webmozart-assert": "^2.0",
"phpunit/phpunit": "^10.0",
"rector/rector": "^0.18.2",
"rector/rector": "^2.0",
"sylius-labs/coding-standard": "^4.4",
"sylius/grid-bundle": "^1.13",
"symfony/console": "^6.4 || ^7.1",
Expand Down Expand Up @@ -137,7 +137,8 @@
"analyse": [
"@composer validate --strict",
"vendor/bin/ecs check",
"vendor/bin/phpstan analyse --ansi --memory-limit=256M -c phpstan.neon -l max src"
"vendor/bin/phpstan analyse --ansi --memory-limit=256M -c phpstan.neon -l max src",
"vendor/bin/rector process --dry-run"
],
"fix": [
"vendor/bin/ecs check --fix"
Expand Down
847 changes: 847 additions & 0 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ includes:
- vendor/phpstan/phpstan-phpunit/extension.neon

- vendor/phpstan/phpstan-phpunit/rules.neon
- phpstan-baseline.neon

parameters:
reportUnmatchedIgnoredErrors: false
Expand Down
25 changes: 11 additions & 14 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

declare(strict_types=1);

use Rector\Core\Configuration\Option;
use Rector\Php74\Rector\Property\TypedPropertyRector;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void
{
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
$parameters->set(Option::IMPORT_SHORT_CLASSES, false);

$services = $containerConfigurator->services();
$services->set(TypedPropertyRector::class);
};
use Rector\Config\RectorConfig;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/src'
])
->withSkipPath('src/Bundle/spec')
->withSkipPath('src/Component/legacy/spec')
->withSkipPath('src/Component/spec')
->withPhpSets(php80: true)
;
2 changes: 1 addition & 1 deletion src/Bundle/AbstractResourceBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected function getModelNamespace(): ?string
/**
* Return mapping compiler pass class depending on driver.
*
*
* @return string[]
*
* @throws UnknownDriverException
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Bundle/Controller/ControllerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ protected function json($data, int $status = 200, array $headers = [], array $co
protected function file($file, string $fileName = null, string $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT): BinaryFileResponse
{
$response = new BinaryFileResponse($file);
$response->setContentDisposition($disposition, null === $fileName ? $response->getFile()->getFilename() : $fileName);
$response->setContentDisposition($disposition, $fileName ?? $response->getFile()->getFilename());

return $response;
}
Expand Down
5 changes: 1 addition & 4 deletions src/Bundle/Controller/EventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@

final class EventDispatcher implements EventDispatcherInterface
{
private SymfonyEventDispatcherInterface $eventDispatcher;

public function __construct(SymfonyEventDispatcherInterface $eventDispatcher)
public function __construct(private SymfonyEventDispatcherInterface $eventDispatcher)
{
$this->eventDispatcher = $eventDispatcher;
}

public function dispatch(
Expand Down
8 changes: 1 addition & 7 deletions src/Bundle/Controller/FlashHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,10 @@ final class FlashHelper implements FlashHelperInterface
/** @var RequestStack|SessionInterface */
private $requestStack;

private TranslatorInterface $translator;

private string $defaultLocale;

/**
* @param RequestStack|SessionInterface $requestStack
*/
public function __construct(/* RequestStack */ $requestStack, TranslatorInterface $translator, string $defaultLocale)
public function __construct(/* RequestStack */ $requestStack, private TranslatorInterface $translator, private string $defaultLocale)
{
/** @phpstan-ignore-next-line */
if (!$requestStack instanceof SessionInterface && !$requestStack instanceof RequestStack) {
Expand All @@ -53,8 +49,6 @@ public function __construct(/* RequestStack */ $requestStack, TranslatorInterfac
}

$this->requestStack = $requestStack;
$this->translator = $translator;
$this->defaultLocale = $defaultLocale;
}

public function addSuccessFlash(
Expand Down
14 changes: 4 additions & 10 deletions src/Bundle/Controller/ParametersParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,8 @@

final class ParametersParser implements ParametersParserInterface
{
private ContainerInterface $container;

private ExpressionLanguage $expression;

public function __construct(ContainerInterface $container, ExpressionLanguage $expression)
public function __construct(private ContainerInterface $container, private ExpressionLanguage $expression)
{
$this->container = $container;
$this->expression = $expression;
}

public function parseRequestValues(array $parameters, Request $request): array
Expand Down Expand Up @@ -61,15 +55,15 @@ private function parseRequestValue($parameter, Request $request)
return $parameter;
}

if (0 === strpos($parameter, '$')) {
if (str_starts_with($parameter, '$')) {
return RequestParameterProvider::provide($request, substr($parameter, 1));
}

if (0 === strpos($parameter, 'expr:')) {
if (str_starts_with($parameter, 'expr:')) {
return $this->parseRequestValueExpression(substr($parameter, 5), $request);
}

if (0 === strpos($parameter, '!!')) {
if (str_starts_with($parameter, '!!')) {
return $this->parseRequestValueTypecast($parameter, $request);
}

Expand Down
7 changes: 2 additions & 5 deletions src/Bundle/Controller/RedirectHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@

final class RedirectHandler implements RedirectHandlerInterface
{
private RouterInterface $router;

public function __construct(RouterInterface $router)
public function __construct(private RouterInterface $router)
{
$this->router = $router;
}

public function redirectToResource(RequestConfiguration $configuration, ResourceInterface $resource): Response
Expand All @@ -37,7 +34,7 @@ public function redirectToResource(RequestConfiguration $configuration, Resource
(string) $configuration->getRedirectRoute(ResourceActions::SHOW),
$configuration->getRedirectParameters($resource),
);
} catch (RouteNotFoundException $exception) {
} catch (RouteNotFoundException) {
return $this->redirectToRoute(
$configuration,
(string) $configuration->getRedirectRoute(ResourceActions::INDEX),
Expand Down
20 changes: 4 additions & 16 deletions src/Bundle/Controller/RequestConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,8 @@

class RequestConfiguration
{
private Request $request;

private MetadataInterface $metadata;

private Parameters $parameters;

public function __construct(MetadataInterface $metadata, Request $request, Parameters $parameters)
public function __construct(private MetadataInterface $metadata, private Request $request, private Parameters $parameters)
{
$this->metadata = $metadata;
$this->request = $request;
$this->parameters = $parameters;
}

/**
Expand Down Expand Up @@ -82,7 +73,7 @@ public function getDefaultTemplate($name)
{
$templatesNamespace = (string) $this->metadata->getTemplatesNamespace();

if (false !== strpos($templatesNamespace, ':')) {
if (str_contains($templatesNamespace, ':')) {
return sprintf('%s:%s.%s', $templatesNamespace ?: ':', $name, 'twig');
}

Expand Down Expand Up @@ -128,11 +119,8 @@ public function getFormType()
public function getFormOptions()
{
$form = $this->parameters->get('form');
if (isset($form['options'])) {
return $form['options'];
}

return [];
return $form['options'] ?? [];
}

/**
Expand Down Expand Up @@ -541,7 +529,7 @@ private function parseResourceValues(array $parameters, $resource): array
$parameters[$key] = $this->parseResourceValues($value, $resource);
}

if (is_string($value) && 0 === strpos($value, 'resource.')) {
if (is_string($value) && str_starts_with($value, 'resource.')) {
$parameters[$key] = $accessor->getValue($resource, substr($value, 9));
}
}
Expand Down
23 changes: 8 additions & 15 deletions src/Bundle/Controller/RequestConfigurationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,17 @@ final class RequestConfigurationFactory implements RequestConfigurationFactoryIn

private const API_GROUPS_REGEXP = '/(g|groups)=(?P<groups>[a-z,_\s]+)/i';

private ParametersParserInterface $parametersParser;

/**
* @var string
* @psalm-var class-string<RequestConfiguration>
*/
private $configurationClass;

private array $defaultParameters;

/**
* @psalm-param class-string<RequestConfiguration> $configurationClass
*/
public function __construct(ParametersParserInterface $parametersParser, string $configurationClass, array $defaultParameters = [])
{
$this->parametersParser = $parametersParser;
$this->configurationClass = $configurationClass;
$this->defaultParameters = $defaultParameters;
public function __construct(
private ParametersParserInterface $parametersParser,
/**
* @psalm-param class-string<RequestConfiguration>
*/
private string $configurationClass,
private array $defaultParameters = [],
) {
}

public function create(MetadataInterface $metadata, Request $request): RequestConfiguration
Expand Down
85 changes: 17 additions & 68 deletions src/Bundle/Controller/ResourceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,76 +36,25 @@ class ResourceController
use ControllerTrait;
use ContainerAwareTrait;

protected MetadataInterface $metadata;

protected RequestConfigurationFactoryInterface $requestConfigurationFactory;

protected ?ViewHandlerInterface $viewHandler;

protected RepositoryInterface $repository;

protected FactoryInterface $factory;

protected NewResourceFactoryInterface $newResourceFactory;

protected ObjectManager $manager;

protected SingleResourceProviderInterface $singleResourceProvider;

protected ResourcesCollectionProviderInterface $resourcesCollectionProvider;

protected ResourceFormFactoryInterface $resourceFormFactory;

protected RedirectHandlerInterface $redirectHandler;

protected FlashHelperInterface $flashHelper;

protected AuthorizationCheckerInterface $authorizationChecker;

protected EventDispatcherInterface $eventDispatcher;

protected ?StateMachineInterface $stateMachine;

protected ResourceUpdateHandlerInterface $resourceUpdateHandler;

protected ResourceDeleteHandlerInterface $resourceDeleteHandler;

public function __construct(
MetadataInterface $metadata,
RequestConfigurationFactoryInterface $requestConfigurationFactory,
?ViewHandlerInterface $viewHandler,
RepositoryInterface $repository,
FactoryInterface $factory,
NewResourceFactoryInterface $newResourceFactory,
ObjectManager $manager,
SingleResourceProviderInterface $singleResourceProvider,
ResourcesCollectionProviderInterface $resourcesFinder,
ResourceFormFactoryInterface $resourceFormFactory,
RedirectHandlerInterface $redirectHandler,
FlashHelperInterface $flashHelper,
AuthorizationCheckerInterface $authorizationChecker,
EventDispatcherInterface $eventDispatcher,
?StateMachineInterface $stateMachine,
ResourceUpdateHandlerInterface $resourceUpdateHandler,
ResourceDeleteHandlerInterface $resourceDeleteHandler,
protected MetadataInterface $metadata,
protected RequestConfigurationFactoryInterface $requestConfigurationFactory,
protected ?ViewHandlerInterface $viewHandler,
protected RepositoryInterface $repository,
protected FactoryInterface $factory,
protected NewResourceFactoryInterface $newResourceFactory,
protected ObjectManager $manager,
protected SingleResourceProviderInterface $singleResourceProvider,
protected ResourcesCollectionProviderInterface $resourcesCollectionProvider,
protected ResourceFormFactoryInterface $resourceFormFactory,
protected RedirectHandlerInterface $redirectHandler,
protected FlashHelperInterface $flashHelper,
protected AuthorizationCheckerInterface $authorizationChecker,
protected EventDispatcherInterface $eventDispatcher,
protected ?StateMachineInterface $stateMachine,
protected ResourceUpdateHandlerInterface $resourceUpdateHandler,
protected ResourceDeleteHandlerInterface $resourceDeleteHandler,
) {
$this->metadata = $metadata;
$this->requestConfigurationFactory = $requestConfigurationFactory;
$this->viewHandler = $viewHandler;
$this->repository = $repository;
$this->factory = $factory;
$this->newResourceFactory = $newResourceFactory;
$this->manager = $manager;
$this->singleResourceProvider = $singleResourceProvider;
$this->resourcesCollectionProvider = $resourcesFinder;
$this->resourceFormFactory = $resourceFormFactory;
$this->redirectHandler = $redirectHandler;
$this->flashHelper = $flashHelper;
$this->authorizationChecker = $authorizationChecker;
$this->eventDispatcher = $eventDispatcher;
$this->stateMachine = $stateMachine;
$this->resourceUpdateHandler = $resourceUpdateHandler;
$this->resourceDeleteHandler = $resourceDeleteHandler;
}

public function showAction(Request $request): Response
Expand Down
5 changes: 1 addition & 4 deletions src/Bundle/Controller/ResourceFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@

final class ResourceFormFactory implements ResourceFormFactoryInterface
{
private FormFactoryInterface $formFactory;

public function __construct(FormFactoryInterface $formFactory)
public function __construct(private FormFactoryInterface $formFactory)
{
$this->formFactory = $formFactory;
}

public function create(RequestConfiguration $requestConfiguration, ResourceInterface $resource): FormInterface
Expand Down
5 changes: 1 addition & 4 deletions src/Bundle/Controller/ResourceUpdateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@

final class ResourceUpdateHandler implements ResourceUpdateHandlerInterface
{
private ?StateMachineInterface $stateMachine;

public function __construct(?StateMachineInterface $stateMachine)
public function __construct(private ?StateMachineInterface $stateMachine)
{
$this->stateMachine = $stateMachine;
}

public function handle(
Expand Down
5 changes: 1 addition & 4 deletions src/Bundle/Controller/StateMachine.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@

final class StateMachine implements StateMachineInterface
{
private FactoryInterface $stateMachineFactory;

public function __construct(FactoryInterface $stateMachineFactory)
public function __construct(private FactoryInterface $stateMachineFactory)
{
$this->stateMachineFactory = $stateMachineFactory;
}

public function can(RequestConfiguration $configuration, ResourceInterface $resource): bool
Expand Down
Loading
Loading