Skip to content

Commit

Permalink
Apply ECS.
Browse files Browse the repository at this point in the history
  • Loading branch information
bytes-commerce committed Sep 3, 2023
1 parent 0a528f8 commit 2ec18dd
Show file tree
Hide file tree
Showing 505 changed files with 8,968 additions and 4,639 deletions.
1 change: 0 additions & 1 deletion src/ArgumentResolver/AdminContextResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace EasyCorp\Bundle\EasyAdminBundle\ArgumentResolver;

use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
Expand Down
28 changes: 20 additions & 8 deletions src/ArgumentResolver/BatchActionDtoResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

use EasyCorp\Bundle\EasyAdminBundle\Config\Option\EA;
use EasyCorp\Bundle\EasyAdminBundle\Dto\BatchActionDto;
use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProviderInterface;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGeneratorInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
Expand All @@ -23,8 +21,10 @@ final class BatchActionDtoResolver implements ValueResolverInterface

private AdminUrlGeneratorInterface $adminUrlGenerator;

public function __construct(AdminContextProviderInterface $adminContextProvider, AdminUrlGeneratorInterface $adminUrlGenerator)
{
public function __construct(
AdminContextProviderInterface $adminContextProvider,
AdminUrlGeneratorInterface $adminUrlGenerator
) {
$this->adminContextProvider = $adminContextProvider;
$this->adminUrlGenerator = $adminUrlGenerator;
}
Expand All @@ -36,7 +36,12 @@ public function resolve(Request $request, ArgumentMetadata $argument): iterable
}

if (null === $context = $this->adminContextProvider->getContext()) {
throw new \RuntimeException(sprintf('Some of your controller actions have type-hinted an argument with the "%s" class but that\'s only available for actions run to serve EasyAdmin requests. Remove the type-hint or make sure the action is part of an EasyAdmin request.', BatchActionDto::class));
throw new \RuntimeException(
sprintf(
'Some of your controller actions have type-hinted an argument with the "%s" class but that\'s only available for actions run to serve EasyAdmin requests. Remove the type-hint or make sure the action is part of an EasyAdmin request.',
BatchActionDto::class
)
);
}

$batchActionUrl = $context->getRequest()->request->get(EA::BATCH_ACTION_URL);
Expand All @@ -59,8 +64,10 @@ final class BatchActionDtoResolver implements ArgumentValueResolverInterface
private AdminContextProviderInterface $adminContextProvider;
private AdminUrlGeneratorInterface $adminUrlGenerator;

