From a2b4d5dd51c5feb5a24fb15a5cb9f8d8f37663de Mon Sep 17 00:00:00 2001 From: SonataCI Date: Wed, 13 Nov 2024 10:50:02 +0000 Subject: [PATCH 1/3] DevKit updates --- rector.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rector.php b/rector.php index b6dac16fc..744632387 100644 --- a/rector.php +++ b/rector.php @@ -19,6 +19,7 @@ use Rector\Config\RectorConfig; use Rector\Php70\Rector\FunctionLike\ExceptionHandlerTypehintRector; +use Rector\PHPUnit\CodeQuality\Rector\Class_\NarrowUnusedSetUpDefinedPropertyRector; use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector; use Rector\PHPUnit\Set\PHPUnitSetList; use Rector\Set\ValueObject\LevelSetList; @@ -40,5 +41,6 @@ $rectorConfig->skip([ ExceptionHandlerTypehintRector::class, PreferPHPUnitThisCallRector::class, + NarrowUnusedSetUpDefinedPropertyRector::class, ]); }; From 38787a78fd7717f89d005f29889a4cbf8c2273d5 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Wed, 13 Nov 2024 14:57:16 +0100 Subject: [PATCH 2/3] Fix --- composer.json | 1 + src/Block/AuditBlockService.php | 2 +- src/Builder/DatagridBuilder.php | 8 ++--- src/Builder/ListBuilder.php | 8 ++--- src/Builder/ShowBuilder.php | 6 ++-- src/Datagrid/Pager.php | 4 +-- src/Datagrid/ProxyQuery.php | 6 ++-- .../Compiler/AddAuditEntityCompilerPass.php | 2 +- src/Exporter/DataSource.php | 2 +- .../FieldDescriptionFactory.php | 2 +- src/Filter/AbstractDateFilter.php | 16 +++++----- src/Filter/BooleanFilter.php | 8 ++--- src/Filter/CallbackFilter.php | 4 +-- src/Filter/ChoiceFilter.php | 8 ++--- src/Filter/ClassFilter.php | 4 +-- src/Filter/CountFilter.php | 4 +-- src/Filter/EmptyFilter.php | 4 +-- src/Filter/Filter.php | 4 +-- src/Filter/ModelAutocompleteFilter.php | 4 +-- src/Filter/ModelFilter.php | 8 ++--- src/Filter/NullFilter.php | 4 +-- src/Filter/NumberFilter.php | 4 +-- src/Filter/StringFilter.php | 8 ++--- src/Filter/StringListFilter.php | 4 +-- src/Filter/UidFilter.php | 4 +-- src/Model/ModelManager.php | 30 +++++++++---------- src/Util/ObjectAclManipulator.php | 8 ++--- tests/App/Admin/AuthorAdmin.php | 2 +- tests/App/AppKernel.php | 2 +- tests/App/Entity/Address.php | 2 +- tests/App/Entity/Author.php | 2 +- tests/App/Entity/Book.php | 2 +- tests/App/Entity/Car.php | 2 +- tests/App/Entity/Category.php | 2 +- tests/App/Entity/Command.php | 2 +- tests/App/Entity/Item.php | 2 +- tests/App/Entity/Product.php | 2 +- tests/App/Entity/ProductAttribute.php | 2 +- tests/App/Entity/UlidChildEntity.php | 2 +- tests/App/Entity/UuidEntity.php | 2 +- .../FilterTypeGuesserTest.php | 2 +- tests/FieldDescription/TypeGuesserTest.php | 2 +- tests/Filter/CallbackFilterTest.php | 6 ++-- tests/Filter/DateRangeFilterTest.php | 2 +- tests/Filter/FilterTestCase.php | 8 ++--- tests/Filter/StringFilterTest.php | 10 +++---- tests/Fixtures/Entity/AssociatedEntity.php | 2 +- tests/Fixtures/Entity/ContainerEntity.php | 2 +- tests/Fixtures/Entity/DoubleNameEntity.php | 2 +- tests/Fixtures/Entity/Product.php | 2 +- tests/Model/ModelManagerTest.php | 8 ++--- 51 files changed, 119 insertions(+), 120 deletions(-) diff --git a/composer.json b/composer.json index ebd7945d6..f6797de62 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/src/Block/AuditBlockService.php b/src/Block/AuditBlockService.php index a5c39d7d8..4b190cb8e 100644 --- a/src/Block/AuditBlockService.php +++ b/src/Block/AuditBlockService.php @@ -27,7 +27,7 @@ final class AuditBlockService extends AbstractBlockService { public function __construct( Environment $twig, - private AuditReader $auditReader + private AuditReader $auditReader, ) { parent::__construct($twig); } diff --git a/src/Builder/DatagridBuilder.php b/src/Builder/DatagridBuilder.php index 7514096aa..0e69657b6 100644 --- a/src/Builder/DatagridBuilder.php +++ b/src/Builder/DatagridBuilder.php @@ -44,7 +44,7 @@ public function __construct( private FormFactoryInterface $formFactory, private FilterFactoryInterface $filterFactory, private TypeGuesserInterface $guesser, - private bool $csrfTokenEnabled = true + private bool $csrfTokenEnabled = true, ) { } @@ -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() )); @@ -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 $query */ @@ -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)); } } } diff --git a/src/Builder/ListBuilder.php b/src/Builder/ListBuilder.php index f1fcd4d6d..a57a6a1d4 100644 --- a/src/Builder/ListBuilder.php +++ b/src/Builder/ListBuilder.php @@ -32,7 +32,7 @@ final class ListBuilder implements ListBuilderInterface */ public function __construct( private TypeGuesserInterface $guesser, - private array $templates = [] + private array $templates = [], ) { } @@ -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() )); @@ -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 @@ -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); } } diff --git a/src/Builder/ShowBuilder.php b/src/Builder/ShowBuilder.php index 848a160c1..152b0c97e 100644 --- a/src/Builder/ShowBuilder.php +++ b/src/Builder/ShowBuilder.php @@ -30,7 +30,7 @@ final class ShowBuilder implements ShowBuilderInterface */ public function __construct( private TypeGuesserInterface $guesser, - private array $templates + private array $templates, ) { } @@ -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() )); @@ -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 diff --git a/src/Datagrid/Pager.php b/src/Datagrid/Pager.php index d5d77f160..ec8245f6c 100644 --- a/src/Datagrid/Pager.php +++ b/src/Datagrid/Pager.php @@ -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(); @@ -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()); diff --git a/src/Datagrid/ProxyQuery.php b/src/Datagrid/ProxyQuery.php index 35ae4247a..29616e5a5 100644 --- a/src/Datagrid/ProxyQuery.php +++ b/src/Datagrid/ProxyQuery.php @@ -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) @@ -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; @@ -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; diff --git a/src/DependencyInjection/Compiler/AddAuditEntityCompilerPass.php b/src/DependencyInjection/Compiler/AddAuditEntityCompilerPass.php index 5841e7be6..a46796a4c 100755 --- a/src/DependencyInjection/Compiler/AddAuditEntityCompilerPass.php +++ b/src/DependencyInjection/Compiler/AddAuditEntityCompilerPass.php @@ -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; diff --git a/src/Exporter/DataSource.php b/src/Exporter/DataSource.php index 997063bd3..ec47b7233 100644 --- a/src/Exporter/DataSource.php +++ b/src/Exporter/DataSource.php @@ -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()); diff --git a/src/FieldDescription/FieldDescriptionFactory.php b/src/FieldDescription/FieldDescriptionFactory.php index 12b9e3b04..41ea51f53 100644 --- a/src/FieldDescription/FieldDescriptionFactory.php +++ b/src/FieldDescription/FieldDescriptionFactory.php @@ -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; diff --git a/src/Filter/AbstractDateFilter.php b/src/Filter/AbstractDateFilter.php index f78d9167c..8b143cc64 100644 --- a/src/Filter/AbstractDateFilter.php +++ b/src/Filter/AbstractDateFilter.php @@ -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()); @@ -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)); } @@ -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)); } } @@ -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)) diff --git a/src/Filter/BooleanFilter.php b/src/Filter/BooleanFilter.php index b70d36439..19ab10c0a 100644 --- a/src/Filter/BooleanFilter.php +++ b/src/Filter/BooleanFilter.php @@ -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); } @@ -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); diff --git a/src/Filter/CallbackFilter.php b/src/Filter/CallbackFilter.php index 11efe1fa9..f1416d438 100644 --- a/src/Filter/CallbackFilter.php +++ b/src/Filter/CallbackFilter.php @@ -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).'"' )); diff --git a/src/Filter/ChoiceFilter.php b/src/Filter/ChoiceFilter.php index a6c084dfa..72a39094e 100644 --- a/src/Filter/ChoiceFilter.php +++ b/src/Filter/ChoiceFilter.php @@ -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(); @@ -96,7 +96,7 @@ 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()) { @@ -104,7 +104,7 @@ private function filterWithSingleValue(ProxyQueryInterface $query, string $alias } 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()); } @@ -112,7 +112,7 @@ private function filterWithSingleValue(ProxyQueryInterface $query, string $alias 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()); } } diff --git a/src/Filter/ClassFilter.php b/src/Filter/ClassFilter.php index 9b070683c..462f0b3e8 100644 --- a/src/Filter/ClassFilter.php +++ b/src/Filter/ClassFilter.php @@ -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 @@ -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)) diff --git a/src/Filter/CountFilter.php b/src/Filter/CountFilter.php index 16fc45c10..6a5c83410 100644 --- a/src/Filter/CountFilter.php +++ b/src/Filter/CountFilter.php @@ -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()); } @@ -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)) diff --git a/src/Filter/EmptyFilter.php b/src/Filter/EmptyFilter.php index 50e4c0069..077df9e24 100644 --- a/src/Filter/EmptyFilter.php +++ b/src/Filter/EmptyFilter.php @@ -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) ); } } diff --git a/src/Filter/Filter.php b/src/Filter/Filter.php index 925d7e117..fef83a033 100644 --- a/src/Filter/Filter.php +++ b/src/Filter/Filter.php @@ -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()) { @@ -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); diff --git a/src/Filter/ModelAutocompleteFilter.php b/src/Filter/ModelAutocompleteFilter.php index ebb57be9c..5608e19e0 100644 --- a/src/Filter/ModelAutocompleteFilter.php +++ b/src/Filter/ModelAutocompleteFilter.php @@ -111,9 +111,9 @@ private function handleModel(ProxyQueryInterface $query, string $alias, FilterDa $parameterName = $this->getNewParameterName($query); if ($data->isType(EqualOperatorType::TYPE_NOT_EQUAL)) { - $this->applyWhere($query, sprintf('%s != :%s', $alias, $parameterName)); + $this->applyWhere($query, \sprintf('%s != :%s', $alias, $parameterName)); } else { - $this->applyWhere($query, sprintf('%s = :%s', $alias, $parameterName)); + $this->applyWhere($query, \sprintf('%s = :%s', $alias, $parameterName)); } $query->getQueryBuilder()->setParameter($parameterName, $data->getValue()); diff --git a/src/Filter/ModelFilter.php b/src/Filter/ModelFilter.php index 010c52355..c7bed61af 100644 --- a/src/Filter/ModelFilter.php +++ b/src/Filter/ModelFilter.php @@ -81,11 +81,11 @@ protected function handleMultiple(ProxyQueryInterface $query, string $alias, Fil if ($data->isType(EqualOperatorType::TYPE_NOT_EQUAL)) { if (false === ($this->getAssociationMapping()['isOwningSide'] ?? true)) { - $nullExpression = sprintf('IDENTITY(%s.%s) IS NULL', $alias, $this->getAssociationMapping()['mappedBy']); + $nullExpression = \sprintf('IDENTITY(%s.%s) IS NULL', $alias, $this->getAssociationMapping()['mappedBy']); } else { $nullExpression = ClassMetadata::MANY_TO_MANY === $this->getAssociationMapping()['type'] - ? sprintf('%s.%s IS EMPTY', $this->getParentAlias($query, $alias), $this->getFieldName()) - : sprintf('IDENTITY(%s.%s) IS NULL', $this->getParentAlias($query, $alias), $this->getFieldName()); + ? \sprintf('%s.%s IS EMPTY', $this->getParentAlias($query, $alias), $this->getFieldName()) + : \sprintf('IDENTITY(%s.%s) IS NULL', $this->getParentAlias($query, $alias), $this->getFieldName()); } $inExpression = $query->getQueryBuilder()->expr()->orX( @@ -158,7 +158,7 @@ private function buildInExpression(ProxyQueryInterface $query, string $alias, Fi foreach ($metadata->getIdentifierValues($value) as $fieldName => $identifierValue) { $parameterName = $this->getNewParameterName($query); - $andX->add($queryBuilder->expr()->eq(sprintf('%s.%s', $alias, $fieldName), ':'.$parameterName)); + $andX->add($queryBuilder->expr()->eq(\sprintf('%s.%s', $alias, $fieldName), ':'.$parameterName)); $queryBuilder->setParameter( $parameterName, $identifierValue, diff --git a/src/Filter/NullFilter.php b/src/Filter/NullFilter.php index 8234b8d94..403840566 100644 --- a/src/Filter/NullFilter.php +++ b/src/Filter/NullFilter.php @@ -35,12 +35,12 @@ public function filter(ProxyQueryInterface $query, string $alias, string $field, if (!$inverse && $isYes || $inverse && $isNo) { $this->applyWhere( $query, - $query->getQueryBuilder()->expr()->isNull(sprintf('%s.%s', $alias, $field)) + $query->getQueryBuilder()->expr()->isNull(\sprintf('%s.%s', $alias, $field)) ); } else { $this->applyWhere( $query, - $query->getQueryBuilder()->expr()->isNotNull(sprintf('%s.%s', $alias, $field)) + $query->getQueryBuilder()->expr()->isNotNull(\sprintf('%s.%s', $alias, $field)) ); } } diff --git a/src/Filter/NumberFilter.php b/src/Filter/NumberFilter.php index 9d3f76e87..18acaae88 100644 --- a/src/Filter/NumberFilter.php +++ b/src/Filter/NumberFilter.php @@ -39,7 +39,7 @@ public function filter(ProxyQueryInterface $query, string $alias, string $field, // c.name > '1' => c.name OPERATOR :FIELDNAME $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, $data->getValue()); } @@ -66,7 +66,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)) diff --git a/src/Filter/StringFilter.php b/src/Filter/StringFilter.php index 6e441bd45..dfe6917b6 100644 --- a/src/Filter/StringFilter.php +++ b/src/Filter/StringFilter.php @@ -76,11 +76,11 @@ public function filter(ProxyQueryInterface $query, string $alias, string $field, } $or = $query->getQueryBuilder()->expr()->orX( - sprintf($clause, $alias, $field, $operator, $parameterName) + \sprintf($clause, $alias, $field, $operator, $parameterName) ); if (StringOperatorType::TYPE_NOT_CONTAINS === $type || StringOperatorType::TYPE_NOT_EQUAL === $type) { - $or->add($query->getQueryBuilder()->expr()->isNull(sprintf('%s.%s', $alias, $field))); + $or->add($query->getQueryBuilder()->expr()->isNull(\sprintf('%s.%s', $alias, $field))); } $this->applyWhere($query, $or); @@ -94,7 +94,7 @@ public function filter(ProxyQueryInterface $query, string $alias, string $field, $query->getQueryBuilder()->setParameter( $parameterName, - sprintf( + \sprintf( $format, $forceCaseInsensitivity && '' !== $value ? mb_strtolower($value) : $value ) @@ -132,7 +132,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)) diff --git a/src/Filter/StringListFilter.php b/src/Filter/StringListFilter.php index d7450be26..a5e90ce51 100644 --- a/src/Filter/StringListFilter.php +++ b/src/Filter/StringListFilter.php @@ -36,13 +36,13 @@ public function filter(ProxyQueryInterface $query, string $alias, string $field, $andConditions = $query->getQueryBuilder()->expr()->andX(); foreach ($data->getValue() as $item) { $parameterName = $this->getNewParameterName($query); - $andConditions->add(sprintf('%s.%s %s :%s', $alias, $field, $operator, $parameterName)); + $andConditions->add(\sprintf('%s.%s %s :%s', $alias, $field, $operator, $parameterName)); $query->getQueryBuilder()->setParameter($parameterName, '%'.serialize($item).'%'); } if ($data->isType(ContainsOperatorType::TYPE_EQUAL)) { - $andConditions->add(sprintf("%s.%s LIKE 'a:%s:%%'", $alias, $field, \count($data->getValue()))); + $andConditions->add(\sprintf("%s.%s LIKE 'a:%s:%%'", $alias, $field, \count($data->getValue()))); } $this->applyWhere($query, $andConditions); diff --git a/src/Filter/UidFilter.php b/src/Filter/UidFilter.php index 256463c31..be984f7f8 100644 --- a/src/Filter/UidFilter.php +++ b/src/Filter/UidFilter.php @@ -44,7 +44,7 @@ public function filter(ProxyQueryInterface $query, string $alias, string $field, $operator = $this->getOperator($data->getType() ?? EqualOperatorType::TYPE_EQUAL); $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, $uidValue, $this->getParameterType($uidValue)); } @@ -93,7 +93,7 @@ private function convertToUid(string $value): ?AbstractUid 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)) diff --git a/src/Model/ModelManager.php b/src/Model/ModelManager.php index 4230ef017..9509afd2b 100644 --- a/src/Model/ModelManager.php +++ b/src/Model/ModelManager.php @@ -54,7 +54,7 @@ final class ModelManager implements ModelManagerInterface, LockInterface, ProxyR public function __construct( private ManagerRegistry $registry, - private PropertyAccessorInterface $propertyAccessor + private PropertyAccessorInterface $propertyAccessor, ) { } @@ -82,7 +82,7 @@ public function create(object $object): void $entityManager->flush(); } catch (\PDOException|Exception $exception) { throw new ModelManagerException( - sprintf('Failed to create object: %s', $this->getRealClass($object)), + \sprintf('Failed to create object: %s', $this->getRealClass($object)), (int) $exception->getCode(), $exception ); @@ -97,7 +97,7 @@ public function update(object $object): void $entityManager->flush(); } catch (\PDOException|Exception $exception) { throw new ModelManagerException( - sprintf('Failed to update object: %s', $this->getRealClass($object)), + \sprintf('Failed to update object: %s', $this->getRealClass($object)), (int) $exception->getCode(), $exception ); @@ -112,7 +112,7 @@ public function delete(object $object): void $entityManager->flush(); } catch (\PDOException|Exception $exception) { throw new ModelManagerException( - sprintf('Failed to delete object: %s', $this->getRealClass($object)), + \sprintf('Failed to delete object: %s', $this->getRealClass($object)), (int) $exception->getCode(), $exception ); @@ -198,7 +198,7 @@ public function getEntityManager($class): EntityManagerInterface $em = $this->registry->getManagerForClass($class); if (!$em instanceof EntityManagerInterface) { - throw new \RuntimeException(sprintf('No entity manager defined for class %s', $class)); + throw new \RuntimeException(\sprintf('No entity manager defined for class %s', $class)); } $this->cache[$class] = $em; @@ -238,7 +238,7 @@ public function executeQuery(object $query) return $results; } - throw new \InvalidArgumentException(sprintf( + throw new \InvalidArgumentException(\sprintf( 'Argument 1 passed to %s() must be an instance of %s, %s, or %s', __METHOD__, QueryBuilder::class, @@ -316,11 +316,11 @@ public function getUrlSafeIdentifier(object $model): ?string public function addIdentifiersToQuery(string $class, BaseProxyQueryInterface $query, array $idx): 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 ([] === $idx) { - throw new \InvalidArgumentException(sprintf( + throw new \InvalidArgumentException(\sprintf( 'Array passed as argument 3 to "%s()" must not be empty.', __METHOD__ )); @@ -338,8 +338,8 @@ public function addIdentifiersToQuery(string $class, BaseProxyQueryInterface $qu $ands = []; foreach ($fieldNames as $index => $name) { - $parameterName = sprintf('field_%s_%s_%d', $prefix, $name, $pos); - $ands[] = sprintf('%s.%s = :%s', $rootAlias, $name, $parameterName); + $parameterName = \sprintf('field_%s_%s_%d', $prefix, $name, $pos); + $ands[] = \sprintf('%s.%s = :%s', $rootAlias, $name, $parameterName); $qb->setParameter( $parameterName, $ids[$index], @@ -350,13 +350,13 @@ public function addIdentifiersToQuery(string $class, BaseProxyQueryInterface $qu $sqls[] = implode(' AND ', $ands); } - $qb->andWhere(sprintf('( %s )', implode(' OR ', $sqls))); + $qb->andWhere(\sprintf('( %s )', implode(' OR ', $sqls))); } public function batchDelete(string $class, BaseProxyQueryInterface $query, int $batchSize = self::BATCH_SIZE): 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 ([] !== $query->getQueryBuilder()->getDQLPart('join')) { @@ -394,7 +394,7 @@ public function batchDelete(string $class, BaseProxyQueryInterface $query, int $ if (null === $id) { throw new ModelManagerException( - sprintf('Failed to perform batch deletion for "%s" objects', $class), + \sprintf('Failed to perform batch deletion for "%s" objects', $class), (int) $exception->getCode(), $exception ); @@ -402,11 +402,11 @@ public function batchDelete(string $class, BaseProxyQueryInterface $query, int $ $msg = 'Failed to delete object "%s" (id: %s) while performing batch deletion'; if ($i > $batchSize) { - $msg .= sprintf(' (%u objects were successfully deleted before this error)', $confirmedDeletionsCount); + $msg .= \sprintf(' (%u objects were successfully deleted before this error)', $confirmedDeletionsCount); } throw new ModelManagerException( - sprintf( + \sprintf( $msg, $class, $id diff --git a/src/Util/ObjectAclManipulator.php b/src/Util/ObjectAclManipulator.php index 5884a703e..4e18193dd 100644 --- a/src/Util/ObjectAclManipulator.php +++ b/src/Util/ObjectAclManipulator.php @@ -39,7 +39,7 @@ public function batchConfigureAcls(OutputInterface $output, AdminInterface $admi return; } - $output->writeln(sprintf(' > generate ACLs for %s', $admin->getCode())); + $output->writeln(\sprintf(' > generate ACLs for %s', $admin->getCode())); $objectOwnersMsg = null === $securityIdentity ? '' : ' and set the object owner'; $class = $admin->getClass(); @@ -71,7 +71,7 @@ public function batchConfigureAcls(OutputInterface $output, AdminInterface $admi } if (0 === ($count % $batchSizeOutput)) { - $output->writeln(sprintf(' - generated class ACEs%s for %s objects (added %s, updated %s)', $objectOwnersMsg, $count, $countAdded, $countUpdated)); + $output->writeln(\sprintf(' - generated class ACEs%s for %s objects (added %s, updated %s)', $objectOwnersMsg, $count, $countAdded, $countUpdated)); } } @@ -82,13 +82,13 @@ public function batchConfigureAcls(OutputInterface $output, AdminInterface $admi } } catch (\PDOException|Exception $e) { throw new ModelManagerException( - sprintf('Failed to configure acl for class: %s', $class), + \sprintf('Failed to configure acl for class: %s', $class), (int) $e->getCode(), $e ); } - $output->writeln(sprintf( + $output->writeln(\sprintf( ' - [TOTAL] generated class ACEs%s for %s objects (added %s, updated %s)', $objectOwnersMsg, $count, diff --git a/tests/App/Admin/AuthorAdmin.php b/tests/App/Admin/AuthorAdmin.php index 2df790400..ba7484db7 100644 --- a/tests/App/Admin/AuthorAdmin.php +++ b/tests/App/Admin/AuthorAdmin.php @@ -90,7 +90,7 @@ protected function configureQuery(ProxyQueryInterface $query): ProxyQueryInterfa ->getQueryBuilder() ->addSelect('book') ->addSelect('reader') - ->leftJoin(sprintf('%s.books', $alias), 'book') + ->leftJoin(\sprintf('%s.books', $alias), 'book') ->leftJoin('book.readers', 'reader'); return $query; diff --git a/tests/App/AppKernel.php b/tests/App/AppKernel.php index c0950b09e..314488ea4 100644 --- a/tests/App/AppKernel.php +++ b/tests/App/AppKernel.php @@ -75,7 +75,7 @@ public function getProjectDir(): string protected function configureRoutes(RoutingConfigurator $routes): void { - $routes->import(sprintf('%s/config/routes.yaml', $this->getProjectDir())); + $routes->import(\sprintf('%s/config/routes.yaml', $this->getProjectDir())); } protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void diff --git a/tests/App/Entity/Address.php b/tests/App/Entity/Address.php index 9ece3a5ac..2b73840fd 100644 --- a/tests/App/Entity/Address.php +++ b/tests/App/Entity/Address.php @@ -21,7 +21,7 @@ class Address implements \Stringable { public function __construct( #[ORM\Column(type: Types::STRING)] - private string $street = '' + private string $street = '', ) { } diff --git a/tests/App/Entity/Author.php b/tests/App/Entity/Author.php index bac6e5b0c..76bed3b97 100644 --- a/tests/App/Entity/Author.php +++ b/tests/App/Entity/Author.php @@ -36,7 +36,7 @@ public function __construct( #[ORM\GeneratedValue(strategy: 'NONE')] private string $id = '', #[ORM\Column(type: Types::STRING)] - private string $name = '' + private string $name = '', ) { $this->address = new Address(); $this->books = new ArrayCollection(); diff --git a/tests/App/Entity/Book.php b/tests/App/Entity/Book.php index dcac0c8e3..5b8c76e1b 100644 --- a/tests/App/Entity/Book.php +++ b/tests/App/Entity/Book.php @@ -42,7 +42,7 @@ public function __construct( private string $name = '', #[ORM\ManyToOne(targetEntity: Author::class, inversedBy: 'books')] #[ORM\JoinColumn(name: 'author_id', referencedColumnName: 'id', onDelete: 'SET NULL')] - private ?Author $author = null + private ?Author $author = null, ) { $this->categories = new ArrayCollection(); $this->readers = new ArrayCollection(); diff --git a/tests/App/Entity/Car.php b/tests/App/Entity/Car.php index 195a9cf57..ba2eafe1a 100644 --- a/tests/App/Entity/Car.php +++ b/tests/App/Entity/Car.php @@ -25,7 +25,7 @@ public function __construct( private string $name = '', #[ORM\Id] #[ORM\Column(type: Types::INTEGER)] - private int $year = 0 + private int $year = 0, ) { } diff --git a/tests/App/Entity/Category.php b/tests/App/Entity/Category.php index 8bbd81a13..1bac7f418 100644 --- a/tests/App/Entity/Category.php +++ b/tests/App/Entity/Category.php @@ -25,7 +25,7 @@ public function __construct( #[ORM\GeneratedValue(strategy: 'NONE')] private string $id = '', #[ORM\Column(type: Types::STRING)] - private string $name = '' + private string $name = '', ) { } diff --git a/tests/App/Entity/Command.php b/tests/App/Entity/Command.php index e318f13fa..2035759ed 100644 --- a/tests/App/Entity/Command.php +++ b/tests/App/Entity/Command.php @@ -25,7 +25,7 @@ class Command implements \Stringable public function __construct( #[ORM\Id] #[ORM\Column(type: Types::INTEGER)] - private int $id + private int $id, ) { $this->createdAt = new \DateTime(); } diff --git a/tests/App/Entity/Item.php b/tests/App/Entity/Item.php index f27c5061b..6ec94d1c3 100644 --- a/tests/App/Entity/Item.php +++ b/tests/App/Entity/Item.php @@ -28,7 +28,7 @@ public function __construct( private Command $command, #[ORM\Id] #[ORM\ManyToOne(targetEntity: Product::class)] - private Product $product + private Product $product, ) { $this->offeredPrice = $product->getCurrentPrice(); } diff --git a/tests/App/Entity/Product.php b/tests/App/Entity/Product.php index a3a213887..7bf83ffe0 100644 --- a/tests/App/Entity/Product.php +++ b/tests/App/Entity/Product.php @@ -26,7 +26,7 @@ public function __construct( #[ORM\Column(type: Types::STRING)] private string $name = '', #[ORM\Column(type: Types::DECIMAL, precision: 2)] - private string $currentPrice = '0.0' + private string $currentPrice = '0.0', ) { } diff --git a/tests/App/Entity/ProductAttribute.php b/tests/App/Entity/ProductAttribute.php index 24970121a..952e010a3 100644 --- a/tests/App/Entity/ProductAttribute.php +++ b/tests/App/Entity/ProductAttribute.php @@ -24,7 +24,7 @@ public function __construct( #[ORM\ManyToOne(targetEntity: Product::class)] private Product $product, #[ORM\Column(type: Types::STRING)] - private string $name + private string $name, ) { } diff --git a/tests/App/Entity/UlidChildEntity.php b/tests/App/Entity/UlidChildEntity.php index 8a60644c0..7e3697827 100644 --- a/tests/App/Entity/UlidChildEntity.php +++ b/tests/App/Entity/UlidChildEntity.php @@ -28,7 +28,7 @@ public function __construct( #[ORM\Column(type: 'ulid')] private Ulid $id, #[ORM\Column(type: Types::STRING)] - private ?string $name = null + private ?string $name = null, ) { } diff --git a/tests/App/Entity/UuidEntity.php b/tests/App/Entity/UuidEntity.php index 3ac563d13..40eb3b0f0 100644 --- a/tests/App/Entity/UuidEntity.php +++ b/tests/App/Entity/UuidEntity.php @@ -35,7 +35,7 @@ class UuidEntity implements \Stringable public function __construct( #[ORM\Id] #[ORM\Column(type: 'uuid')] - private Uuid $id + private Uuid $id, ) { } diff --git a/tests/FieldDescription/FilterTypeGuesserTest.php b/tests/FieldDescription/FilterTypeGuesserTest.php index 0e2ff8838..933b5a523 100644 --- a/tests/FieldDescription/FilterTypeGuesserTest.php +++ b/tests/FieldDescription/FilterTypeGuesserTest.php @@ -54,7 +54,7 @@ public function testGuess( string $expectedType, array $expectedOptions, int $expectedConfidence, - array $fieldMapping = [] + array $fieldMapping = [], ): void { $fieldDescription = $this->createStub(FieldDescriptionInterface::class); $fieldDescription->method('getFieldName')->willReturn('foo'); diff --git a/tests/FieldDescription/TypeGuesserTest.php b/tests/FieldDescription/TypeGuesserTest.php index f965e507a..f2ad69891 100644 --- a/tests/FieldDescription/TypeGuesserTest.php +++ b/tests/FieldDescription/TypeGuesserTest.php @@ -40,7 +40,7 @@ public function testGuess( int|string|null $mappingType, string $expectedType, array $expectedOptions, - int $expectedConfidence + int $expectedConfidence, ): void { $fieldDescription = $this->createStub(FieldDescriptionInterface::class); $fieldDescription->method('getFieldName')->willReturn('foo'); diff --git a/tests/Filter/CallbackFilterTest.php b/tests/Filter/CallbackFilterTest.php index 506670266..8d57ba7b2 100644 --- a/tests/Filter/CallbackFilterTest.php +++ b/tests/Filter/CallbackFilterTest.php @@ -38,7 +38,7 @@ public function testFilterClosure(): void $filter = new CallbackFilter(); $filter->initialize('field_name', [ 'callback' => static function (ProxyQueryInterface $query, string $alias, string $field, FilterData $data): bool { - $query->getQueryBuilder()->andWhere(sprintf('CUSTOM QUERY %s.%s', $alias, $field)); + $query->getQueryBuilder()->andWhere(\sprintf('CUSTOM QUERY %s.%s', $alias, $field)); $query->getQueryBuilder()->setParameter('value', $data->getValue()); return true; @@ -73,7 +73,7 @@ public function testFilterMethod(): void */ public function customCallback(ProxyQueryInterface $query, string $alias, string $field, FilterData $data): bool { - $query->getQueryBuilder()->andWhere(sprintf('CUSTOM QUERY %s.%s', $alias, $field)); + $query->getQueryBuilder()->andWhere(\sprintf('CUSTOM QUERY %s.%s', $alias, $field)); $query->getQueryBuilder()->setParameter('value', $data->getValue()); return true; @@ -97,7 +97,7 @@ public function testApplyMethod(): void $filter = new CallbackFilter(); $filter->initialize('field_name_test', [ 'callback' => static function (ProxyQueryInterface $query, string $alias, string $field, FilterData $data): bool { - $query->getQueryBuilder()->andWhere(sprintf('CUSTOM QUERY %s.%s', $alias, $field)); + $query->getQueryBuilder()->andWhere(\sprintf('CUSTOM QUERY %s.%s', $alias, $field)); $query->getQueryBuilder()->setParameter('value', $data->getValue()); return true; diff --git a/tests/Filter/DateRangeFilterTest.php b/tests/Filter/DateRangeFilterTest.php index cbae28eab..b815244ff 100644 --- a/tests/Filter/DateRangeFilterTest.php +++ b/tests/Filter/DateRangeFilterTest.php @@ -116,7 +116,7 @@ public function testFilterEndDate(): void public function testFilterEndDateCoversWholeDay( \DateTimeImmutable $expectedEndDateTime, \DateTime $viewEndDateTime, - \DateTimeZone $modelTimeZone + \DateTimeZone $modelTimeZone, ): void { $filter = new DateRangeFilter(); $filter->initialize('field_name', ['field_options' => ['class' => 'FooBar']]); diff --git a/tests/Filter/FilterTestCase.php b/tests/Filter/FilterTestCase.php index 37a1a868b..e9e3ae618 100644 --- a/tests/Filter/FilterTestCase.php +++ b/tests/Filter/FilterTestCase.php @@ -68,7 +68,7 @@ static function (string $name, mixed $value) use ($queryBuilder): TestQueryBuild $queryBuilder->method('andWhere')->willReturnCallback( static function (mixed $query) use ($queryBuilder): TestQueryBuilder { - $queryBuilder->query[] = sprintf('WHERE %s', $query); + $queryBuilder->query[] = \sprintf('WHERE %s', $query); return $queryBuilder; } @@ -76,7 +76,7 @@ static function (mixed $query) use ($queryBuilder): TestQueryBuilder { $queryBuilder->method('andHaving')->willReturnCallback( static function (mixed $query) use ($queryBuilder): TestQueryBuilder { - $queryBuilder->query[] = sprintf('HAVING %s', $query); + $queryBuilder->query[] = \sprintf('HAVING %s', $query); return $queryBuilder; } @@ -84,7 +84,7 @@ static function (mixed $query) use ($queryBuilder): TestQueryBuilder { $queryBuilder->method('addGroupBy')->willReturnCallback( static function (string $groupBy) use ($queryBuilder): TestQueryBuilder { - $queryBuilder->query[] = sprintf('GROUP BY %s', $groupBy); + $queryBuilder->query[] = \sprintf('GROUP BY %s', $groupBy); return $queryBuilder; } @@ -104,7 +104,7 @@ static function (string $groupBy) use ($queryBuilder): TestQueryBuilder { $queryBuilder->method('leftJoin')->willReturnCallback( static function (string $parameter, string $alias) use ($queryBuilder): TestQueryBuilder { - $queryBuilder->query[] = sprintf('LEFT JOIN %s AS %s', $parameter, $alias); + $queryBuilder->query[] = \sprintf('LEFT JOIN %s AS %s', $parameter, $alias); return $queryBuilder; } diff --git a/tests/Filter/StringFilterTest.php b/tests/Filter/StringFilterTest.php index c19e48fca..024e4813d 100644 --- a/tests/Filter/StringFilterTest.php +++ b/tests/Filter/StringFilterTest.php @@ -85,7 +85,7 @@ public function testDefaultType(?string $value, bool $allowEmpty, bool $shouldBe if ($shouldBeActive) { self::assertSameQuery(['WHERE alias.field LIKE :field_name_0'], $proxyQuery); - self::assertSameQueryParameters(['field_name_0' => sprintf('%%%s%%', $value ?? '')], $proxyQuery); + self::assertSameQueryParameters(['field_name_0' => \sprintf('%%%s%%', $value ?? '')], $proxyQuery); static::assertTrue($filter->isActive()); } else { self::assertSameQuery([], $proxyQuery); @@ -108,7 +108,7 @@ public function testContains(?string $value, bool $allowEmpty, bool $shouldBeAct if ($shouldBeActive) { self::assertSameQuery(['WHERE alias.field LIKE :field_name_0'], $proxyQuery); - self::assertSameQueryParameters(['field_name_0' => sprintf('%%%s%%', $value ?? '')], $proxyQuery); + self::assertSameQueryParameters(['field_name_0' => \sprintf('%%%s%%', $value ?? '')], $proxyQuery); static::assertTrue($filter->isActive()); } else { self::assertSameQuery([], $proxyQuery); @@ -131,7 +131,7 @@ public function testStartsWith(?string $value, bool $allowEmpty, bool $shouldBeA if ($shouldBeActive) { self::assertSameQuery(['WHERE alias.field LIKE :field_name_0'], $proxyQuery); - self::assertSameQueryParameters(['field_name_0' => sprintf('%s%%', $value ?? '')], $proxyQuery); + self::assertSameQueryParameters(['field_name_0' => \sprintf('%s%%', $value ?? '')], $proxyQuery); static::assertTrue($filter->isActive()); } else { self::assertSameQuery([], $proxyQuery); @@ -154,7 +154,7 @@ public function testEndsWith(?string $value, bool $allowEmpty, bool $shouldBeAct if ($shouldBeActive) { self::assertSameQuery(['WHERE alias.field LIKE :field_name_0'], $proxyQuery); - self::assertSameQueryParameters(['field_name_0' => sprintf('%%%s', $value ?? '')], $proxyQuery); + self::assertSameQueryParameters(['field_name_0' => \sprintf('%%%s', $value ?? '')], $proxyQuery); static::assertTrue($filter->isActive()); } else { self::assertSameQuery([], $proxyQuery); @@ -177,7 +177,7 @@ public function testNotContains(?string $value, bool $allowEmpty, bool $shouldBe if ($shouldBeActive) { self::assertSameQuery(['WHERE alias.field NOT LIKE :field_name_0 OR alias.field IS NULL'], $proxyQuery); - self::assertSameQueryParameters(['field_name_0' => sprintf('%%%s%%', $value ?? '')], $proxyQuery); + self::assertSameQueryParameters(['field_name_0' => \sprintf('%%%s%%', $value ?? '')], $proxyQuery); static::assertTrue($filter->isActive()); } else { self::assertSameQuery([], $proxyQuery); diff --git a/tests/Fixtures/Entity/AssociatedEntity.php b/tests/Fixtures/Entity/AssociatedEntity.php index 20ec984ff..4307b44e7 100644 --- a/tests/Fixtures/Entity/AssociatedEntity.php +++ b/tests/Fixtures/Entity/AssociatedEntity.php @@ -19,7 +19,7 @@ final class AssociatedEntity { public function __construct( public EmbeddedEntity $embeddedEntity, - private int $plainField + private int $plainField, ) { } diff --git a/tests/Fixtures/Entity/ContainerEntity.php b/tests/Fixtures/Entity/ContainerEntity.php index d1583c833..6b6760710 100644 --- a/tests/Fixtures/Entity/ContainerEntity.php +++ b/tests/Fixtures/Entity/ContainerEntity.php @@ -21,7 +21,7 @@ final class ContainerEntity public function __construct( private AssociatedEntity $associatedEntity, - public EmbeddedEntity $embeddedEntity + public EmbeddedEntity $embeddedEntity, ) { } diff --git a/tests/Fixtures/Entity/DoubleNameEntity.php b/tests/Fixtures/Entity/DoubleNameEntity.php index 4bb89bcc1..31cb00aad 100644 --- a/tests/Fixtures/Entity/DoubleNameEntity.php +++ b/tests/Fixtures/Entity/DoubleNameEntity.php @@ -26,7 +26,7 @@ public function __construct( #[ORM\Column(type: Types::STRING)] public string $name, #[ORM\Column(type: Types::STRING, nullable: true)] - public ?string $name2 = null + public ?string $name2 = null, ) { } } diff --git a/tests/Fixtures/Entity/Product.php b/tests/Fixtures/Entity/Product.php index 0b1cfe572..e316aaaf1 100644 --- a/tests/Fixtures/Entity/Product.php +++ b/tests/Fixtures/Entity/Product.php @@ -17,7 +17,7 @@ final class Product { public function __construct( private ProductId $id, - private string $name + private string $name, ) { } diff --git a/tests/Model/ModelManagerTest.php b/tests/Model/ModelManagerTest.php index c2910b718..5d273ff59 100644 --- a/tests/Model/ModelManagerTest.php +++ b/tests/Model/ModelManagerTest.php @@ -241,7 +241,7 @@ public function testLock(bool $isVersioned, bool $expectsException): void if ($expectsException) { $em->expects(static::once()) ->method('lock') - ->will(static::throwException(OptimisticLockException::lockFailed($object))); + ->willThrowException(OptimisticLockException::lockFailed($object)); $this->expectException(LockException::class); } @@ -612,9 +612,7 @@ public function testFailingBatchDelete(string $expectedExceptionMessage, ?array $em ->expects(static::exactly(null === $result ? 0 : (int) ceil(\count($result) / $batchSize))) ->method('flush') - ->will(static::onConsecutiveCalls( - ...$onConsecutiveFlush - )); + ->willReturnOnConsecutiveCalls(...$onConsecutiveFlush); $em ->method('getConfiguration') ->willReturn(new Configuration()); @@ -717,7 +715,7 @@ public function testAddIdentifiersToQuery(array $expectedParameters, array $iden $queryBuilder ->expects(static::once()) ->method('andWhere') - ->with(static::stringContains(sprintf('( p.%s = :field_', $identifierFieldNames[0]))); + ->with(static::stringContains(\sprintf('( p.%s = :field_', $identifierFieldNames[0]))); $proxyQuery = new ProxyQuery($queryBuilder); From 2035828e01225e9ea4f4614ad9c831caeff72dcf Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Wed, 13 Nov 2024 15:01:59 +0100 Subject: [PATCH 3/3] Fix phpstan --- src/Datagrid/ProxyQuery.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Datagrid/ProxyQuery.php b/src/Datagrid/ProxyQuery.php index 29616e5a5..5115aa3a5 100644 --- a/src/Datagrid/ProxyQuery.php +++ b/src/Datagrid/ProxyQuery.php @@ -72,10 +72,12 @@ * @method QueryBuilder addOrderBy($sort, $order = null) * @method QueryBuilder addCriteria(Criteria $criteria) * @method mixed getDQLPart($queryPartName) - * @method array getDQLParts() + * @method mixed[] getDQLParts() * @method QueryBuilder resetDQLParts($parts = null) * @method QueryBuilder resetDQLPart($part) * + * @phpstan-method ArrayCollection getParameters() + * * @phpstan-template-covariant T of object * @phpstan-implements ProxyQueryInterface */