Skip to content

Commit

Permalink
Fix CS
Browse files Browse the repository at this point in the history
  • Loading branch information
hlecorche committed Nov 16, 2024
1 parent d39a720 commit fd34aa9
Show file tree
Hide file tree
Showing 30 changed files with 51 additions and 51 deletions.
2 changes: 1 addition & 1 deletion src/Controller/CrudControllerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ abstract protected function getCrudOptions(): array;

abstract protected function getTemplateName(string $action): string;

protected function createCrudConfig(string $sessionName = null): CrudConfig
protected function createCrudConfig(?string $sessionName = null): CrudConfig
{
return new CrudConfig($sessionName);
}
Expand Down
12 changes: 6 additions & 6 deletions src/Crud/Crud.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function __construct(array $options, protected ContainerInterface $contai
throw new \Exception('A column must be an array or a CrudColum instance.');
}
if (\array_key_exists($column->getId(), $columns)) {
throw new \Exception(sprintf('The column "column1" already exists.', $column->getId()));
throw new \Exception(\sprintf('The column "column1" already exists.', $column->getId()));
}
$columns[$column->getId()] = $column;
}
Expand All @@ -133,7 +133,7 @@ public function __construct(array $options, protected ContainerInterface $contai
throw new \Exception('A column must be an array or a CrudColum instance.');
}
if (\array_key_exists($column->getId(), $columns)) {
throw new \Exception(sprintf('The column "column1" already exists.', $column->getId()));
throw new \Exception(\sprintf('The column "column1" already exists.', $column->getId()));
}
$columns[$column->getId()] = $column;
}
Expand Down Expand Up @@ -186,7 +186,7 @@ public function __construct(array $options, protected ContainerInterface $contai
// Check duplicates in columns / vitual columns
$duplicates = array_intersect_key($this->options['columns'], $this->options['virtual_columns']);
if (\count($duplicates) > 0) {
throw new \Exception(sprintf('The column "column1" already exists.', array_keys($duplicates)[0]));
throw new \Exception(\sprintf('The column "column1" already exists.', array_keys($duplicates)[0]));
}

$this->init();
Expand Down Expand Up @@ -262,7 +262,7 @@ public function getColumn(string $columnId): CrudColumn
if (isset($this->options['columns'][$columnId])) {
return $this->options['columns'][$columnId];
}
throw new \Exception(sprintf('The column "%s" does not exist.', $columnId));
throw new \Exception(\sprintf('The column "%s" does not exist.', $columnId));
}

/**
Expand Down Expand Up @@ -296,7 +296,7 @@ public function getVirtualColumn(string $columnId): CrudColumn
if (isset($this->options['virtual_columns'][$columnId])) {
return $this->options['virtual_columns'][$columnId];
}
throw new \Exception(sprintf('The column "%s" does not exist.', $columnId));
throw new \Exception(\sprintf('The column "%s" does not exist.', $columnId));
}

public function getQueryBuilder(): \Doctrine\ORM\QueryBuilder|\Doctrine\DBAL\Query\QueryBuilder|QueryBuilderInterface
Expand Down Expand Up @@ -805,7 +805,7 @@ protected function createDisplaySettingsForm(): void
'resultsPerPage' => $this->getSessionValues()->getMaxPerPage(),
'displayedColumns' => $this->getSessionValues()->getDisplayedColumns(),
];
$formName = sprintf('crud_display_settings_%s', $this->getSessionName());
$formName = \sprintf('crud_display_settings_%s', $this->getSessionName());

$this->displaySettingsForm = $this->container->get('form.factory')->createNamed($formName, DisplaySettingsType::class, $data, [
'results_per_page_choices' => $resultsPerPageChoices,
Expand Down
6 changes: 3 additions & 3 deletions src/Crud/CrudConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class CrudConfig implements \ArrayAccess
{
protected array $options = [];

public function __construct(string $sessionName = null)
public function __construct(?string $sessionName = null)
{
if (null !== $sessionName) {
$this->setSessionName($sessionName);
Expand Down Expand Up @@ -155,7 +155,7 @@ public function setRoute(string $name, array $parameters = []): self
return $this;
}

public function createSearchForm(SearcherInterface $defaultData, string $type = null, array $options = []): self
public function createSearchForm(SearcherInterface $defaultData, ?string $type = null, array $options = []): self
{
$this->options['search_form_data'] = $defaultData;
$this->options['search_form_type'] = $type;
Expand Down Expand Up @@ -209,7 +209,7 @@ public function setTwigFunctionsConfiguration(array $value): self
return $this;
}

public function resetOptions(string|array $options = null): self
public function resetOptions(string|array|null $options = null): self
{
if (null === $options) {
$this->options = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Crud/CrudResponseGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ protected function renderCrudView(string $view, array $parameters = []): string
return $this->container->get('twig')->render($view, $parameters);
}

protected function renderCrud(string $view, array $parameters = [], Response $response = null): Response
protected function renderCrud(string $view, array $parameters = [], ?Response $response = null): Response
{
$content = $this->container->get('twig')->render($view, $parameters);

Expand Down
2 changes: 1 addition & 1 deletion src/Crud/CrudSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class CrudSession
/**
* @internal
*/
public function __construct(protected int $maxPerPage, protected array $displayedColumns, protected string $sort, protected string $sortDirection, SearcherInterface $searchFormData = null)
public function __construct(protected int $maxPerPage, protected array $displayedColumns, protected string $sort, protected string $sortDirection, ?SearcherInterface $searchFormData = null)
{
$this->searchFormData = ($searchFormData) ? clone $searchFormData : null; // Avoid modification by reference (by the user or an invalid form)
}
Expand Down
2 changes: 1 addition & 1 deletion src/Crud/Http/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class QueryBuilder implements QueryBuilderInterface
protected array $orders = [];
protected HttpClientInterface $client;

