Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored and github-actions[bot] committed Nov 13, 2024
1 parent 4a31428 commit 8c36483
Show file tree
Hide file tree
Showing 51 changed files with 119 additions and 120 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"friendsofphp/php-cs-fixer": "^3.4",
"matthiasnoback/symfony-dependency-injection-test": "^4.2 || ^5.0",
"phpstan/extension-installer": "^1.0",
"phpstan/phpdoc-parser": "^1.0",
"phpstan/phpstan": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpstan/phpstan-strict-rules": "^1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Block/AuditBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class AuditBlockService extends AbstractBlockService
{
public function __construct(
Environment $twig,
private AuditReader $auditReader
private AuditReader $auditReader,
) {
parent::__construct($twig);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Builder/DatagridBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(
private FormFactoryInterface $formFactory,
private FilterFactoryInterface $filterFactory,
private TypeGuesserInterface $guesser,
private bool $csrfTokenEnabled = true
private bool $csrfTokenEnabled = true,
) {
}

Expand Down Expand Up @@ -102,7 +102,7 @@ public function addFilter(DatagridInterface $datagrid, ?string $type, FieldDescr
if (null === $type) {
$guessType = $this->guesser->guess($fieldDescription);
if (null === $guessType) {
throw new \InvalidArgumentException(sprintf(
throw new \InvalidArgumentException(\sprintf(
'Cannot guess a type for the field description "%s", You MUST provide a type.',
$fieldDescription->getName()
));
Expand Down Expand Up @@ -143,7 +143,7 @@ public function getBaseDatagrid(AdminInterface $admin, array $values = []): Data

$query = $admin->createQuery();
if (!$query instanceof ProxyQueryInterface) {
throw new \TypeError(sprintf('The admin query MUST implement %s.', ProxyQueryInterface::class));
throw new \TypeError(\sprintf('The admin query MUST implement %s.', ProxyQueryInterface::class));
}
/** @phpstan-var ProxyQueryInterface<object> $query */

Expand All @@ -170,7 +170,7 @@ private function getPager(string $pagerType): PagerInterface
return $simplePager;

default:
throw new \RuntimeException(sprintf('Unknown pager type "%s".', $pagerType));
throw new \RuntimeException(\sprintf('Unknown pager type "%s".', $pagerType));
}
}
}
8 changes: 4 additions & 4 deletions src/Builder/ListBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ final class ListBuilder implements ListBuilderInterface
*/
public function __construct(
private TypeGuesserInterface $guesser,
private array $templates = []
private array $templates = [],
) {
}

Expand All @@ -46,7 +46,7 @@ public function buildField(?string $type, FieldDescriptionInterface $fieldDescri
if (null === $type) {
$guessType = $this->guesser->guess($fieldDescription);
if (null === $guessType) {
throw new \InvalidArgumentException(sprintf(
throw new \InvalidArgumentException(\sprintf(
'Cannot guess a type for the field description "%s", You MUST provide a type.',
$fieldDescription->getName()
));
Expand All @@ -72,7 +72,7 @@ public function fixFieldDescription(FieldDescriptionInterface $fieldDescription)
{
$type = $fieldDescription->getType();
if (null === $type) {
throw new \RuntimeException(sprintf(
throw new \RuntimeException(\sprintf(
'Please define a type for field `%s` in `%s`',
$fieldDescription->getName(),
$fieldDescription->getAdmin()::class
Expand Down Expand Up @@ -141,7 +141,7 @@ private function buildActionFieldDescription(FieldDescriptionInterface $fieldDes
$actions = $fieldDescription->getOption('actions');
foreach ($actions as $k => $action) {
if (!isset($action['template'])) {
$actions[$k]['template'] = sprintf('@SonataAdmin/CRUD/list__action_%s.html.twig', $k);
$actions[$k]['template'] = \sprintf('@SonataAdmin/CRUD/list__action_%s.html.twig', $k);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Builder/ShowBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class ShowBuilder implements ShowBuilderInterface
*/
public function __construct(
private TypeGuesserInterface $guesser,
private array $templates
private array $templates,
) {
}

Expand All @@ -44,7 +44,7 @@ public function addField(FieldDescriptionCollection $list, ?string $type, FieldD
if (null === $type) {
$guessType = $this->guesser->guess($fieldDescription);
if (null === $guessType) {
throw new \InvalidArgumentException(sprintf(
throw new \InvalidArgumentException(\sprintf(
'Cannot guess a type for the field description "%s", You MUST provide a type.',
$fieldDescription->getName()
));
Expand All @@ -65,7 +65,7 @@ public function fixFieldDescription(FieldDescriptionInterface $fieldDescription)
{
$type = $fieldDescription->getType();
if (null === $type) {
throw new \RuntimeException(sprintf(
throw new \RuntimeException(\sprintf(
'Please define a type for field `%s` in `%s`',
$fieldDescription->getName(),
$fieldDescription->getAdmin()::class
Expand Down
4 changes: 2 additions & 2 deletions src/Datagrid/Pager.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function getCurrentPageResults(): iterable
{
$query = $this->getQuery();
if (!$query instanceof ProxyQueryInterface) {
throw new \TypeError(sprintf('The pager query MUST implement %s.', ProxyQueryInterface::class));
throw new \TypeError(\sprintf('The pager query MUST implement %s.', ProxyQueryInterface::class));
}

$results = $query->execute();
Expand All @@ -55,7 +55,7 @@ public function init(): void
{
$query = $this->getQuery();
if (!$query instanceof ProxyQueryInterface) {
throw new \TypeError(sprintf('The pager query MUST implement %s.', ProxyQueryInterface::class));
throw new \TypeError(\sprintf('The pager query MUST implement %s.', ProxyQueryInterface::class));
}

$this->resultsCount = \count($query->execute());
Expand Down
6 changes: 3 additions & 3 deletions src/Datagrid/ProxyQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public function getSortBy(): ?string
public function setSortOrder(string $sortOrder): BaseProxyQueryInterface
{
if (!\in_array(strtoupper($sortOrder), $validSortOrders = ['ASC', 'DESC'], true)) {
throw new \InvalidArgumentException(sprintf(
throw new \InvalidArgumentException(\sprintf(
'"%s" is not a valid sort order, valid values are "%s"',
$sortOrder,
implode(', ', $validSortOrders)
Expand Down Expand Up @@ -294,7 +294,7 @@ public function entityJoin(array $associationMappings): string
/** @var literal-string $newAliasTmp */
$newAliasTmp = $joinExpr->getAlias() ?? '';

if (sprintf('%s.%s', $alias, $fieldName) === $joinExpr->getJoin()) {
if (\sprintf('%s.%s', $alias, $fieldName) === $joinExpr->getJoin()) {
$this->entityJoinAliases[] = $newAliasTmp;
$alias = $newAliasTmp;

Expand All @@ -306,7 +306,7 @@ public function entityJoin(array $associationMappings): string
$newAlias .= '_'.$fieldName;
if (!\in_array($newAlias, $this->entityJoinAliases, true)) {
$this->entityJoinAliases[] = $newAlias;
$this->queryBuilder->leftJoin(sprintf('%s.%s', $alias, $fieldName), $newAlias);
$this->queryBuilder->leftJoin(\sprintf('%s.%s', $alias, $fieldName), $newAlias);
}

$alias = $newAlias;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private function getModelName(ContainerBuilder $container, string $name): string
if ('%' === $name[0]) {
$parameter = $container->getParameter(substr($name, 1, -1));
if (!\is_string($parameter)) {
throw new \InvalidArgumentException(sprintf('Cannot find the model name "%s"', $name));
throw new \InvalidArgumentException(\sprintf('Cannot find the model name "%s"', $name));
}

return $parameter;
Expand Down
2 changes: 1 addition & 1 deletion src/Exporter/DataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class DataSource implements DataSourceInterface
public function createIterator(BaseProxyQueryInterface $query, array $fields): \Iterator
{
if (!$query instanceof ProxyQueryInterface) {
throw new \TypeError(sprintf('The query MUST implement %s.', ProxyQueryInterface::class));
throw new \TypeError(\sprintf('The query MUST implement %s.', ProxyQueryInterface::class));
}

$rootAlias = current($query->getQueryBuilder()->getRootAliases());
Expand Down
2 changes: 1 addition & 1 deletion src/FieldDescription/FieldDescriptionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private function getEntityManager(string $class): EntityManagerInterface
$em = $this->registry->getManagerForClass($class);

if (!$em instanceof EntityManagerInterface) {
throw new \UnexpectedValueException(sprintf('No entity manager defined for class "%s".', $class));
throw new \UnexpectedValueException(\sprintf('No entity manager defined for class "%s".', $class));
}

return $em;
Expand Down
16 changes: 8 additions & 8 deletions src/Filter/AbstractDateFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ final public function filter(ProxyQueryInterface $query, string $alias, string $
$type = DateOperatorType::TYPE_GREATER_EQUAL;

$endDateParameterName = $this->getNewParameterName($query);
$this->applyWhere($query, sprintf('%s.%s %s :%s', $alias, $field, '<', $endDateParameterName));
$this->applyWhere($query, \sprintf('%s.%s %s :%s', $alias, $field, '<', $endDateParameterName));

if ('timestamp' === $this->getOption('input_type')) {
$endValue = strtotime('+1 day', $value->getTimestamp());
Expand All @@ -92,7 +92,7 @@ final public function filter(ProxyQueryInterface $query, string $alias, string $
$value = 'timestamp' === $this->getOption('input_type') ? $value->getTimestamp() : $value;

$parameterName = $this->getNewParameterName($query);
$this->applyWhere($query, sprintf('%s.%s %s :%s', $alias, $field, $operator, $parameterName));
$this->applyWhere($query, \sprintf('%s.%s %s :%s', $alias, $field, $operator, $parameterName));
$query->getQueryBuilder()->setParameter($parameterName, $value, $this->getParameterType($value));
}

Expand Down Expand Up @@ -161,19 +161,19 @@ private function filterRange(ProxyQueryInterface $query, string $alias, string $

if (DateRangeOperatorType::TYPE_NOT_BETWEEN === $type) {
if (null !== $value['start'] && null !== $value['end']) {
$this->applyWhere($query, sprintf('%s.%s < :%s OR %s.%s > :%s', $alias, $field, $startDateParameterName, $alias, $field, $endDateParameterName));
$this->applyWhere($query, \sprintf('%s.%s < :%s OR %s.%s > :%s', $alias, $field, $startDateParameterName, $alias, $field, $endDateParameterName));
} elseif (null !== $value['start']) {
$this->applyWhere($query, sprintf('%s.%s %s :%s', $alias, $field, '<', $startDateParameterName));
$this->applyWhere($query, \sprintf('%s.%s %s :%s', $alias, $field, '<', $startDateParameterName));
} elseif (null !== $value['end']) {
$this->applyWhere($query, sprintf('%s.%s %s :%s', $alias, $field, '>', $endDateParameterName));
$this->applyWhere($query, \sprintf('%s.%s %s :%s', $alias, $field, '>', $endDateParameterName));
}
} else {
if (null !== $value['start']) {
$this->applyWhere($query, sprintf('%s.%s %s :%s', $alias, $field, '>=', $startDateParameterName));
$this->applyWhere($query, \sprintf('%s.%s %s :%s', $alias, $field, '>=', $startDateParameterName));
}

if (null !== $value['end']) {
$this->applyWhere($query, sprintf('%s.%s %s :%s', $alias, $field, '<=', $endDateParameterName));
$this->applyWhere($query, \sprintf('%s.%s %s :%s', $alias, $field, '<=', $endDateParameterName));
}
}

Expand Down Expand Up @@ -212,7 +212,7 @@ private function getParameterType($parameter): string
private function getOperator(int $type): string
{
if (!isset(self::CHOICES[$type])) {
throw new \OutOfRangeException(sprintf(
throw new \OutOfRangeException(\sprintf(
'The type "%s" is not supported, allowed one are "%s".',
$type,
implode('", "', array_keys(self::CHOICES))
Expand Down
8 changes: 4 additions & 4 deletions src/Filter/BooleanFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ private function filterWithMultipleValues(ProxyQueryInterface $query, string $al
false === $treatNullAs && \in_array(0, $values, true)
|| true === $treatNullAs && \in_array(1, $values, true)
) {
$or->add($query->getQueryBuilder()->expr()->isNull(sprintf('%s.%s', $alias, $field)));
$or->add($query->getQueryBuilder()->expr()->isNull(\sprintf('%s.%s', $alias, $field)));
}

$or->add($query->getQueryBuilder()->expr()->in(sprintf('%s.%s', $alias, $field), $values));
$or->add($query->getQueryBuilder()->expr()->in(\sprintf('%s.%s', $alias, $field), $values));

$this->applyWhere($query, $or);
}
Expand All @@ -100,11 +100,11 @@ private function filterWithSingleValue(ProxyQueryInterface $query, string $alias
false === $treatNullAs && BooleanType::TYPE_NO === $data->getValue()
|| true === $treatNullAs && BooleanType::TYPE_YES === $data->getValue()
) {
$or->add($query->getQueryBuilder()->expr()->isNull(sprintf('%s.%s', $alias, $field)));
$or->add($query->getQueryBuilder()->expr()->isNull(\sprintf('%s.%s', $alias, $field)));
}

$parameterName = $this->getNewParameterName($query);
$or->add(sprintf('%s.%s = :%s', $alias, $field, $parameterName));
$or->add(\sprintf('%s.%s = :%s', $alias, $field, $parameterName));
$query->getQueryBuilder()->setParameter($parameterName, (BooleanType::TYPE_YES === $data->getValue()) ? 1 : 0);

$this->applyWhere($query, $or);
Expand Down
4 changes: 2 additions & 2 deletions src/Filter/CallbackFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ final class CallbackFilter extends Filter
public function filter(ProxyQueryInterface $query, string $alias, string $field, FilterData $data): void
{
if (!\is_callable($this->getOption('callback'))) {
throw new \RuntimeException(sprintf('Please provide a valid callback option "filter" for field "%s"', $this->getName()));
throw new \RuntimeException(\sprintf('Please provide a valid callback option "filter" for field "%s"', $this->getName()));
}

$isActive = \call_user_func($this->getOption('callback'), $query, $alias, $field, $data);
if (!\is_bool($isActive)) {
throw new \UnexpectedValueException(sprintf(
throw new \UnexpectedValueException(\sprintf(
'The callback should return a boolean, %s returned',
\is_object($isActive) ? 'instance of "'.$isActive::class.'"' : '"'.\gettype($isActive).'"'
));
Expand Down
8 changes: 4 additions & 4 deletions src/Filter/ChoiceFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private function filterWithMultipleValues(ProxyQueryInterface $query, string $al
}

$isNullSelected = \in_array(null, $data->getValue(), true);
$completeField = sprintf('%s.%s', $alias, $field);
$completeField = \sprintf('%s.%s', $alias, $field);
$parameterName = $this->getNewParameterName($query);

$or = $query->getQueryBuilder()->expr()->orX();
Expand Down Expand Up @@ -96,23 +96,23 @@ private function filterWithSingleValue(ProxyQueryInterface $query, string $alias
}

$parameterName = $this->getNewParameterName($query);
$completeField = sprintf('%s.%s', $alias, $field);
$completeField = \sprintf('%s.%s', $alias, $field);

if ($data->isType(EqualOperatorType::TYPE_NOT_EQUAL)) {
if (null === $data->getValue()) {
$this->applyWhere($query, $query->getQueryBuilder()->expr()->isNotNull($completeField));
} else {
$this->applyWhere(
$query,
sprintf('%s != :%s OR %s IS NULL', $completeField, $parameterName, $completeField)
\sprintf('%s != :%s OR %s IS NULL', $completeField, $parameterName, $completeField)
);
$query->getQueryBuilder()->setParameter($parameterName, $data->getValue());
}
} else {
if (null === $data->getValue()) {
$this->applyWhere($query, $query->getQueryBuilder()->expr()->isNull($completeField));
} else {
$this->applyWhere($query, sprintf('%s = :%s', $completeField, $parameterName));
$this->applyWhere($query, \sprintf('%s = :%s', $completeField, $parameterName));
$query->getQueryBuilder()->setParameter($parameterName, $data->getValue());
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Filter/ClassFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function filter(ProxyQueryInterface $query, string $alias, string $field,
$type = $data->getType() ?? EqualOperatorType::TYPE_EQUAL;
$operator = $this->getOperator($type);

$this->applyWhere($query, sprintf('%s %s %s', $alias, $operator, $data->getValue()));
$this->applyWhere($query, \sprintf('%s %s %s', $alias, $operator, $data->getValue()));
}

public function getDefaultOptions(): array
Expand Down Expand Up @@ -74,7 +74,7 @@ public function getFormOptions(): array
private function getOperator(int $type): string
{
if (!isset(self::CHOICES[$type])) {
throw new \OutOfRangeException(sprintf(
throw new \OutOfRangeException(\sprintf(
'The type "%s" is not supported, allowed one are "%s".',
$type,
implode('", "', array_keys(self::CHOICES))
Expand Down
4 changes: 2 additions & 2 deletions src/Filter/CountFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function filter(ProxyQueryInterface $query, string $alias, string $field,
}

$query->getQueryBuilder()->addGroupBy($rootAlias);
$this->applyHaving($query, sprintf('COUNT(%s.%s) %s :%s', $alias, $field, $operator, $parameterName));
$this->applyHaving($query, \sprintf('COUNT(%s.%s) %s :%s', $alias, $field, $operator, $parameterName));
$query->getQueryBuilder()->setParameter($parameterName, $data->getValue());
}

Expand All @@ -73,7 +73,7 @@ public function getFormOptions(): array
private function getOperator(int $type): string
{
if (!isset(self::CHOICES[$type])) {
throw new \OutOfRangeException(sprintf(
throw new \OutOfRangeException(\sprintf(
'The type "%s" is not supported, allowed one are "%s".',
$type,
implode('", "', array_keys(self::CHOICES))
Expand Down
4 changes: 2 additions & 2 deletions src/Filter/EmptyFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public function filter(ProxyQueryInterface $query, string $alias, string $field,
if (!$inverse && $isYes || $inverse && $isNo) {
$this->applyWhere(
$query,
sprintf('%s.%s IS EMPTY', $alias, $field)
\sprintf('%s.%s IS EMPTY', $alias, $field)
);
} else {
$this->applyWhere(
$query,
sprintf('%s.%s IS NOT EMPTY', $alias, $field)
\sprintf('%s.%s IS NOT EMPTY', $alias, $field)
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Filter/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ abstract public function filter(ProxyQueryInterface $query, string $alias, strin
final public function apply(BaseProxyQueryInterface $query, FilterData $filterData): void
{
if (!$query instanceof ProxyQueryInterface) {
throw new \TypeError(sprintf('The query MUST implement %s.', ProxyQueryInterface::class));
throw new \TypeError(\sprintf('The query MUST implement %s.', ProxyQueryInterface::class));
}

if ($filterData->hasValue()) {
Expand All @@ -53,7 +53,7 @@ public function setConditionGroup(Composite $conditionGroup): void
public function getConditionGroup(): Composite
{
if (!$this->hasConditionGroup()) {
throw new \LogicException(sprintf('Filter "%s" has no condition group.', $this->getName()));
throw new \LogicException(\sprintf('Filter "%s" has no condition group.', $this->getName()));
}
\assert(null !== $this->conditionGroup);

Expand Down
Loading

0 comments on commit 8c36483

Please sign in to comment.