public function __construct(AdminContextProviderInterface $adminContextProvider, AdminUrlGeneratorInterface $adminUrlGenerator)
{
public function __construct(
AdminContextProviderInterface $adminContextProvider,
AdminUrlGeneratorInterface $adminUrlGenerator
) {
$this->adminContextProvider = $adminContextProvider;
$this->adminUrlGenerator = $adminUrlGenerator;
}
Expand All @@ -73,7 +80,12 @@ public function supports(Request $request, ArgumentMetadata $argument): bool
public function resolve(Request $request, ArgumentMetadata $argument): iterable
{
if (null === $context = $this->adminContextProvider->getContext()) {
throw new \RuntimeException(sprintf('Some of your controller actions have type-hinted an argument with the "%s" class but that\'s only available for actions run to serve EasyAdmin requests. Remove the type-hint or make sure the action is part of an EasyAdmin request.', BatchActionDto::class));
throw new \RuntimeException(
sprintf(
'Some of your controller actions have type-hinted an argument with the "%s" class but that\'s only available for actions run to serve EasyAdmin requests. Remove the type-hint or make sure the action is part of an EasyAdmin request.',
BatchActionDto::class
)
);
}

$batchActionUrl = $context->getRequest()->request->get(EA::BATCH_ACTION_URL);
Expand Down
1 change: 1 addition & 0 deletions src/Cache/CacheWarmer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouterInterface;

use function Symfony\Component\String\u;

/**
Expand Down
31 changes: 18 additions & 13 deletions src/Collection/ActionCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use ArrayIterator;
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Collection\CollectionInterface;
use EasyCorp\Bundle\EasyAdminBundle\Dto\ActionDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\ActionDtoInterface;

use function array_key_exists;
Expand Down Expand Up @@ -85,25 +84,31 @@ public function getIterator(): ArrayIterator

public function getEntityActions(): self
{
return self::new(array_filter(
$this->actions,
static fn (ActionDtoInterface $action): bool => $action->isEntityAction()
));
return self::new(
array_filter(
$this->actions,
static fn(ActionDtoInterface $action): bool => $action->isEntityAction()
)
);
}

public function getGlobalActions(): self
{
return self::new(array_filter(
$this->actions,
static fn (ActionDtoInterface $action): bool => $action->isGlobalAction()
));
return self::new(
array_filter(
$this->actions,
static fn(ActionDtoInterface $action): bool => $action->isGlobalAction()
)
);
}

public function getBatchActions(): self
{
return self::new(array_filter(
$this->actions,
static fn (ActionDtoInterface $action): bool => $action->isBatchAction()
));
return self::new(
array_filter(
$this->actions,
static fn(ActionDtoInterface $action): bool => $action->isBatchAction()
)
);
}
}
1 change: 0 additions & 1 deletion src/Collection/EntityCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace EasyCorp\Bundle\EasyAdminBundle\Collection;

use EasyCorp\Bundle\EasyAdminBundle\Contracts\Collection\CollectionInterface;
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDtoInterface;

/**
Expand Down
1 change: 0 additions & 1 deletion src/Collection/FieldCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use EasyCorp\Bundle\EasyAdminBundle\Contracts\Collection\CollectionInterface;
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldInterface;
use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDtoInterface;
use EasyCorp\Bundle\EasyAdminBundle\Field\Field;

Expand Down
1 change: 0 additions & 1 deletion src/Collection/FilterCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace EasyCorp\Bundle\EasyAdminBundle\Collection;

use EasyCorp\Bundle\EasyAdminBundle\Contracts\Collection\CollectionInterface;
use EasyCorp\Bundle\EasyAdminBundle\Dto\FilterDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\FilterDtoInterface;

/**
Expand Down
51 changes: 37 additions & 14 deletions src/Command/MakeAdminDashboardCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace EasyCorp\Bundle\EasyAdminBundle\Command;

use EasyCorp\Bundle\EasyAdminBundle\Maker\ClassMaker;
use EasyCorp\Bundle\EasyAdminBundle\Maker\ClassMakerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
Expand All @@ -11,6 +10,7 @@
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\String\Slugger\AsciiSlugger;

use function Symfony\Component\String\u;

/**
Expand All @@ -37,8 +37,7 @@ public function __construct(ClassMakerInterface $classMaker, string $projectDir,
protected function configure(): void
{
$this
->setHelp($this->getCommandHelp())
;
->setHelp($this->getCommandHelp());
}

protected function execute(InputInterface $input, OutputInterface $output): int
Expand All @@ -49,7 +48,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$controllerClassName = $io->ask(
'Which class name do you prefer for your Dashboard controller?',
'DashboardController',
fn (string $className): string => u($className)->ensureEnd('Controller')->toString()
fn(string $className): string => u($className)->ensureEnd('Controller')->toString()
);

$projectDir = $this->projectDir;
Expand All @@ -59,32 +58,56 @@ protected function execute(InputInterface $input, OutputInterface $output): int
static function (string $selectedDir) use ($fs, $projectDir) {
$absoluteDir = u($selectedDir)->ensureStart($projectDir.\DIRECTORY_SEPARATOR);
if (null !== $absoluteDir->indexOf('..')) {
throw new \RuntimeException(sprintf('The given directory path can\'t contain ".." and must be relative to the project directory (which is "%s")', $projectDir));
throw new \RuntimeException(
sprintf(
'The given directory path can\'t contain ".." and must be relative to the project directory (which is "%s")',
$projectDir
)
);
}

$fs->mkdir($absoluteDir);

if (!$fs->exists($absoluteDir)) {
throw new \RuntimeException('The given directory does not exist and couldn\'t be created. Type in the path of an existing directory relative to your project root (e.g. src/Controller/Admin/)');
throw new \RuntimeException(
'The given directory does not exist and couldn\'t be created. Type in the path of an existing directory relative to your project root (e.g. src/Controller/Admin/)'
);
}

return $absoluteDir->after($projectDir.\DIRECTORY_SEPARATOR)->trimEnd(\DIRECTORY_SEPARATOR)->toString();
}
);

$controllerFilePath = sprintf('%s/%s.php', u($controllerDir)->ensureStart($projectDir.\DIRECTORY_SEPARATOR), $controllerClassName);
$controllerFilePath = sprintf(
'%s/%s.php',
u($controllerDir)->ensureStart($projectDir.\DIRECTORY_SEPARATOR),
$controllerClassName
);
if ($fs->exists($controllerFilePath)) {
throw new \RuntimeException(sprintf('The "%s.php" file already exists in the given "%s" directory. Use a different controller name or generate it in a different directory.', $controllerClassName, $controllerDir));
throw new \RuntimeException(
sprintf(
'The "%s.php" file already exists in the given "%s" directory. Use a different controller name or generate it in a different directory.',
$controllerClassName,
$controllerDir
)
);
}

$guessedNamespace = u($controllerDir)->equalsTo('src')
? 'App'
: u($controllerDir)->replace('/', ' ')->replace('\\', ' ')->replace('src ', 'app ')->title(true)->replace(' ', '\\')->trimEnd('\\');

$generatedFilePath = $this->classMaker->make(sprintf('%s/%s.php', $controllerDir, $controllerClassName), 'dashboard.tpl', [
'namespace' => $guessedNamespace,
'site_title' => $this->getSiteTitle($this->projectDir),
]);
: u($controllerDir)->replace('/', ' ')->replace('\\', ' ')->replace('src ', 'app ')->title(true)->replace(
' ',
'\\'
)->trimEnd('\\');

$generatedFilePath = $this->classMaker->make(
sprintf('%s/%s.php', $controllerDir, $controllerClassName),
'dashboard.tpl',
[
'namespace' => $guessedNamespace,
'site_title' => $this->getSiteTitle($this->projectDir),
]
);

$io = new SymfonyStyle($input, $output);
$io->success('Your dashboard class has been successfully generated.');
Expand Down
44 changes: 29 additions & 15 deletions src/Command/MakeCrudControllerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
namespace EasyCorp\Bundle\EasyAdminBundle\Command;

use Doctrine\Persistence\ManagerRegistry;
use EasyCorp\Bundle\EasyAdminBundle\Maker\ClassMaker;
use EasyCorp\Bundle\EasyAdminBundle\Maker\ClassMakerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Filesystem\Filesystem;

use function Symfony\Component\String\u;

/**
Expand All @@ -28,8 +28,12 @@ final class MakeCrudControllerCommand extends Command
private ClassMakerInterface $classMaker;
private ManagerRegistry $doctrine;

public function __construct(string $projectDir, ClassMakerInterface $classMaker, ManagerRegistry $doctrine, ?string $name = null)
{
public function __construct(
string $projectDir,
ClassMakerInterface $classMaker,
ManagerRegistry $doctrine,
?string $name = null
) {
parent::__construct($name);
$this->projectDir = $projectDir;
$this->classMaker = $classMaker;
Expand All @@ -39,8 +43,7 @@ public function __construct(string $projectDir, ClassMakerInterface $classMaker,
protected function configure(): void
{
$this
->setHelp($this->getCommandHelp())
;
->setHelp($this->getCommandHelp());
}

protected function execute(InputInterface $input, OutputInterface $output): int
Expand All @@ -50,7 +53,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$doctrineEntitiesFqcn = $this->getAllDoctrineEntitiesFqcn();
if (0 === \count($doctrineEntitiesFqcn)) {
$io->error('This command generates the CRUD controller of an existing Doctrine entity, but no entities were found in your application. Create some Doctrine entities first and then run this command again.');
$io->error(
'This command generates the CRUD controller of an existing Doctrine entity, but no entities were found in your application. Create some Doctrine entities first and then run this command again.'
);

return Command::FAILURE;
}
Expand All @@ -62,22 +67,31 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$controllerFileNamePattern = sprintf('%s{number}CrudController.php', $entityClassName);

$projectDir = $this->projectDir;
$controllerDir = $io->ask('Which directory do you want to generate the CRUD controller in?', 'src/Controller/Admin/', static function (string $selectedDir) use ($fs, $projectDir) {
$absoluteDir = u($selectedDir)->ensureStart($projectDir.\DIRECTORY_SEPARATOR);
if (!$fs->exists($absoluteDir)) {
throw new \RuntimeException('The given directory does not exist. Type in the path of an existing directory relative to your project root (e.g. src/Controller/Admin/)');
$controllerDir = $io->ask(
'Which directory do you want to generate the CRUD controller in?',
'src/Controller/Admin/',
static function (string $selectedDir) use ($fs, $projectDir) {
$absoluteDir = u($selectedDir)->ensureStart($projectDir.\DIRECTORY_SEPARATOR);
if (!$fs->exists($absoluteDir)) {
throw new \RuntimeException(
'The given directory does not exist. Type in the path of an existing directory relative to your project root (e.g. src/Controller/Admin/)'
);
}

return $absoluteDir->after($projectDir.\DIRECTORY_SEPARATOR)->trimEnd(\DIRECTORY_SEPARATOR)->toString();
}

return $absoluteDir->after($projectDir.\DIRECTORY_SEPARATOR)->trimEnd(\DIRECTORY_SEPARATOR)->toString();
});
);

$guessedNamespace = u($controllerDir)->equalsTo('src')
? 'App'
: u($controllerDir)->replace('/', ' ')->replace('\\', ' ')->replace('src ', 'app ')->title(true)->replace('App App ', 'App ')->replace(' ', '\\')->trimEnd(\DIRECTORY_SEPARATOR);
: u($controllerDir)->replace('/', ' ')->replace('\\', ' ')->replace('src ', 'app ')->title(true)->replace(
'App App ',
'App '
)->replace(' ', '\\')->trimEnd(\DIRECTORY_SEPARATOR);
$namespace = $io->ask(
'Namespace of the generated CRUD controller',
$guessedNamespace,
static fn (string $namespace): string => u($namespace)->replace('/', '\\')->toString()
static fn(string $namespace): string => u($namespace)->replace('/', '\\')->toString()
);

$generatedFilePath = $this->classMaker->make(
Expand Down
20 changes: 16 additions & 4 deletions src/Config/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

use EasyCorp\Bundle\EasyAdminBundle\Dto\ActionDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\ActionDtoInterface;
use function Symfony\Component\String\u;
use Symfony\Contracts\Translation\TranslatableInterface;

use function Symfony\Component\String\u;

final class Action implements ActionInterface
{
private ActionDtoInterface $dto;
Expand Down Expand Up @@ -186,11 +187,22 @@ public function displayIf(callable $callable): self
public function getAsDto(): ActionDtoInterface
{
if (null === $this->dto->getLabel() && null === $this->dto->getIcon()) {
throw new \InvalidArgumentException(sprintf('The label and icon of an action cannot be null at the same time. Either set the label, the icon or both for the "%s" action.', $this->dto->getName()));
throw new \InvalidArgumentException(
sprintf(
'The label and icon of an action cannot be null at the same time. Either set the label, the icon or both for the "%s" action.',
$this->dto->getName()
)
);
}

if (null === $this->dto->getCrudActionName() && null === $this->dto->getRouteName() && null === $this->dto->getUrl()) {
throw new \InvalidArgumentException(sprintf('Actions must link to either a route, a CRUD action, or a URL. Set the "linkToCrudAction()", "linkToRoute()", or "linkToUrl()" method for the "%s" action.', $this->dto->getName()));
if (null === $this->dto->getCrudActionName() && null === $this->dto->getRouteName(
) && null === $this->dto->getUrl()) {
throw new \InvalidArgumentException(
sprintf(
'Actions must link to either a route, a CRUD action, or a URL. Set the "linkToCrudAction()", "linkToRoute()", or "linkToUrl()" method for the "%s" action.',
$this->dto->getName()
)
);
}

return $this->dto;
Expand Down
Loading

0 comments on commit 2ec18dd

Please sign in to comment.