public function __construct(protected string $url, protected string $httpMethod, HttpClientInterface $client = null)
public function __construct(protected string $url, protected string $httpMethod, ?HttpClientInterface $client = null)
{
if (null === $client) {
$client = HttpClient::create();
Expand Down
8 changes: 4 additions & 4 deletions src/Crud/SearchFormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected function createFormBuilder(?string $type): void
if ($type) {
$this->form = $formFactory->createBuilder($type, null, $formOptions);
} else {
$formName = sprintf('crud_search_%s', $this->crud->getSessionName());
$formName = \sprintf('crud_search_%s', $this->crud->getSessionName());
$this->form = $formFactory->createNamedBuilder($formName, FormSearchType::class, null, $formOptions);
}
}
Expand All @@ -67,7 +67,7 @@ public function addFilter(string $property, string $filter, array $options = [])
throw new \Exception('The "addFilter" method cannot be called after the form creation');
}
if (!$this->container->get('ecommit_crud.filters')->has($filter)) {
throw new \Exception(sprintf('The filter "%s" does not exist', $filter));
throw new \Exception(\sprintf('The filter "%s" does not exist', $filter));
}
/** @var FilterInterface $filterService */
$filterService = $this->container->get('ecommit_crud.filters')->get($filter);
Expand Down Expand Up @@ -139,7 +139,7 @@ public function createForm(): self
// Check if column exists
$columnId = $filter['options']['column_id'];
if (!\array_key_exists($columnId, $this->crud->getColumns()) && !\array_key_exists($columnId, $this->crud->getVirtualColumns())) {
throw new \Exception(sprintf('The column "%s" does not exist', $columnId));
throw new \Exception(\sprintf('The column "%s" does not exist', $columnId));
}

/** @var FilterInterface $filterService */
Expand Down Expand Up @@ -219,7 +219,7 @@ public function updateQueryBuilder(\Doctrine\ORM\QueryBuilder|\Doctrine\DBAL\Que
/** @var FilterInterface $filterService */
$filterService = $this->container->get('ecommit_crud.filters')->get($filter['name']);
if (!$filterService->supportsQueryBuilder($queryBuilder)) {
throw new \Exception(sprintf('The filter "%s" does not support "%s" query builder', $filter['name'], $queryBuilder::class));
throw new \Exception(\sprintf('The filter "%s" does not support "%s" query builder', $filter['name'], $queryBuilder::class));
}
$filterService->updateQueryBuilder($queryBuilder, $property, $value, $filter['options']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function reverseTransform(mixed $value): mixed
}
$value = array_unique($value);
if (\count($value) > $this->maxResults) {
throw new TransformationFailedException(sprintf('This collection should contain %s elements or less.', $this->maxResults));
throw new TransformationFailedException(\sprintf('This collection should contain %s elements or less.', $this->maxResults));
}

$hash = $this->getCacheHash($value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function reverseTransform(mixed $value): mixed
}
if (1 !== \count($entities)) {
if ($this->throwExceptionIfValueNotFoundInReverse) {
throw new TransformationFailedException(sprintf('The entity with key "%s" could not be found or is not unique', (string) $value));
throw new TransformationFailedException(\sprintf('The entity with key "%s" could not be found or is not unique', (string) $value));
}

return null;
Expand Down
10 changes: 5 additions & 5 deletions src/Form/Filter/BooleanFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,25 @@ public function updateQueryBuilder(mixed $queryBuilder, string $property, mixed

if (static::VALUE_TRUE === $value) {
$or = $queryBuilder->expr()->orX();
$or->add(sprintf('%s = :%s', $options['alias_search'], $parameterTrueName));
$or->add(\sprintf('%s = :%s', $options['alias_search'], $parameterTrueName));
$queryBuilder->setParameter($parameterTrueName, $options['value_true']);
if ($options['not_null_is_true']) {
$or->add(sprintf('%s IS NOT NULL AND %s != :%s', $options['alias_search'], $options['alias_search'], $parameterFalseName));
$or->add(\sprintf('%s IS NOT NULL AND %s != :%s', $options['alias_search'], $options['alias_search'], $parameterFalseName));
$queryBuilder->setParameter($parameterFalseName, $options['value_false']);
}
$queryBuilder->andWhere($or);
} elseif (static::VALUE_FALSE === $value) {
if (null === $options['value_false']) {
$queryBuilder->andWhere(sprintf('%s IS NULL', $options['alias_search']));
$queryBuilder->andWhere(\sprintf('%s IS NULL', $options['alias_search']));

return;
}

$or = $queryBuilder->expr()->orX();
$or->add(sprintf('%s = :%s', $options['alias_search'], $parameterFalseName));
$or->add(\sprintf('%s = :%s', $options['alias_search'], $parameterFalseName));
$queryBuilder->setParameter($parameterFalseName, $options['value_false']);
if ($options['null_is_false']) {
$or->add(sprintf('%s IS NULL', $options['alias_search']));
$or->add(\sprintf('%s IS NULL', $options['alias_search']));
}
$queryBuilder->andWhere($or);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Form/Filter/CollectionFilterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected function updateCollectionQueryBuilder(mixed $queryBuilder, string $pro
if (!\is_scalar($value)) {
return;
}
$queryBuilder->andWhere(sprintf('%s = :%s', $options['alias_search'], $parameterName))
$queryBuilder->andWhere(\sprintf('%s = :%s', $options['alias_search'], $parameterName))
->setParameter($parameterName, $value);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Form/Filter/DateFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function updateQueryBuilder(mixed $queryBuilder, string $property, mixed
}
$value = $value->format('Y-m-d H:i:s');
$queryBuilder->andWhere(
sprintf('%s %s :%s', $options['alias_search'], $options['comparator'], $parameterName)
\sprintf('%s %s :%s', $options['alias_search'], $options['comparator'], $parameterName)
)
->setParameter($parameterName, $value);
break;
Expand All @@ -66,7 +66,7 @@ public function updateQueryBuilder(mixed $queryBuilder, string $property, mixed
}
$value = $value->format('Y-m-d H:i:s');
$queryBuilder->andWhere(
sprintf('%s %s :%s', $options['alias_search'], $options['comparator'], $parameterName)
\sprintf('%s %s :%s', $options['alias_search'], $options['comparator'], $parameterName)
)
->setParameter($parameterName, $value);
break;
Expand All @@ -82,7 +82,7 @@ public function updateQueryBuilder(mixed $queryBuilder, string $property, mixed
$parameterNameInf = 'value_date_inf_'.str_replace(' ', '', $property);
$parameterNameSup = 'value_date_sup_'.str_replace(' ', '', $property);
$queryBuilder->andWhere(
sprintf(
\sprintf(
'%s >= :%s AND %s <= :%s',
$options['alias_search'],
$parameterNameInf,
Expand Down
2 changes: 1 addition & 1 deletion src/Form/Filter/IntegerFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function updateQueryBuilder(mixed $queryBuilder, string $property, mixed

$parameterName = 'value_integer_'.str_replace(' ', '', $property);

$queryBuilder->andWhere(sprintf('%s %s :%s', $options['alias_search'], $options['comparator'], $parameterName))
$queryBuilder->andWhere(\sprintf('%s %s :%s', $options['alias_search'], $options['comparator'], $parameterName))
->setParameter($parameterName, $value);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Form/Filter/NotNullFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public function updateQueryBuilder(mixed $queryBuilder, string $property, mixed
return;
}

$queryBuilder->andWhere(sprintf('%s IS NOT NULL', $options['alias_search']));
$queryBuilder->andWhere(\sprintf('%s IS NOT NULL', $options['alias_search']));
}
}
2 changes: 1 addition & 1 deletion src/Form/Filter/NullFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public function updateQueryBuilder(mixed $queryBuilder, string $property, mixed
return;
}

$queryBuilder->andWhere(sprintf('%s IS NULL', $options['alias_search']));
$queryBuilder->andWhere(\sprintf('%s IS NULL', $options['alias_search']));
}
}
2 changes: 1 addition & 1 deletion src/Form/Filter/TextFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function updateQueryBuilder(mixed $queryBuilder, string $property, mixed
$parameterName = 'value_text_'.str_replace(' ', '', $property);

if ($options['must_begin'] && $options['must_end']) {
$queryBuilder->andWhere(sprintf('%s = :%s', $options['alias_search'], $parameterName))
$queryBuilder->andWhere(\sprintf('%s = :%s', $options['alias_search'], $parameterName))
->setParameter($parameterName, $value);
} else {
$after = ($options['must_begin']) ? '' : '%';
Expand Down
4 changes: 2 additions & 2 deletions src/Form/Type/EntityAjaxType.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ public function configureOptions(OptionsResolver $resolver): void

$em = $this->registry->getManagerForClass($options['class']);
if (null === $em) {
throw new RuntimeException(sprintf('Class "%s" : Entity manager not found', $options['class']));
throw new RuntimeException(\sprintf('Class "%s" : Entity manager not found', $options['class']));
}

return $em;
};
$resolver->setNormalizer('em', $emNormalizer);

$queryBuilderNormalizer = function (Options $options, null|QueryBuilder|\Closure $queryBuilder): QueryBuilder {
$queryBuilderNormalizer = function (Options $options, QueryBuilder|\Closure|null $queryBuilder): QueryBuilder {
$em = $options['em'];
$class = $options['class'];

Expand Down
4 changes: 2 additions & 2 deletions src/Twig/CrudExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ protected function getAjaxAttributes(array $options): array
return $attributes;
}

public function crudIcon(Environment $environment, string $iconName, string $iconTheme = null): string
public function crudIcon(Environment $environment, string $iconName, ?string $iconTheme = null): string
{
if (null === $iconTheme) {
$iconTheme = $this->iconTheme;
Expand All @@ -723,7 +723,7 @@ protected function renderBlock(Environment $environment, string $templateName, s
return ob_get_clean();
}

protected function buildOptions(string $function, array $inlineOptions, Crud $crud = null): array
protected function buildOptions(string $function, array $inlineOptions, ?Crud $crud = null): array
{
$options = [];

Expand Down
2 changes: 1 addition & 1 deletion tests/Crud/AbstractCrudTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected function createCrud(array|CrudConfig $crudConfig, array $filters = [],
return $crud;
}

protected function createValidCrudConfig(CrudConfig $crudConfig = null, bool $withSearcher = false): CrudConfig
protected function createValidCrudConfig(?CrudConfig $crudConfig = null, bool $withSearcher = false): CrudConfig
{
$queryBuilder = self::getContainer()->get(ManagerRegistry::class)->getRepository(TestUser::class)
->createQueryBuilder('u')
Expand Down
2 changes: 1 addition & 1 deletion tests/Crud/CrudSessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ protected function setPropertyWithoutGetter(CrudSession $crudSession, string $pr
$reflectionMethod->setValue($crudSession, $value);
}

protected function createCrudSession(UserSearcher $searchFormData = null): CrudSession
protected function createCrudSession(?UserSearcher $searchFormData = null): CrudSession
{
return new CrudSession(100, ['col1'], 'sort1', Crud::ASC, $searchFormData);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Crud/SearchFormBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ protected function createCrudContainer(array $filters = []): ContainerInterface
return $container;
}

protected function createSearchFormBuilder(array $filters = null, Crud $crud = null, SearcherInterface $defaultData = null, string $type = null, array $options = []): SearchFormBuilder
protected function createSearchFormBuilder(?array $filters = null, ?Crud $crud = null, ?SearcherInterface $defaultData = null, ?string $type = null, array $options = []): SearchFormBuilder
{
$filters = (null !== $filters) ? $filters : ['my_filter' => $this->createMock(FilterInterface::class)];
$crud = ($crud) ?: $this->createCrud($this->createValidCrudConfig());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testTransform($choiceLabel, array $expected): void

public function getTestTransformProvider(): array
{
$closure = fn (Tag $tag) => sprintf('name: %s', $tag->getName());
$closure = fn (Tag $tag) => \sprintf('name: %s', $tag->getName());

return [
[null, ['1' => 'tag1', '3' => '3']], // Choice label: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected function createTransformer(...$args): DataTransformerInterface

public function getTestTransformProvider(): array
{
$closure = fn (Tag $tag) => sprintf('name: %s', $tag->getName());
$closure = fn (Tag $tag) => \sprintf('name: %s', $tag->getName());

return [
[null, ['1', '3']], // Choice label: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function testTransform($choiceLabel, $expected): void

public function getTestTransformProvider(): array
{
$closure = fn (Tag $tag) => sprintf('name: %s', $tag->getName());
$closure = fn (Tag $tag) => \sprintf('name: %s', $tag->getName());

return [
[null, ['3' => '3']], // Choice label: null
Expand Down
2 changes: 1 addition & 1 deletion tests/Form/DataTransformer/EntityToIdTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function createTransformer(...$args): DataTransformerInterface

public function getTestTransformProvider(): array
{
$closure = fn (Tag $tag) => sprintf('name: %s', $tag->getName());
$closure = fn (Tag $tag) => \sprintf('name: %s', $tag->getName());

return [
[null, '3'], // Choice label: null
Expand Down
Loading

0 comments on commit fd34aa9

Please sign in to comment.