From 672a614bd96fac8b633a07571eff4ee2fd3db934 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Mon, 26 Aug 2024 11:20:22 +0200 Subject: [PATCH] Fix SA (#8207) --- src/Action/AppendFormFieldElementAction.php | 2 +- .../GetShortObjectDescriptionAction.php | 2 +- .../RetrieveAutocompleteItemsAction.php | 14 ++-- src/Action/RetrieveFormFieldElementAction.php | 2 +- src/Action/SetObjectFieldValueAction.php | 6 +- src/Admin/AbstractAdmin.php | 78 +++++++++---------- src/Admin/AdminHelper.php | 4 +- src/Admin/BreadcrumbsBuilder.php | 4 +- src/Admin/Pool.php | 16 ++-- src/BCLayer/BCHelper.php | 2 +- src/Bridge/Exporter/AdminExporter.php | 2 +- src/Builder/AbstractFormContractor.php | 8 +- src/Command/ExplainAdminCommand.php | 28 +++---- src/Command/GenerateObjectAclCommand.php | 10 +-- src/Command/ListAdminCommand.php | 2 +- src/Command/SetupAclCommand.php | 2 +- src/Command/Validators.php | 8 +- src/Controller/CRUDController.php | 48 ++++++------ src/Datagrid/Datagrid.php | 4 +- src/Datagrid/DatagridMapper.php | 2 +- src/Datagrid/ListMapper.php | 4 +- .../Admin/AbstractTaggedAdmin.php | 38 ++++----- .../Compiler/AddAuditReadersCompilerPass.php | 2 +- .../AddDependencyCallsCompilerPass.php | 24 +++--- .../Compiler/AddFilterTypeCompilerPass.php | 6 +- .../Compiler/AdminSearchCompilerPass.php | 2 +- .../Compiler/ExtensionCompilerPass.php | 10 +-- .../Compiler/ModelManagerCompilerPass.php | 2 +- src/DependencyInjection/Configuration.php | 2 +- .../SonataAdminExtension.php | 2 +- src/Exception/AbstractClassException.php | 2 +- .../BadRequestParamHttpException.php | 2 +- src/FieldDescription/BaseFieldDescription.php | 14 ++-- .../FieldDescriptionCollection.php | 4 +- src/FieldDescription/TypeGuesserChain.php | 2 +- src/Filter/Filter.php | 10 +-- src/Filter/FilterFactory.php | 4 +- src/Filter/Model/FilterData.php | 4 +- .../Persister/SessionFilterPersister.php | 2 +- src/Form/ChoiceList/ModelChoiceLoader.php | 6 +- .../ModelToIdPropertyTransformer.php | 4 +- .../ModelsToArrayTransformer.php | 6 +- .../Field/Type/FormTypeFieldExtension.php | 14 ++-- src/Form/FormMapper.php | 2 +- src/Form/Type/AdminType.php | 2 +- src/Maker/AdminMaker.php | 28 +++---- src/Manipulator/ServicesManipulator.php | 8 +- src/Mapper/BaseGroupedMapper.php | 10 +-- src/Model/AuditManager.php | 4 +- src/Request/AdminFetcher.php | 2 +- src/Route/DefaultRouteGenerator.php | 10 +-- src/Route/PathInfoBuilder.php | 14 ++-- src/Route/RouteCollection.php | 12 +-- src/Route/RoutesCache.php | 2 +- src/Security/Handler/AclSecurityHandler.php | 10 +-- src/Security/Handler/RoleSecurityHandler.php | 14 ++-- src/Show/ShowMapper.php | 2 +- src/Templating/AbstractTemplateRegistry.php | 2 +- src/Translator/BCLabelTranslatorStrategy.php | 4 +- .../UnderscoreLabelTranslatorStrategy.php | 2 +- src/Twig/Extension/BreadcrumbsExtension.php | 4 +- src/Twig/Extension/CanonicalizeExtension.php | 4 +- src/Twig/Extension/GroupExtension.php | 2 +- src/Twig/Extension/IconExtension.php | 2 +- src/Twig/Extension/RenderElementExtension.php | 8 +- src/Twig/Extension/SecurityExtension.php | 2 +- src/Twig/Extension/SonataAdminExtension.php | 2 +- .../Extension/TemplateRegistryExtension.php | 4 +- src/Twig/Extension/XEditableExtension.php | 4 +- src/Twig/IconRuntime.php | 4 +- src/Twig/RenderElementRuntime.php | 10 +-- src/Util/AdminAclManipulator.php | 10 +-- src/Util/AdminObjectAclData.php | 2 +- src/Util/FormBuilderIterator.php | 2 +- src/Util/ObjectAclManipulator.php | 4 +- src/Util/TraversableToCollection.php | 2 +- tests/Admin/AdminHelperTest.php | 14 ++-- tests/Admin/AdminTest.php | 26 +++---- tests/Admin/PoolTest.php | 2 +- tests/App/AppKernel.php | 12 +-- tests/App/EventListener/ConfigureMenu.php | 2 +- tests/Command/ExplainAdminCommandTest.php | 4 +- tests/Controller/CRUDControllerTest.php | 8 +- tests/Datagrid/DatagridMapperTest.php | 2 +- tests/Datagrid/ListMapperTest.php | 4 +- .../Compiler/ExtensionCompilerPassTest.php | 8 +- .../Compiler/ModelManagerCompilerPassTest.php | 2 +- .../SonataAdminExtensionTest.php | 2 +- tests/Filter/FilterTest.php | 2 +- tests/Filter/Model/FilterDataTest.php | 2 +- .../Fixtures/Controller/PreCRUDController.php | 8 +- tests/Fixtures/Entity/FooArrayAccess.php | 4 +- .../FieldDescription/FieldDescription.php | 8 +- tests/Fixtures/StubTranslator.php | 2 +- tests/Fixtures/TestExtension.php | 2 +- tests/Form/AbstractLayoutTestCase.php | 4 +- .../ModelToIdPropertyTransformerTest.php | 2 +- tests/Form/Type/AdminTypeTest.php | 8 +- tests/Form/Widget/BaseWidgetTest.php | 6 +- tests/Functional/Controller/MenuTest.php | 2 +- tests/Maker/AdminMakerTest.php | 6 +- tests/Manipulator/ObjectManipulatorTest.php | 18 ++--- tests/Manipulator/ServicesManipulatorTest.php | 2 +- tests/Mapper/BaseGroupedMapperTest.php | 2 +- tests/Menu/Integration/BaseMenuTest.php | 8 +- tests/Menu/Matcher/Voter/AdminVoterTest.php | 6 +- tests/Menu/Provider/GroupMenuProviderTest.php | 8 +- tests/Model/AuditManagerTest.php | 2 +- tests/Route/DefaultRouteGeneratorTest.php | 22 +++--- tests/Route/RouteCollectionTest.php | 2 +- .../Acl/Permission/MaskBuilderTest.php | 10 +-- tests/Show/ShowMapperTest.php | 2 +- .../FakeTemplateRegistryExtension.php | 2 +- .../Extension/RenderElementExtensionTest.php | 10 +-- .../Extension/SonataAdminExtensionTest.php | 4 +- tests/Twig/RenderElementRuntimeTest.php | 10 +-- tests/Twig/SonataAdminRuntimeTest.php | 4 +- tests/Util/TraversableToCollectionTest.php | 2 +- 118 files changed, 430 insertions(+), 430 deletions(-) diff --git a/src/Action/AppendFormFieldElementAction.php b/src/Action/AppendFormFieldElementAction.php index f02ff792e5..760bbba1ff 100644 --- a/src/Action/AppendFormFieldElementAction.php +++ b/src/Action/AppendFormFieldElementAction.php @@ -48,7 +48,7 @@ public function __invoke(Request $request): Response } elseif (\is_string($objectId) || \is_int($objectId)) { $subject = $admin->getObject($objectId); if (null === $subject) { - throw new NotFoundHttpException(sprintf( + throw new NotFoundHttpException(\sprintf( 'Unable to find the object id: %s, class: %s', $objectId, $admin->getClass() diff --git a/src/Action/GetShortObjectDescriptionAction.php b/src/Action/GetShortObjectDescriptionAction.php index c12ea16c33..17ada5bc75 100644 --- a/src/Action/GetShortObjectDescriptionAction.php +++ b/src/Action/GetShortObjectDescriptionAction.php @@ -54,7 +54,7 @@ public function __invoke(Request $request): Response try { $object = $admin->getObject($objectId); if (null === $object) { - throw new NotFoundHttpException(sprintf('Could not find subject for id "%s"', $objectId)); + throw new NotFoundHttpException(\sprintf('Could not find subject for id "%s"', $objectId)); } } finally { // Restore the subclass if present to reduce impact of the parameter removal above. diff --git a/src/Action/RetrieveAutocompleteItemsAction.php b/src/Action/RetrieveAutocompleteItemsAction.php index 89204ee0bd..88a6796835 100644 --- a/src/Action/RetrieveAutocompleteItemsAction.php +++ b/src/Action/RetrieveAutocompleteItemsAction.php @@ -133,7 +133,7 @@ public function __invoke(Request $request): JsonResponse $previousFilter = null; foreach ($property as $prop) { if (!$datagrid->hasFilter($prop)) { - throw new BadRequestHttpException(sprintf( + throw new BadRequestHttpException(\sprintf( 'To retrieve autocomplete items, you MUST add the filter "%s"' .' to the %s::configureDatagridFilters() method.', $prop, @@ -143,7 +143,7 @@ public function __invoke(Request $request): JsonResponse $filter = $datagrid->getFilter($prop); if (!$filter instanceof ChainableFilterInterface) { - throw new BadRequestHttpException(sprintf( + throw new BadRequestHttpException(\sprintf( 'To retrieve autocomplete items with multiple properties,' .' the filter "%s" of the admin "%s" MUST implements "%s".', $filter->getName(), @@ -165,7 +165,7 @@ public function __invoke(Request $request): JsonResponse $datagrid->reorderFilters($property); } elseif (\is_string($property)) { if (!$datagrid->hasFilter($property)) { - throw new BadRequestHttpException(sprintf( + throw new BadRequestHttpException(\sprintf( 'To retrieve autocomplete items, you MUST add the filter "%s"' .' to the %s::configureDatagridFilters() method.', $property, @@ -235,13 +235,13 @@ private function retrieveFilterFieldDescription( string $field ): FieldDescriptionInterface { if (!$admin->hasFilterFieldDescription($field)) { - throw new \RuntimeException(sprintf('The field "%s" does not exist.', $field)); + throw new \RuntimeException(\sprintf('The field "%s" does not exist.', $field)); } $fieldDescription = $admin->getFilterFieldDescription($field); if (null === $fieldDescription->getTargetModel()) { - throw new \RuntimeException(sprintf('No associated entity with field "%s".', $field)); + throw new \RuntimeException(\sprintf('No associated entity with field "%s".', $field)); } return $fieldDescription; @@ -259,13 +259,13 @@ private function retrieveFormFieldDescription( string $field ): FieldDescriptionInterface { if (!$admin->hasFormFieldDescription($field)) { - throw new \RuntimeException(sprintf('The field "%s" does not exist.', $field)); + throw new \RuntimeException(\sprintf('The field "%s" does not exist.', $field)); } $fieldDescription = $admin->getFormFieldDescription($field); if (null === $fieldDescription->getTargetModel()) { - throw new \RuntimeException(sprintf('No associated entity with field "%s".', $field)); + throw new \RuntimeException(\sprintf('No associated entity with field "%s".', $field)); } return $fieldDescription; diff --git a/src/Action/RetrieveFormFieldElementAction.php b/src/Action/RetrieveFormFieldElementAction.php index 8f8ff0495b..93b903882e 100644 --- a/src/Action/RetrieveFormFieldElementAction.php +++ b/src/Action/RetrieveFormFieldElementAction.php @@ -48,7 +48,7 @@ public function __invoke(Request $request): Response } elseif (\is_string($objectId) || \is_int($objectId)) { $subject = $admin->getObject($objectId); if (null === $subject) { - throw new NotFoundHttpException(sprintf( + throw new NotFoundHttpException(\sprintf( 'Unable to find the object id: %s, class: %s', $objectId, $admin->getClass() diff --git a/src/Action/SetObjectFieldValueAction.php b/src/Action/SetObjectFieldValueAction.php index 46d5201ae2..0bbc00be8a 100644 --- a/src/Action/SetObjectFieldValueAction.php +++ b/src/Action/SetObjectFieldValueAction.php @@ -42,7 +42,7 @@ public function __construct( ) { // NEXT_MAJOR: Remove the deprecation and restrict param constructor to RenderElementRuntime. if (null === $renderElementRuntime) { - @trigger_error(sprintf( + @trigger_error(\sprintf( 'Passing null as argument 5 of "%s()" is deprecated since sonata-project/admin-bundle 4.7' .' and will throw an error in 5.0. You MUST pass an instance of %s instead.', __METHOD__, @@ -69,7 +69,7 @@ public function __invoke(Request $request): JsonResponse } if (Request::METHOD_POST !== $request->getMethod()) { - return new JsonResponse(sprintf( + return new JsonResponse(\sprintf( 'Invalid request method given "%s", %s expected', $request->getMethod(), Request::METHOD_POST @@ -138,7 +138,7 @@ public function __invoke(Request $request): JsonResponse } if (null === $value && FieldDescriptionInterface::TYPE_CHOICE === $fieldDescription->getType()) { - return new JsonResponse(sprintf( + return new JsonResponse(\sprintf( 'Edit failed, object with id "%s" not found in association "%s".', $objectId, $field diff --git a/src/Admin/AbstractAdmin.php b/src/Admin/AbstractAdmin.php index 7844c990ba..f75ac38666 100644 --- a/src/Admin/AbstractAdmin.php +++ b/src/Admin/AbstractAdmin.php @@ -516,7 +516,7 @@ final public function getFilterParameters(): array final public function getParentAssociationMapping(): ?string { if (!$this->isChild()) { - throw new \LogicException(sprintf( + throw new \LogicException(\sprintf( 'Admin "%s" has no parent.', static::class )); @@ -534,7 +534,7 @@ final public function getBaseRoutePattern(): string } if ($this->isChild()) { // the admin class is a child, prefix it with the parent route pattern - $this->cachedBaseRoutePattern = sprintf( + $this->cachedBaseRoutePattern = \sprintf( '%s/%s/%s', $this->getParent()->getBaseRoutePattern(), $this->getParent()->getRouterIdParameter(), @@ -559,7 +559,7 @@ final public function getBaseRouteName(): string } if ($this->isChild()) { // the admin class is a child, prefix it with the parent route name - $this->cachedBaseRouteName = sprintf( + $this->cachedBaseRouteName = \sprintf( '%s_%s', $this->getParent()->getBaseRouteName(), $this->generateBaseRouteName(true) @@ -582,7 +582,7 @@ final public function getClass(): string \assert(\is_string($subClass)); if (!$this->hasSubClass($subClass)) { - throw new \LogicException(sprintf('Subclass "%s" is not defined.', $subClass)); + throw new \LogicException(\sprintf('Subclass "%s" is not defined.', $subClass)); } return $this->getSubClass($subClass); @@ -631,7 +631,7 @@ final public function hasActiveSubClass(): bool final public function getActiveSubClass(): string { if (!$this->hasActiveSubClass()) { - throw new \LogicException(sprintf( + throw new \LogicException(\sprintf( 'Admin "%s" has no active subclass.', static::class )); @@ -643,7 +643,7 @@ final public function getActiveSubClass(): string final public function getActiveSubclassCode(): string { if (!$this->hasActiveSubClass()) { - throw new \LogicException(sprintf( + throw new \LogicException(\sprintf( 'Admin "%s" has no active subclass.', static::class )); @@ -652,7 +652,7 @@ final public function getActiveSubclassCode(): string $subClass = (string) $this->getRequest()->query->get('subclass'); if (!$this->hasSubClass($subClass)) { - throw new \LogicException(sprintf( + throw new \LogicException(\sprintf( 'Admin "%s" has no active subclass.', static::class )); @@ -708,7 +708,7 @@ final public function getRoutes(): RouteCollectionInterface public function getRouterIdParameter(): string { - return sprintf('{%s}', $this->getIdParameter()); + return \sprintf('{%s}', $this->getIdParameter()); } public function getIdParameter(): string @@ -716,7 +716,7 @@ public function getIdParameter(): string $parameter = 'id'; for ($i = 0; $i < $this->getChildDepth(); ++$i) { - $parameter = sprintf('child%s', ucfirst($parameter)); + $parameter = \sprintf('child%s', ucfirst($parameter)); } return $parameter; @@ -800,7 +800,7 @@ final public function getFormBuilder(): FormBuilderInterface final public function defineFormBuilder(FormBuilderInterface $formBuilder): void { if (!$this->hasSubject()) { - throw new \LogicException(sprintf( + throw new \LogicException(\sprintf( 'Admin "%s" has no subject.', static::class )); @@ -1029,7 +1029,7 @@ final public function setParentFieldDescription(FieldDescriptionInterface $paren final public function getParentFieldDescription(): FieldDescriptionInterface { if (!$this->hasParentFieldDescription()) { - throw new \LogicException(sprintf( + throw new \LogicException(\sprintf( 'Admin "%s" has no parent field description.', static::class )); @@ -1049,7 +1049,7 @@ final public function hasParentFieldDescription(): bool final public function setSubject(?object $subject): void { if (null !== $subject && !is_a($subject, $this->getModelClass(), true)) { - throw new \LogicException(sprintf( + throw new \LogicException(\sprintf( 'Admin "%s" does not allow this subject: %s, use the one register with this admin class %s', static::class, $subject::class, @@ -1063,7 +1063,7 @@ final public function setSubject(?object $subject): void final public function getSubject(): object { if (!$this->hasSubject()) { - throw new \LogicException(sprintf( + throw new \LogicException(\sprintf( 'Admin "%s" has no subject.', static::class )); @@ -1100,7 +1100,7 @@ final public function getFormFieldDescription(string $name): FieldDescriptionInt $this->buildForm(); if (!$this->hasFormFieldDescription($name)) { - throw new \LogicException(sprintf( + throw new \LogicException(\sprintf( 'Admin "%s" has no form field description for the field %s.', static::class, $name @@ -1153,7 +1153,7 @@ final public function getShowFieldDescription(string $name): FieldDescriptionInt $this->buildShow(); if (!$this->hasShowFieldDescription($name)) { - throw new \LogicException(sprintf( + throw new \LogicException(\sprintf( 'Admin "%s" has no show field description for the field %s.', static::class, $name @@ -1192,7 +1192,7 @@ final public function getListFieldDescription(string $name): FieldDescriptionInt $this->buildList(); if (!$this->hasListFieldDescription($name)) { - throw new \LogicException(sprintf( + throw new \LogicException(\sprintf( 'Admin "%s" has no list field description for %s.', static::class, $name @@ -1224,7 +1224,7 @@ final public function getFilterFieldDescription(string $name): FieldDescriptionI $this->buildDatagrid(); if (!$this->hasFilterFieldDescription($name)) { - throw new \LogicException(sprintf( + throw new \LogicException(\sprintf( 'Admin "%s" has no filter field description for the field %s.', static::class, $name @@ -1269,7 +1269,7 @@ final public function addChild(AdminInterface $child, ?string $field = null): vo } if ($parentAdmin->getCode() === $child->getCode()) { - throw new \LogicException(sprintf( + throw new \LogicException(\sprintf( 'Circular reference detected! The child admin `%s` is already in the parent tree of the `%s` admin.', $child->getCode(), $this->getCode() @@ -1295,7 +1295,7 @@ final public function getChildren(): array final public function getChild(string $code): AdminInterface { if (!$this->hasChild($code)) { - throw new \LogicException(sprintf( + throw new \LogicException(\sprintf( 'Admin "%s" has no child for the code %s.', static::class, $code @@ -1314,7 +1314,7 @@ final public function setParent(AdminInterface $parent, ?string $parentAssociati final public function getParent(): AdminInterface { if (null === $this->parent) { - throw new \LogicException(sprintf( + throw new \LogicException(\sprintf( 'Admin "%s" has no parent.', static::class )); @@ -1385,7 +1385,7 @@ final public function setUniqId(string $uniqId): void final public function getUniqId(): string { if (null === $this->uniqId) { - $this->uniqId = sprintf('s%s', uniqid()); + $this->uniqId = \sprintf('s%s', uniqid()); } return $this->uniqId; @@ -1394,7 +1394,7 @@ final public function getUniqId(): string final public function getClassnameLabel(): string { if (null === $this->classnameLabel) { - throw new \LogicException(sprintf( + throw new \LogicException(\sprintf( 'Admin "%s" has no classname label. Did you forgot to initialize the admin ?', static::class )); @@ -1523,7 +1523,7 @@ public function showInDashboard(): bool final public function showIn(string $context): bool { if ('sonata_deprecation_mute' !== (\func_get_args()[1] ?? null)) { - @trigger_error(sprintf( + @trigger_error(\sprintf( 'The "%s()" method is deprecated since sonata-project/admin-bundle version 4.7 and will be' .' removed in 5.0 version. Use showInDashboard() instead.', __METHOD__ @@ -1546,7 +1546,7 @@ final public function isGranted($name, ?object $object = null): bool { if (\is_array($name)) { @trigger_error( - sprintf( + \sprintf( 'Passing an array as argument 1 of "%s()" is deprecated since sonata-project/admin-bundle 4.6' .' and will throw an error in 5.0. You MUST pass a string instead.', __METHOD__ @@ -1555,7 +1555,7 @@ final public function isGranted($name, ?object $object = null): bool ); } - $objectRef = null !== $object ? sprintf('/%s#%s', spl_object_hash($object), $this->id($object) ?? '') : ''; + $objectRef = null !== $object ? \sprintf('/%s#%s', spl_object_hash($object), $this->id($object) ?? '') : ''; $key = md5(json_encode($name, \JSON_THROW_ON_ERROR).$objectRef); if (!\array_key_exists($key, $this->cacheIsGranted)) { @@ -1623,7 +1623,7 @@ final public function removeExtension(AdminExtensionInterface $extension): void $key = array_search($extension, $this->extensions, true); if (false === $key) { throw new \InvalidArgumentException( - sprintf('The extension "%s" was not set to the "%s" admin.', $extension::class, self::class) + \sprintf('The extension "%s" was not set to the "%s" admin.', $extension::class, self::class) ); } @@ -1649,7 +1649,7 @@ public function toString(object $object): string $class = BCHelper::getClass($object); } - return sprintf('%s:%s', $class, spl_object_hash($object)); + return \sprintf('%s:%s', $class, spl_object_hash($object)); } final public function supportsPreviewMode(): bool @@ -1693,7 +1693,7 @@ public function getObjectMetadata(object $object): MetadataInterface final public function setListMode(string $mode): void { - $this->getRequest()->getSession()->set(sprintf('%s.list_mode', $this->getCode()), $mode); + $this->getRequest()->getSession()->set(\sprintf('%s.list_mode', $this->getCode()), $mode); } final public function getListMode(): string @@ -1703,7 +1703,7 @@ final public function getListMode(): string return $defaultListMode; } - return $this->getRequest()->getSession()->get(sprintf('%s.list_mode', $this->getCode()), $defaultListMode); + return $this->getRequest()->getSession()->get(\sprintf('%s.list_mode', $this->getCode()), $defaultListMode); } final public function checkAccess(string $action, ?object $object = null): void @@ -1711,7 +1711,7 @@ final public function checkAccess(string $action, ?object $object = null): void $access = $this->getAccess(); if (!\array_key_exists($action, $access)) { - throw new \InvalidArgumentException(sprintf( + throw new \InvalidArgumentException(\sprintf( 'Action "%s" could not be found in access mapping.' .' Please make sure your action is defined into your admin class accessMapping property.', $action @@ -1724,7 +1724,7 @@ final public function checkAccess(string $action, ?object $object = null): void foreach ($access[$action] as $role) { if (false === $this->isGranted($role, $object)) { - throw new AccessDeniedException(sprintf('Access Denied to the action %s and role %s', $action, $role)); + throw new AccessDeniedException(\sprintf('Access Denied to the action %s and role %s', $action, $role)); } } } @@ -1829,7 +1829,7 @@ protected function generateBaseRoutePattern(bool $isChildAdmin = false): string { // NEXT_MAJOR: Remove this code if (null !== $this->baseRoutePattern) { - @trigger_error(sprintf( + @trigger_error(\sprintf( 'Overriding the baseRoutePattern property is deprecated since sonata-project/admin-bundle 4.15.' .' You MUST override the method %s() instead.', __METHOD__ @@ -1841,7 +1841,7 @@ protected function generateBaseRoutePattern(bool $isChildAdmin = false): string preg_match(self::CLASS_REGEX, $this->getModelClass(), $matches); if (!isset($matches[1], $matches[3], $matches[5])) { - throw new \LogicException(sprintf( + throw new \LogicException(\sprintf( 'Please define a default `baseRoutePattern` value for the admin class `%s`', static::class )); @@ -1851,7 +1851,7 @@ protected function generateBaseRoutePattern(bool $isChildAdmin = false): string return $this->urlize($matches[5], '-'); } - return sprintf( + return \sprintf( '/%s%s/%s', '' === $matches[1] ? '' : $this->urlize($matches[1], '-').'/', $this->urlize($matches[3], '-'), @@ -1866,7 +1866,7 @@ protected function generateBaseRouteName(bool $isChildAdmin = false): string { // NEXT_MAJOR: Remove this code if (null !== $this->baseRouteName) { - @trigger_error(sprintf( + @trigger_error(\sprintf( 'Overriding the baseRouteName property is deprecated since sonata-project/admin-bundle 4.15.' .' You MUST override the method %s() instead.', __METHOD__ @@ -1878,7 +1878,7 @@ protected function generateBaseRouteName(bool $isChildAdmin = false): string preg_match(self::CLASS_REGEX, $this->getModelClass(), $matches); if (!isset($matches[1], $matches[3], $matches[5])) { - throw new \LogicException(sprintf( + throw new \LogicException(\sprintf( 'Cannot automatically determine base route name,' .' please define a default `baseRouteName` value for the admin class `%s`', static::class @@ -1889,7 +1889,7 @@ protected function generateBaseRouteName(bool $isChildAdmin = false): string return $this->urlize($matches[5]); } - return sprintf( + return \sprintf( 'admin_%s%s_%s', '' === $matches[1] ? '' : $this->urlize($matches[1]).'_', $this->urlize($matches[3]), @@ -2161,7 +2161,7 @@ protected function getSubClass(string $name): string return $this->subClasses[$name]; } - throw new \LogicException(sprintf('Unable to find the subclass `%s` for admin `%s`', $name, static::class)); + throw new \LogicException(\sprintf('Unable to find the subclass `%s` for admin `%s`', $name, static::class)); } /** @@ -2212,7 +2212,7 @@ protected function getAccessMapping(): array protected function getPermissionsShow(string $context): array { if ('sonata_deprecation_mute' !== (\func_get_args()[1] ?? null)) { - @trigger_error(sprintf( + @trigger_error(\sprintf( 'The "%s()" method is deprecated since sonata-project/admin-bundle version 4.7 and will be' .' removed in 5.0 version.', __METHOD__ diff --git a/src/Admin/AdminHelper.php b/src/Admin/AdminHelper.php index 4004b93fb3..c96f2e6c74 100644 --- a/src/Admin/AdminHelper.php +++ b/src/Admin/AdminHelper.php @@ -175,7 +175,7 @@ public function appendFormFieldElement(AdminInterface $admin, object $subject, s $collection = $this->propertyAccessor->getValue($subject, $path); if (!$collection instanceof \ArrayAccess && !\is_array($collection)) { - throw new \TypeError(sprintf( + throw new \TypeError(\sprintf( 'Collection must be an instance of %s or array, %s given.', \ArrayAccess::class, \is_object($collection) ? 'instance of "'.$collection::class.'"' : '"'.\gettype($collection).'"' @@ -267,7 +267,7 @@ private function getElementAccessPath(string $elementId, $model): string } if ('' !== $currentPath) { - throw new \Exception(sprintf( + throw new \Exception(\sprintf( 'Could not get element id from %s Failing part: %s', $elementId, $currentPath diff --git a/src/Admin/BreadcrumbsBuilder.php b/src/Admin/BreadcrumbsBuilder.php index 840bcd0c6f..817b1e56a6 100644 --- a/src/Admin/BreadcrumbsBuilder.php +++ b/src/Admin/BreadcrumbsBuilder.php @@ -92,7 +92,7 @@ public function buildBreadcrumbs( $menu = $this->createMenuItem( $admin, $menu, - sprintf('%s_list', $admin->getClassnameLabel()), + \sprintf('%s_list', $admin->getClassnameLabel()), $admin->getTranslationDomain(), [ 'uri' => $admin->hasRoute('list') && $admin->hasAccess('list') ? @@ -139,7 +139,7 @@ public function buildBreadcrumbs( return $this->createMenuItem( $admin, $menu, - sprintf('%s_%s', $admin->getClassnameLabel(), $action), + \sprintf('%s_%s', $admin->getClassnameLabel(), $action), $admin->getTranslationDomain() ); } diff --git a/src/Admin/Pool.php b/src/Admin/Pool.php index 3f9b65d389..b81b8c18e7 100644 --- a/src/Admin/Pool.php +++ b/src/Admin/Pool.php @@ -102,7 +102,7 @@ public function getDashboardGroups(): array continue; } } else { - @trigger_error(sprintf( + @trigger_error(\sprintf( 'Not implementing "%s::showInDashboard()" is deprecated since sonata-project/admin-bundle 4.7' .' and will fail in 5.0.', AdminInterface::class @@ -139,7 +139,7 @@ public function getDashboardGroups(): array public function getAdminByClass(string $class): AdminInterface { if (!$this->hasAdminByClass($class)) { - throw new AdminClassNotFoundException(sprintf('Pool has no admin for the class %s.', $class)); + throw new AdminClassNotFoundException(\sprintf('Pool has no admin for the class %s.', $class)); } if (isset($this->adminClasses[$class][self::DEFAULT_ADMIN_KEY])) { @@ -147,7 +147,7 @@ public function getAdminByClass(string $class): AdminInterface } if (1 !== \count($this->adminClasses[$class])) { - throw new TooManyAdminClassException(sprintf( + throw new TooManyAdminClassException(\sprintf( 'Unable to find a valid admin for the class: %s, there are too many registered: %s.' .' Please define a default one with the tag attribute `default: true` in your admin configuration.', $class, @@ -182,7 +182,7 @@ public function getAdminByAdminCode(string $adminCode): AdminInterface foreach ($codes as $code) { if (!\in_array($code, $this->adminServiceCodes, true)) { - throw new AdminCodeNotFoundException(sprintf( + throw new AdminCodeNotFoundException(\sprintf( 'Argument 1 passed to %s() must contain a valid admin reference, "%s" found at "%s".', __METHOD__, $code, @@ -191,7 +191,7 @@ public function getAdminByAdminCode(string $adminCode): AdminInterface } if (!$admin->hasChild($code)) { - throw new AdminCodeNotFoundException(sprintf( + throw new AdminCodeNotFoundException(\sprintf( 'Argument 1 passed to %s() must contain a valid admin hierarchy,' .' "%s" is not a valid child for "%s"', __METHOD__, @@ -259,7 +259,7 @@ public function getInstance(string $code): AdminInterface } if (!\in_array($code, $this->adminServiceCodes, true)) { - $msg = sprintf('Admin service "%s" not found in admin pool.', $code); + $msg = \sprintf('Admin service "%s" not found in admin pool.', $code); $shortest = -1; $closest = null; $alternatives = []; @@ -278,7 +278,7 @@ public function getInstance(string $code): AdminInterface if (null !== $closest) { asort($alternatives); unset($alternatives[$closest]); - $msg = sprintf( + $msg = \sprintf( 'Admin service "%s" not found in admin pool. Did you mean "%s" or one of those: [%s]?', $code, $closest, @@ -292,7 +292,7 @@ public function getInstance(string $code): AdminInterface $admin = $this->container->get($code); if (!$admin instanceof AdminInterface) { - throw new \InvalidArgumentException(sprintf('Found service "%s" is not a valid admin service', $code)); + throw new \InvalidArgumentException(\sprintf('Found service "%s" is not a valid admin service', $code)); } return $admin; diff --git a/src/BCLayer/BCHelper.php b/src/BCLayer/BCHelper.php index 8e069ab540..f7109800fe 100644 --- a/src/BCLayer/BCHelper.php +++ b/src/BCLayer/BCHelper.php @@ -30,7 +30,7 @@ public static function getClass(object $object): string $class = $object::class; if ($class !== $classFromDoctrine) { - @trigger_error(sprintf( + @trigger_error(\sprintf( 'Using proxy class "%s" without a model manager which implements %s is deprecated' .' since sonata-project/admin-bundle version 4.17 and will not work in 5.0 version.', $class, diff --git a/src/Bridge/Exporter/AdminExporter.php b/src/Bridge/Exporter/AdminExporter.php index 400a8f7747..bbae8ada05 100644 --- a/src/Bridge/Exporter/AdminExporter.php +++ b/src/Bridge/Exporter/AdminExporter.php @@ -59,7 +59,7 @@ public function getExportFilename(AdminInterface $admin, string $format): string $class = $admin->getClass(); $namespaceSeparatorPos = strripos($class, '\\'); - return sprintf( + return \sprintf( 'export_%s_%s.%s', strtolower(false !== $namespaceSeparatorPos ? substr($class, $namespaceSeparatorPos + 1) : $class), date('Y_m_d_H_i_s', time()), diff --git a/src/Builder/AbstractFormContractor.php b/src/Builder/AbstractFormContractor.php index ebfc225970..99042a5681 100644 --- a/src/Builder/AbstractFormContractor.php +++ b/src/Builder/AbstractFormContractor.php @@ -86,7 +86,7 @@ final public function getDefaultOptions( if ($this->isAnyInstanceOf($type, [ModelAutocompleteType::class])) { if (!$fieldDescription->hasAssociationAdmin()) { - throw new \InvalidArgumentException(sprintf( + throw new \InvalidArgumentException(\sprintf( 'The current field `%s` is not linked to an admin.' .' Please create one for the target model: `%s`.', $fieldDescription->getName(), @@ -96,7 +96,7 @@ final public function getDefaultOptions( } } elseif ($this->isAnyInstanceOf($type, [AdminType::class])) { if (!$fieldDescription->hasAssociationAdmin()) { - throw new \InvalidArgumentException(sprintf( + throw new \InvalidArgumentException(\sprintf( 'The current field `%s` is not linked to an admin.' .' Please create one for the target model: `%s`.', $fieldDescription->getName(), @@ -105,7 +105,7 @@ final public function getDefaultOptions( } if (!$fieldDescription->describesSingleValuedAssociation()) { - throw new \InvalidArgumentException(sprintf( + throw new \InvalidArgumentException(\sprintf( 'You are trying to add `%s` field `%s` which is not a One-To-One or Many-To-One association.' .' You SHOULD use `%s` instead.', AdminType::class, @@ -125,7 +125,7 @@ final public function getDefaultOptions( CollectionType::class, ])) { if (!$fieldDescription->hasAssociationAdmin()) { - throw new \InvalidArgumentException(sprintf( + throw new \InvalidArgumentException(\sprintf( 'The current field `%s` is not linked to an admin.' .' Please create one for the target model: `%s`.', $fieldDescription->getName(), diff --git a/src/Command/ExplainAdminCommand.php b/src/Command/ExplainAdminCommand.php index 24ed911b73..706d455089 100644 --- a/src/Command/ExplainAdminCommand.php +++ b/src/Command/ExplainAdminCommand.php @@ -49,29 +49,29 @@ public function execute(InputInterface $input, OutputInterface $output): int $admin->setSubject($admin->getNewInstance()); $output->writeln('AdminBundle Information'); - $output->writeln(sprintf('% -20s : %s', 'id', $admin->getCode())); - $output->writeln(sprintf('% -20s : %s', 'Admin', $admin::class)); - $output->writeln(sprintf('% -20s : %s', 'Model', $admin->getClass())); - $output->writeln(sprintf('% -20s : %s', 'Controller', $admin->getBaseControllerName())); - $output->writeln(sprintf('% -20s : %s', 'Model Manager', $admin->getModelManager()::class)); - $output->writeln(sprintf('% -20s : %s', 'Form Builder', $admin->getFormBuilder()::class)); - $output->writeln(sprintf('% -20s : %s', 'Datagrid Builder', $admin->getDatagridBuilder()::class)); - $output->writeln(sprintf('% -20s : %s', 'List Builder', $admin->getListBuilder()::class)); + $output->writeln(\sprintf('% -20s : %s', 'id', $admin->getCode())); + $output->writeln(\sprintf('% -20s : %s', 'Admin', $admin::class)); + $output->writeln(\sprintf('% -20s : %s', 'Model', $admin->getClass())); + $output->writeln(\sprintf('% -20s : %s', 'Controller', $admin->getBaseControllerName())); + $output->writeln(\sprintf('% -20s : %s', 'Model Manager', $admin->getModelManager()::class)); + $output->writeln(\sprintf('% -20s : %s', 'Form Builder', $admin->getFormBuilder()::class)); + $output->writeln(\sprintf('% -20s : %s', 'Datagrid Builder', $admin->getDatagridBuilder()::class)); + $output->writeln(\sprintf('% -20s : %s', 'List Builder', $admin->getListBuilder()::class)); if ($admin->isChild()) { - $output->writeln(sprintf('% -15s : %s', 'Parent', $admin->getParent()->getCode())); + $output->writeln(\sprintf('% -15s : %s', 'Parent', $admin->getParent()->getCode())); } $output->writeln(''); $output->writeln('Routes'); foreach ($admin->getRoutes()->getElements() as $route) { - $output->writeln(sprintf(' - % -25s %s', $route->getDefault('_sonata_name'), $route->getPath())); + $output->writeln(\sprintf(' - % -25s %s', $route->getDefault('_sonata_name'), $route->getPath())); } $output->writeln(''); $output->writeln('Datagrid Columns'); foreach ($admin->getListFieldDescriptions() as $name => $fieldDescription) { - $output->writeln(sprintf( + $output->writeln(\sprintf( ' - % -25s % -15s % -15s', $name, $fieldDescription->getType() ?? '', @@ -82,7 +82,7 @@ public function execute(InputInterface $input, OutputInterface $output): int $output->writeln(''); $output->writeln('Datagrid Filters'); foreach ($admin->getFilterFieldDescriptions() as $name => $fieldDescription) { - $output->writeln(sprintf( + $output->writeln(\sprintf( ' - % -25s % -15s % -15s', $name, $fieldDescription->getType() ?? '', @@ -93,13 +93,13 @@ public function execute(InputInterface $input, OutputInterface $output): int $output->writeln(''); $output->writeln('Form theme(s)'); foreach ($admin->getFormTheme() as $template) { - $output->writeln(sprintf(' - %s', $template)); + $output->writeln(\sprintf(' - %s', $template)); } $output->writeln(''); $output->writeln('Form Fields'); foreach ($admin->getFormFieldDescriptions() as $name => $fieldDescription) { - $output->writeln(sprintf( + $output->writeln(\sprintf( ' - % -25s % -15s % -15s', $name, $fieldDescription->getType() ?? '', diff --git a/src/Command/GenerateObjectAclCommand.php b/src/Command/GenerateObjectAclCommand.php index 35490b3225..542ff06447 100644 --- a/src/Command/GenerateObjectAclCommand.php +++ b/src/Command/GenerateObjectAclCommand.php @@ -66,7 +66,7 @@ public function execute(InputInterface $input, OutputInterface $output): int try { $this->getUserModelClass($input, $output); } catch (\Exception $e) { - $output->writeln(sprintf('%s', $e->getMessage())); + $output->writeln(\sprintf('%s', $e->getMessage())); return 1; } @@ -83,12 +83,12 @@ public function execute(InputInterface $input, OutputInterface $output): int $admin = $this->pool->getInstance($code); } catch (\Exception $e) { $output->writeln('Warning : The admin class cannot be initiated from the command line'); - $output->writeln(sprintf('%s', $e->getMessage())); + $output->writeln(\sprintf('%s', $e->getMessage())); continue; } - if ($input->getOption('step') && !$this->askConfirmation($input, $output, sprintf("Generate ACLs for the object instances handled by \"%s\"?\n", $code), 'no')) { + if ($input->getOption('step') && !$this->askConfirmation($input, $output, \sprintf("Generate ACLs for the object instances handled by \"%s\"?\n", $code), 'no')) { continue; } @@ -104,7 +104,7 @@ public function execute(InputInterface $input, OutputInterface $output): int $securityIdentity = new UserSecurityIdentity($objectOwner, $this->getUserModelClass($input, $output)); } - $manipulatorId = sprintf('sonata.admin.manipulator.acl.object.%s', $admin->getManagerType()); + $manipulatorId = \sprintf('sonata.admin.manipulator.acl.object.%s', $admin->getManagerType()); if (!isset($this->aclObjectManipulators[$manipulatorId])) { $output->writeln('Admin class is using a manager type that has no manipulator implemented : ignoring'); @@ -137,7 +137,7 @@ private function getUserModelClass(InputInterface $input, OutputInterface $outpu } if (!class_exists($userModelFromInput)) { - throw new \InvalidArgumentException(sprintf( + throw new \InvalidArgumentException(\sprintf( 'The "user_model" name be a fully qualified class name' .' ("%s" given, expecting something like App\Model\User)', $userModelFromInput diff --git a/src/Command/ListAdminCommand.php b/src/Command/ListAdminCommand.php index a342b15ded..43c50ce336 100644 --- a/src/Command/ListAdminCommand.php +++ b/src/Command/ListAdminCommand.php @@ -39,7 +39,7 @@ public function execute(InputInterface $input, OutputInterface $output): int $output->writeln('Admin services:'); foreach ($this->pool->getAdminServiceCodes() as $code) { $instance = $this->pool->getInstance($code); - $output->writeln(sprintf( + $output->writeln(\sprintf( ' %-40s %-60s', $code, $instance->getClass() diff --git a/src/Command/SetupAclCommand.php b/src/Command/SetupAclCommand.php index 813e229446..92e87caade 100644 --- a/src/Command/SetupAclCommand.php +++ b/src/Command/SetupAclCommand.php @@ -45,7 +45,7 @@ public function execute(InputInterface $input, OutputInterface $output): int $admin = $this->pool->getInstance($code); } catch (\Exception $e) { $output->writeln('Warning : The admin class cannot be initiated from the command line'); - $output->writeln(sprintf('%s', $e->getMessage())); + $output->writeln(\sprintf('%s', $e->getMessage())); continue; } diff --git a/src/Command/Validators.php b/src/Command/Validators.php index 958abcaf95..4a2a9aba2f 100644 --- a/src/Command/Validators.php +++ b/src/Command/Validators.php @@ -40,7 +40,7 @@ public static function validateClass(string $class): string $class = str_replace('/', '\\', $class); if (!class_exists($class)) { - throw new \InvalidArgumentException(sprintf('The class "%s" does not exist.', $class)); + throw new \InvalidArgumentException(\sprintf('The class "%s" does not exist.', $class)); } return $class; @@ -54,7 +54,7 @@ public static function validateAdminClassBasename(string $adminClassBasename): s $adminClassBasename = str_replace('/', '\\', $adminClassBasename); if (str_contains($adminClassBasename, ':')) { - throw new \InvalidArgumentException(sprintf( + throw new \InvalidArgumentException(\sprintf( 'The admin class name must not contain a ":" (colon sign)' .' ("%s" given, expecting something like PostAdmin")', $adminClassBasename @@ -72,7 +72,7 @@ public static function validateControllerClassBasename(string $controllerClassBa $controllerClassBasename = str_replace('/', '\\', $controllerClassBasename); if (str_contains($controllerClassBasename, ':')) { - throw new \InvalidArgumentException(sprintf( + throw new \InvalidArgumentException(\sprintf( 'The controller class name must not contain a ":" (colon sign)' .' ("%s" given, expecting something like PostAdminController")', $controllerClassBasename @@ -97,7 +97,7 @@ public static function validateServicesFile(string $servicesFile): string public static function validateServiceId(string $serviceId): string { if (1 === preg_match('/[^A-Za-z\._0-9]/', $serviceId, $matches)) { - throw new \InvalidArgumentException(sprintf( + throw new \InvalidArgumentException(\sprintf( 'Service ID "%s" contains invalid character "%s".', $serviceId, $matches[0] diff --git a/src/Controller/CRUDController.php b/src/Controller/CRUDController.php index 39496e8107..c19ccb8660 100644 --- a/src/Controller/CRUDController.php +++ b/src/Controller/CRUDController.php @@ -342,7 +342,7 @@ public function editAction(Request $request): Response } catch (LockException) { $this->addFlash('sonata_flash_error', $this->trans('flash_lock_error', [ '%name%' => $this->escapeHtml($this->admin->toString($existingObject)), - '%link_start%' => sprintf('', $this->admin->generateObjectUrl('edit', $existingObject)), + '%link_start%' => \sprintf('', $this->admin->generateObjectUrl('edit', $existingObject)), '%link_end%' => '', ], 'SonataAdminBundle')); } @@ -395,7 +395,7 @@ public function batchAction(Request $request): Response $restMethod = $request->getMethod(); if (Request::METHOD_POST !== $restMethod) { - throw $this->createNotFoundException(sprintf( + throw $this->createNotFoundException(\sprintf( 'Invalid request method given "%s", %s expected', $restMethod, Request::METHOD_POST @@ -450,17 +450,17 @@ public function batchAction(Request $request): Response try { $batchActionExecutable = $this->getBatchActionExecutable($action); } catch (\Throwable $error) { - $finalAction = sprintf('batchAction%s', $camelizedAction); - throw new \RuntimeException(sprintf('A `%s::%s` method must be callable or create a `controller` configuration for your batch action.', $this->admin->getBaseControllerName(), $finalAction), 0, $error); + $finalAction = \sprintf('batchAction%s', $camelizedAction); + throw new \RuntimeException(\sprintf('A `%s::%s` method must be callable or create a `controller` configuration for your batch action.', $this->admin->getBaseControllerName(), $finalAction), 0, $error); } $batchAction = $this->admin->getBatchActions()[$action]; - $isRelevantAction = sprintf('batchAction%sIsRelevant', $camelizedAction); + $isRelevantAction = \sprintf('batchAction%sIsRelevant', $camelizedAction); if (method_exists($this, $isRelevantAction)) { // NEXT_MAJOR: Remove if above in sonata-project/admin-bundle 5.0 - @trigger_error(sprintf( + @trigger_error(\sprintf( 'The is relevant hook via "%s()" is deprecated since sonata-project/admin-bundle 4.12' .' and will not be call in 5.0. Move the logic to your controller.', $isRelevantAction, @@ -711,7 +711,7 @@ public function historyAction(Request $request): Response \assert($manager instanceof AuditManagerInterface); if (!$manager->hasReader($this->admin->getClass())) { - throw $this->createNotFoundException(sprintf( + throw $this->createNotFoundException(\sprintf( 'unable to find the audit reader for class : %s', $this->admin->getClass() )); @@ -753,7 +753,7 @@ public function historyViewRevisionAction(Request $request, string $revision): R \assert($manager instanceof AuditManagerInterface); if (!$manager->hasReader($this->admin->getClass())) { - throw $this->createNotFoundException(sprintf( + throw $this->createNotFoundException(\sprintf( 'unable to find the audit reader for class : %s', $this->admin->getClass() )); @@ -765,7 +765,7 @@ public function historyViewRevisionAction(Request $request, string $revision): R $object = $reader->find($this->admin->getClass(), $objectId, $revision); if (null === $object) { - throw $this->createNotFoundException(sprintf( + throw $this->createNotFoundException(\sprintf( 'unable to find the targeted object `%s` from the revision `%s` with classname : `%s`', $objectId, $revision, @@ -806,7 +806,7 @@ public function historyCompareRevisionsAction(Request $request, string $baseRevi \assert($manager instanceof AuditManagerInterface); if (!$manager->hasReader($this->admin->getClass())) { - throw $this->createNotFoundException(sprintf( + throw $this->createNotFoundException(\sprintf( 'unable to find the audit reader for class : %s', $this->admin->getClass() )); @@ -817,7 +817,7 @@ public function historyCompareRevisionsAction(Request $request, string $baseRevi // retrieve the base revision $baseObject = $reader->find($this->admin->getClass(), $objectId, $baseRevision); if (null === $baseObject) { - throw $this->createNotFoundException(sprintf( + throw $this->createNotFoundException(\sprintf( 'unable to find the targeted object `%s` from the revision `%s` with classname : `%s`', $objectId, $baseRevision, @@ -828,7 +828,7 @@ public function historyCompareRevisionsAction(Request $request, string $baseRevi // retrieve the compare revision $compareObject = $reader->find($this->admin->getClass(), $objectId, $compareRevision); if (null === $compareObject) { - throw $this->createNotFoundException(sprintf( + throw $this->createNotFoundException(\sprintf( 'unable to find the targeted object `%s` from the revision `%s` with classname : `%s`', $objectId, $compareRevision, @@ -875,7 +875,7 @@ public function exportAction(Request $request): Response \assert($exporter instanceof ExporterInterface); if (!\in_array($format, $allowedExportFormats, true)) { - throw new \RuntimeException(sprintf( + throw new \RuntimeException(\sprintf( 'Export in format `%s` is not allowed for class: `%s`. Allowed formats are: `%s`', $format, $this->admin->getClass(), @@ -980,7 +980,7 @@ final public function configureAdmin(Request $request): void $this->admin = $admin; if (!$this->admin->hasTemplateRegistry()) { - throw new \RuntimeException(sprintf( + throw new \RuntimeException(\sprintf( 'Unable to find the template registry related to the current admin (%s).', $this->admin->getCode() )); @@ -1113,7 +1113,7 @@ protected function handleModelManagerException(\Exception $exception) return $this->handleModelManagerThrowable($exception); } - @trigger_error(sprintf( + @trigger_error(\sprintf( 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.107 and will be removed in 5.0.', __METHOD__ ), \E_USER_DEPRECATED); @@ -1288,7 +1288,7 @@ protected function getAclRoles(): \Traversable $baseRole = $admin->getSecurityHandler()->getBaseRole($admin); foreach ($admin->getSecurityInformation() as $role => $_permissions) { - $role = sprintf($baseRole, $role); + $role = \sprintf($baseRole, $role); $aclRoles[] = $role; } } @@ -1454,7 +1454,7 @@ final protected function assertObjectExists(Request $request, bool $strict = fal if (\is_string($objectId) || \is_int($objectId)) { $adminObject = $admin->getObject($objectId); if (null === $adminObject) { - throw $this->createNotFoundException(sprintf( + throw $this->createNotFoundException(\sprintf( 'Unable to find %s object with id: %s.', $admin->getClassnameLabel(), $objectId @@ -1465,7 +1465,7 @@ final protected function assertObjectExists(Request $request, bool $strict = fal $object = $adminObject; } } elseif ($strict || $admin !== $this->admin) { - throw $this->createNotFoundException(sprintf( + throw $this->createNotFoundException(\sprintf( 'Unable to find the %s object id of the admin "%s".', $admin->getClassnameLabel(), $admin::class @@ -1520,7 +1520,7 @@ final protected function checkParentChildAssociation(Request $request, object $o $parentAdminObject = $parentAdmin->getObject($parentId); if (null === $parentAdminObject) { - throw new \RuntimeException(sprintf( + throw new \RuntimeException(\sprintf( 'No object was found in the admin "%s" for the id "%s".', $parentAdmin::class, $parentId @@ -1540,7 +1540,7 @@ final protected function checkParentChildAssociation(Request $request, object $o $parentObjectMatches = $this->equalsOrContains($objectParent, $parentAdminObject); if (!$parentObjectMatches) { - throw new \RuntimeException(sprintf( + throw new \RuntimeException(\sprintf( 'There is no association between "%s" and "%s"', $parentAdmin->toString($parentAdminObject), $this->admin->toString($object) @@ -1564,13 +1564,13 @@ private function getBatchActionExecutable(string $action): callable { $batchActions = $this->admin->getBatchActions(); if (!\array_key_exists($action, $batchActions)) { - throw new \RuntimeException(sprintf('The `%s` batch action is not defined', $action)); + throw new \RuntimeException(\sprintf('The `%s` batch action is not defined', $action)); } - $controller = $batchActions[$action]['controller'] ?? sprintf( + $controller = $batchActions[$action]['controller'] ?? \sprintf( '%s::%s', $this->admin->getBaseControllerName(), - sprintf('batchAction%s', (new UnicodeString($action))->camel()->title(true)->toString()) + \sprintf('batchAction%s', (new UnicodeString($action))->camel()->title(true)->toString()) ); // This will throw an exception when called so we know if it's possible or not to call the controller. @@ -1579,7 +1579,7 @@ private function getBatchActionExecutable(string $action): callable ->getController(new Request([], [], ['_controller' => $controller])); if (!$exists) { - throw new \RuntimeException(sprintf('Controller for action `%s` cannot be resolved', $action)); + throw new \RuntimeException(\sprintf('Controller for action `%s` cannot be resolved', $action)); } return function (ProxyQueryInterface $query, Request $request) use ($controller): Response { diff --git a/src/Datagrid/Datagrid.php b/src/Datagrid/Datagrid.php index 98048744f3..1be26d43f5 100644 --- a/src/Datagrid/Datagrid.php +++ b/src/Datagrid/Datagrid.php @@ -121,7 +121,7 @@ public function removeFilter(string $name): void public function getFilter(string $name): FilterInterface { if (!$this->hasFilter($name)) { - throw new \InvalidArgumentException(sprintf( + throw new \InvalidArgumentException(\sprintf( 'Filter named "%s" doesn\'t exist.', $name )); @@ -140,7 +140,7 @@ public function reorderFilters(array $keys): void $orderedFilters = []; foreach ($keys as $name) { if (!$this->hasFilter($name)) { - throw new \InvalidArgumentException(sprintf('Filter "%s" does not exist.', $name)); + throw new \InvalidArgumentException(\sprintf('Filter "%s" does not exist.', $name)); } $orderedFilters[$name] = $this->filters[$name]; diff --git a/src/Datagrid/DatagridMapper.php b/src/Datagrid/DatagridMapper.php index ecd65fcd3e..ffbacffe20 100644 --- a/src/Datagrid/DatagridMapper.php +++ b/src/Datagrid/DatagridMapper.php @@ -74,7 +74,7 @@ public function add( } if ($this->getAdmin()->hasFilterFieldDescription($name)) { - throw new \LogicException(sprintf( + throw new \LogicException(\sprintf( 'Duplicate field name "%s" in datagrid mapper. Names should be unique.', $name )); diff --git a/src/Datagrid/ListMapper.php b/src/Datagrid/ListMapper.php index 41b47d6388..bf699c60e1 100644 --- a/src/Datagrid/ListMapper.php +++ b/src/Datagrid/ListMapper.php @@ -113,11 +113,11 @@ public function add(string $name, ?string $type = null, array $fieldDescriptionO } if (\array_key_exists('identifier', $fieldDescriptionOptions) && !\is_bool($fieldDescriptionOptions['identifier'])) { - throw new \InvalidArgumentException(sprintf('Value for "identifier" option must be boolean, %s given.', \gettype($fieldDescriptionOptions['identifier']))); + throw new \InvalidArgumentException(\sprintf('Value for "identifier" option must be boolean, %s given.', \gettype($fieldDescriptionOptions['identifier']))); } if ($this->getAdmin()->hasListFieldDescription($name)) { - throw new \LogicException(sprintf( + throw new \LogicException(\sprintf( 'Duplicate field name "%s" in list mapper. Names should be unique.', $name )); diff --git a/src/DependencyInjection/Admin/AbstractTaggedAdmin.php b/src/DependencyInjection/Admin/AbstractTaggedAdmin.php index dd0146551e..9830323683 100644 --- a/src/DependencyInjection/Admin/AbstractTaggedAdmin.php +++ b/src/DependencyInjection/Admin/AbstractTaggedAdmin.php @@ -201,7 +201,7 @@ final public function setModelClass(string $modelClass): void final public function getModelClass(): string { if (null === $this->modelClass) { - throw new \LogicException(sprintf('Admin "%s" has no model class.', static::class)); + throw new \LogicException(\sprintf('Admin "%s" has no model class.', static::class)); } return $this->modelClass; @@ -215,7 +215,7 @@ final public function setBaseControllerName(string $baseControllerName): void final public function getBaseControllerName(): string { if (null === $this->baseControllerName) { - throw new \LogicException(sprintf('Admin "%s" has no base controller name.', static::class)); + throw new \LogicException(\sprintf('Admin "%s" has no base controller name.', static::class)); } return $this->baseControllerName; @@ -259,7 +259,7 @@ final public function setManagerType(string $managerType): void final public function getManagerType(): string { if (null === $this->managerType) { - throw new \LogicException(sprintf('Admin "%s" has no manager type.', static::class)); + throw new \LogicException(\sprintf('Admin "%s" has no manager type.', static::class)); } return $this->managerType; @@ -289,7 +289,7 @@ final public function setFilterPersister(?FilterPersisterInterface $filterPersis final public function getFilterPersister(): FilterPersisterInterface { if (!$this->hasFilterPersister()) { - throw new \LogicException(sprintf('Admin "%s" has no filter persister.', static::class)); + throw new \LogicException(\sprintf('Admin "%s" has no filter persister.', static::class)); } return $this->filterPersister; @@ -311,7 +311,7 @@ final public function setModelManager(ModelManagerInterface $modelManager): void final public function getModelManager(): ModelManagerInterface { if (null === $this->modelManager) { - throw new \LogicException(sprintf('Admin "%s" has no model manager.', static::class)); + throw new \LogicException(\sprintf('Admin "%s" has no model manager.', static::class)); } return $this->modelManager; @@ -325,7 +325,7 @@ final public function setDataSource(DataSourceInterface $dataSource): void final public function getDataSource(): DataSourceInterface { if (null === $this->dataSource) { - throw new \LogicException(sprintf('Admin "%s" has no data source.', static::class)); + throw new \LogicException(\sprintf('Admin "%s" has no data source.', static::class)); } return $this->dataSource; @@ -339,7 +339,7 @@ final public function setFieldDescriptionFactory(FieldDescriptionFactoryInterfac public function getFieldDescriptionFactory(): FieldDescriptionFactoryInterface { if (null === $this->fieldDescriptionFactory) { - throw new \LogicException(sprintf( + throw new \LogicException(\sprintf( 'Admin "%s" has no field description factory.', static::class )); @@ -356,7 +356,7 @@ final public function setFormContractor(FormContractorInterface $formContractor) final public function getFormContractor(): FormContractorInterface { if (null === $this->formContractor) { - throw new \LogicException(sprintf('Admin "%s" has no form contractor.', static::class)); + throw new \LogicException(\sprintf('Admin "%s" has no form contractor.', static::class)); } return $this->formContractor; @@ -370,7 +370,7 @@ final public function setShowBuilder(ShowBuilderInterface $showBuilder): void final public function getShowBuilder(): ShowBuilderInterface { if (null === $this->showBuilder) { - throw new \LogicException(sprintf('Admin "%s" has no show builder.', static::class)); + throw new \LogicException(\sprintf('Admin "%s" has no show builder.', static::class)); } return $this->showBuilder; @@ -384,7 +384,7 @@ final public function setListBuilder(ListBuilderInterface $listBuilder): void final public function getListBuilder(): ListBuilderInterface { if (null === $this->listBuilder) { - throw new \LogicException(sprintf('Admin "%s" has no list builder.', static::class)); + throw new \LogicException(\sprintf('Admin "%s" has no list builder.', static::class)); } return $this->listBuilder; @@ -398,7 +398,7 @@ final public function setDatagridBuilder(DatagridBuilderInterface $datagridBuild final public function getDatagridBuilder(): DatagridBuilderInterface { if (null === $this->datagridBuilder) { - throw new \LogicException(sprintf('Admin "%s" has no datagrid builder.', static::class)); + throw new \LogicException(\sprintf('Admin "%s" has no datagrid builder.', static::class)); } return $this->datagridBuilder; @@ -412,7 +412,7 @@ final public function setTranslator(TranslatorInterface $translator): void final public function getTranslator(): TranslatorInterface { if (null === $this->translator) { - throw new \LogicException(sprintf('Admin "%s" has no translator.', static::class)); + throw new \LogicException(\sprintf('Admin "%s" has no translator.', static::class)); } return $this->translator; @@ -426,7 +426,7 @@ final public function setConfigurationPool(Pool $configurationPool): void final public function getConfigurationPool(): Pool { if (null === $this->configurationPool) { - throw new \LogicException(sprintf('Admin "%s" has no pool.', static::class)); + throw new \LogicException(\sprintf('Admin "%s" has no pool.', static::class)); } return $this->configurationPool; @@ -440,7 +440,7 @@ final public function setRouteGenerator(RouteGeneratorInterface $routeGenerator) final public function getRouteGenerator(): RouteGeneratorInterface { if (null === $this->routeGenerator) { - throw new \LogicException(sprintf('Admin "%s" has no route generator.', static::class)); + throw new \LogicException(\sprintf('Admin "%s" has no route generator.', static::class)); } return $this->routeGenerator; @@ -454,7 +454,7 @@ final public function setSecurityHandler(SecurityHandlerInterface $securityHandl final public function getSecurityHandler(): SecurityHandlerInterface { if (null === $this->securityHandler) { - throw new \LogicException(sprintf('Admin "%s" has no security handler.', static::class)); + throw new \LogicException(\sprintf('Admin "%s" has no security handler.', static::class)); } return $this->securityHandler; @@ -468,7 +468,7 @@ final public function setMenuFactory(FactoryInterface $menuFactory): void final public function getMenuFactory(): FactoryInterface { if (null === $this->menuFactory) { - throw new \LogicException(sprintf('Admin "%s" has no security handler.', static::class)); + throw new \LogicException(\sprintf('Admin "%s" has no security handler.', static::class)); } return $this->menuFactory; @@ -482,7 +482,7 @@ final public function setRouteBuilder(RouteBuilderInterface $routeBuilder): void final public function getRouteBuilder(): RouteBuilderInterface { if (null === $this->routeBuilder) { - throw new \LogicException(sprintf('Admin "%s" has no route builder.', static::class)); + throw new \LogicException(\sprintf('Admin "%s" has no route builder.', static::class)); } return $this->routeBuilder; @@ -496,7 +496,7 @@ final public function setLabelTranslatorStrategy(LabelTranslatorStrategyInterfac final public function getLabelTranslatorStrategy(): LabelTranslatorStrategyInterface { if (null === $this->labelTranslatorStrategy) { - throw new \LogicException(sprintf('Admin "%s" has no label translator strategy.', static::class)); + throw new \LogicException(\sprintf('Admin "%s" has no label translator strategy.', static::class)); } return $this->labelTranslatorStrategy; @@ -505,7 +505,7 @@ final public function getLabelTranslatorStrategy(): LabelTranslatorStrategyInter final public function getTemplateRegistry(): MutableTemplateRegistryInterface { if (!$this->hasTemplateRegistry()) { - throw new \LogicException(sprintf('Unable to find the template registry for admin `%s`.', static::class)); + throw new \LogicException(\sprintf('Unable to find the template registry for admin `%s`.', static::class)); } return $this->templateRegistry; diff --git a/src/DependencyInjection/Compiler/AddAuditReadersCompilerPass.php b/src/DependencyInjection/Compiler/AddAuditReadersCompilerPass.php index 889f6ac23b..52c8d2f91d 100644 --- a/src/DependencyInjection/Compiler/AddAuditReadersCompilerPass.php +++ b/src/DependencyInjection/Compiler/AddAuditReadersCompilerPass.php @@ -40,7 +40,7 @@ public function process(ContainerBuilder $container): void $serviceDefinition = $container->getDefinition($id); if (!is_subclass_of($serviceDefinition->getClass() ?? '', AuditReaderInterface::class)) { - throw new LogicException(sprintf( + throw new LogicException(\sprintf( 'Service "%s" MUST implement "%s".', $id, AuditReaderInterface::class diff --git a/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php b/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php index b6b56cf941..8a911ab9b6 100644 --- a/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php +++ b/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php @@ -79,7 +79,7 @@ public function process(ContainerBuilder $container): void foreach ($container->findTaggedServiceIds(TaggedAdminInterface::ADMIN_TAG) as $id => $tags) { if (\count($tags) > 1) { // NEXT_MAJOR: Remove deprecation error with the exception below. - @trigger_error(sprintf( + @trigger_error(\sprintf( 'Found multiple sonata.admin tags in service %s. Tagging a service with sonata.admin more than once is not supported, and will result in a RuntimeException in 5.0.', $id @@ -140,7 +140,7 @@ public function process(ContainerBuilder $container): void $default = (bool) (isset($attributes['default']) ? $parameterBag->resolveValue($attributes['default']) : false); if ($default) { if (isset($classes[$modelClass][Pool::DEFAULT_ADMIN_KEY])) { - throw new \RuntimeException(sprintf( + throw new \RuntimeException(\sprintf( 'The class %s has two admins %s and %s with the "default" attribute set to true. Only one is allowed.', $modelClass, $classes[$modelClass][Pool::DEFAULT_ADMIN_KEY], @@ -346,20 +346,20 @@ private function getDefaultMethodCalls(ContainerBuilder $container, string $serv $managerType = $attributes['manager_type'] ?? null; if (!\is_string($managerType)) { - throw new InvalidArgumentException(sprintf('Missing tag information "manager_type" on service "%s".', $serviceId)); + throw new InvalidArgumentException(\sprintf('Missing tag information "manager_type" on service "%s".', $serviceId)); } $overwriteAdminConfiguration = $container->getParameter('sonata.admin.configuration.default_admin_services'); \assert(\is_array($overwriteAdminConfiguration)); $defaultAddServices = [ - 'model_manager' => sprintf('sonata.admin.manager.%s', $managerType), - 'data_source' => sprintf('sonata.admin.data_source.%s', $managerType), - 'field_description_factory' => sprintf('sonata.admin.field_description_factory.%s', $managerType), - 'form_contractor' => sprintf('sonata.admin.builder.%s_form', $managerType), - 'show_builder' => sprintf('sonata.admin.builder.%s_show', $managerType), - 'list_builder' => sprintf('sonata.admin.builder.%s_list', $managerType), - 'datagrid_builder' => sprintf('sonata.admin.builder.%s_datagrid', $managerType), + 'model_manager' => \sprintf('sonata.admin.manager.%s', $managerType), + 'data_source' => \sprintf('sonata.admin.data_source.%s', $managerType), + 'field_description_factory' => \sprintf('sonata.admin.field_description_factory.%s', $managerType), + 'form_contractor' => \sprintf('sonata.admin.builder.%s_form', $managerType), + 'show_builder' => \sprintf('sonata.admin.builder.%s_show', $managerType), + 'list_builder' => \sprintf('sonata.admin.builder.%s_list', $managerType), + 'datagrid_builder' => \sprintf('sonata.admin.builder.%s_datagrid', $managerType), 'translator' => 'translator', 'configuration_pool' => 'sonata.admin.pool', 'route_generator' => 'sonata.admin.route.default_generator', @@ -502,7 +502,7 @@ private function fixTemplates( $definition->setMethodCalls($methods); - $templateRegistryId = sprintf('%s.template_registry', $serviceId); + $templateRegistryId = \sprintf('%s.template_registry', $serviceId); $templateRegistryDefinition = $container ->register($templateRegistryId, MutableTemplateRegistry::class) ->addTag('sonata.admin.template_registry') @@ -537,7 +537,7 @@ private function replaceDefaultArguments( $argumentValue = $declaredInParent ? $parentArguments[$index] : $arguments[$index] ?? null; if (null === $argumentValue || '' === $argumentValue) { - $arguments[$declaredInParent ? sprintf('index_%s', $index) : $index] = $value; + $arguments[$declaredInParent ? \sprintf('index_%s', $index) : $index] = $value; } } diff --git a/src/DependencyInjection/Compiler/AddFilterTypeCompilerPass.php b/src/DependencyInjection/Compiler/AddFilterTypeCompilerPass.php index f5eab65f9c..5f8da4330d 100644 --- a/src/DependencyInjection/Compiler/AddFilterTypeCompilerPass.php +++ b/src/DependencyInjection/Compiler/AddFilterTypeCompilerPass.php @@ -43,17 +43,17 @@ public function process(ContainerBuilder $container): void $class = $serviceDefinition->getClass(); if (null === $class) { - throw new InvalidArgumentException(sprintf('The service "%s" has no class.', $id)); + throw new InvalidArgumentException(\sprintf('The service "%s" has no class.', $id)); } $reflectionClass = $container->getReflectionClass($class); if (null === $reflectionClass) { - throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id)); + throw new InvalidArgumentException(\sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id)); } if (!$reflectionClass->isSubclassOf(FilterInterface::class)) { - throw new InvalidArgumentException(sprintf('Service "%s" MUST implement interface "%s".', $id, FilterInterface::class)); + throw new InvalidArgumentException(\sprintf('Service "%s" MUST implement interface "%s".', $id, FilterInterface::class)); } $services[$class] = new Reference($id); diff --git a/src/DependencyInjection/Compiler/AdminSearchCompilerPass.php b/src/DependencyInjection/Compiler/AdminSearchCompilerPass.php index 772e8ed5ca..0efa4dfbaa 100644 --- a/src/DependencyInjection/Compiler/AdminSearchCompilerPass.php +++ b/src/DependencyInjection/Compiler/AdminSearchCompilerPass.php @@ -67,7 +67,7 @@ private function getGlobalSearchValue(array $attributes, string $id): ?bool } if (!\is_bool($globalSearch)) { - throw new LogicException(sprintf( + throw new LogicException(\sprintf( 'Attribute "%s" in tag "%s" at service "%s" must be of type boolean, "%s" given.', self::TAG_ATTRIBUTE_TOGGLE_SEARCH, TaggedAdminInterface::ADMIN_TAG, diff --git a/src/DependencyInjection/Compiler/ExtensionCompilerPass.php b/src/DependencyInjection/Compiler/ExtensionCompilerPass.php index 14d7791e85..b1ae7f85ba 100644 --- a/src/DependencyInjection/Compiler/ExtensionCompilerPass.php +++ b/src/DependencyInjection/Compiler/ExtensionCompilerPass.php @@ -123,12 +123,12 @@ public function process(ContainerBuilder $container): void // NEXT_MAJOR: Remove the fallback to $defaultModelClass and use null instead. $modelClass = $attributes['model_class'] ?? $defaultModelClass; if (null === $modelClass) { - throw new InvalidArgumentException(sprintf('Missing tag attribute "model_class" on service "%s".', $id)); + throw new InvalidArgumentException(\sprintf('Missing tag attribute "model_class" on service "%s".', $id)); } $class = $container->getParameterBag()->resolveValue($modelClass); if (!\is_string($class)) { - throw new \TypeError(sprintf( + throw new \TypeError(\sprintf( 'Tag attribute "model_class" for service "%s" must be of type string, %s given.', $id, get_debug_type($class) @@ -159,7 +159,7 @@ public function process(ContainerBuilder $container): void foreach ($extensions as $extension => $attributes) { if (!$container->has($extension)) { - throw new \InvalidArgumentException(sprintf( + throw new \InvalidArgumentException(\sprintf( 'Unable to find extension service for id %s', $extension )); @@ -219,12 +219,12 @@ private function getExtensionsForAdmin(string $id, array $tags, Definition $admi // NEXT_MAJOR: Remove the fallback to $defaultModelClass and use null instead. $modelClass = $attributes['model_class'] ?? $defaultModelClass; if (null === $modelClass) { - throw new InvalidArgumentException(sprintf('Missing tag attribute "model_class" on service "%s".', $id)); + throw new InvalidArgumentException(\sprintf('Missing tag attribute "model_class" on service "%s".', $id)); } $class = $container->getParameterBag()->resolveValue($modelClass); if (!\is_string($class)) { - throw new \TypeError(sprintf( + throw new \TypeError(\sprintf( 'Tag attribute "model_class" for service "%s" must be of type string, %s given.', $id, get_debug_type($class) diff --git a/src/DependencyInjection/Compiler/ModelManagerCompilerPass.php b/src/DependencyInjection/Compiler/ModelManagerCompilerPass.php index 48fb2abc72..104d54b651 100644 --- a/src/DependencyInjection/Compiler/ModelManagerCompilerPass.php +++ b/src/DependencyInjection/Compiler/ModelManagerCompilerPass.php @@ -38,7 +38,7 @@ public function process(ContainerBuilder $container): void $class = $definition->getClass(); if (null === $class || !is_subclass_of($class, ModelManagerInterface::class)) { - throw new LogicException(sprintf( + throw new LogicException(\sprintf( 'Service "%s" must implement `%s`.', $id, ModelManagerInterface::class diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 8c6b9d64b0..851708ad67 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -392,7 +392,7 @@ public function getConfigTreeBuilder(): TreeBuilder $disallowedItems = ['items', 'label']; foreach ($disallowedItems as $item) { if (isset($items[$item])) { - throw new \InvalidArgumentException(sprintf( + throw new \InvalidArgumentException(\sprintf( 'The config value "%s" cannot be used alongside "provider" config value', $item )); diff --git a/src/DependencyInjection/SonataAdminExtension.php b/src/DependencyInjection/SonataAdminExtension.php index d4a15cac0c..f2ba0cd543 100644 --- a/src/DependencyInjection/SonataAdminExtension.php +++ b/src/DependencyInjection/SonataAdminExtension.php @@ -89,7 +89,7 @@ public function load(array $configs, ContainerBuilder $container): void $javascript = $this->buildJavascripts($config); - $config['assets']['stylesheets'][] = sprintf( + $config['assets']['stylesheets'][] = \sprintf( 'bundles/sonataadmin/admin-lte-skins/%s.min.css', $config['options']['skin'] ); diff --git a/src/Exception/AbstractClassException.php b/src/Exception/AbstractClassException.php index cf5a49c887..034e9847cc 100644 --- a/src/Exception/AbstractClassException.php +++ b/src/Exception/AbstractClassException.php @@ -23,6 +23,6 @@ final class AbstractClassException extends \InvalidArgumentException */ public function __construct(string $class) { - parent::__construct(sprintf('Cannot initialize abstract class: %s', $class)); + parent::__construct(\sprintf('Cannot initialize abstract class: %s', $class)); } } diff --git a/src/Exception/BadRequestParamHttpException.php b/src/Exception/BadRequestParamHttpException.php index 820d05c54f..368e1e0454 100644 --- a/src/Exception/BadRequestParamHttpException.php +++ b/src/Exception/BadRequestParamHttpException.php @@ -32,7 +32,7 @@ public function __construct( $expectedTypes = [$expectedTypes]; } - $message = sprintf( + $message = \sprintf( 'Expected request parameter "%s" of type "%s", %s given', $name, implode('|', $expectedTypes), diff --git a/src/FieldDescription/BaseFieldDescription.php b/src/FieldDescription/BaseFieldDescription.php index ed31ddcce7..397da240dd 100644 --- a/src/FieldDescription/BaseFieldDescription.php +++ b/src/FieldDescription/BaseFieldDescription.php @@ -237,7 +237,7 @@ final public function setParent(AdminInterface $parent): void final public function getParent(): AdminInterface { if (!$this->hasParent()) { - throw new \LogicException(sprintf('%s has no parent.', static::class)); + throw new \LogicException(\sprintf('%s has no parent.', static::class)); } return $this->parent; @@ -275,7 +275,7 @@ final public function setAssociationAdmin(AdminInterface $associationAdmin): voi final public function getAssociationAdmin(): AdminInterface { if (!$this->hasAssociationAdmin()) { - throw new \LogicException(sprintf('%s has no association admin.', static::class)); + throw new \LogicException(\sprintf('%s has no association admin.', static::class)); } return $this->associationAdmin; @@ -297,7 +297,7 @@ final public function setAdmin(AdminInterface $admin): void final public function getAdmin(): AdminInterface { if (!$this->hasAdmin()) { - throw new \LogicException(sprintf('%s has no admin.', static::class)); + throw new \LogicException(\sprintf('%s has no admin.', static::class)); } return $this->admin; @@ -318,7 +318,7 @@ final public function mergeOption(string $name, array $options = []): void } if (!\is_array($this->options[$name])) { - throw new \RuntimeException(sprintf('The key `%s` does not point to an array value', $name)); + throw new \RuntimeException(\sprintf('The key `%s` does not point to an array value', $name)); } $this->options[$name] = array_merge($this->options[$name], $options); @@ -392,7 +392,7 @@ final protected function getFieldValue(?object $object, string $fieldName): mixe if ($dotPos > 0) { $child = $this->getFieldValue($object, substr($fieldName, 0, $dotPos)); if (null !== $child && !\is_object($child)) { - throw new NoValueException(sprintf( + throw new NoValueException(\sprintf( <<<'EXCEPTION' Unexpected value when accessing to the property "%s" on the class "%s" for the field "%s". Expected object|null, got %s. @@ -413,7 +413,7 @@ final protected function getFieldValue(?object $object, string $fieldName): mixe return $accessor($object); } if (!\is_string($accessor) && !$accessor instanceof PropertyPathInterface) { - throw new \TypeError(sprintf( + throw new \TypeError(\sprintf( 'The option "accessor" must be a string, a callable or a %s, %s given.', PropertyPathInterface::class, \is_object($accessor) ? 'instance of '.$accessor::class : \gettype($accessor) @@ -428,7 +428,7 @@ final protected function getFieldValue(?object $object, string $fieldName): mixe return $propertyAccessor->getValue($object, $accessor); } catch (ExceptionInterface $exception) { throw new NoValueException( - sprintf('Cannot access property "%s" in class "%s".', $this->getName(), $this->getAdmin()->getClass()), + \sprintf('Cannot access property "%s" in class "%s".', $this->getName(), $this->getAdmin()->getClass()), $exception->getCode(), $exception ); diff --git a/src/FieldDescription/FieldDescriptionCollection.php b/src/FieldDescription/FieldDescriptionCollection.php index 379f5436bf..af1543ab97 100644 --- a/src/FieldDescription/FieldDescriptionCollection.php +++ b/src/FieldDescription/FieldDescriptionCollection.php @@ -61,7 +61,7 @@ public function has(string $name): bool public function get(string $name): FieldDescriptionInterface { if (!$this->has($name)) { - throw new \InvalidArgumentException(sprintf('Element "%s" does not exist.', $name)); + throw new \InvalidArgumentException(\sprintf('Element "%s" does not exist.', $name)); } return $this->elements[$name]; @@ -120,7 +120,7 @@ public function reorder(array $keys): void $orderedElements = []; foreach ($keys as $name) { if (!$this->has($name)) { - throw new \InvalidArgumentException(sprintf('Element "%s" does not exist.', $name)); + throw new \InvalidArgumentException(\sprintf('Element "%s" does not exist.', $name)); } $orderedElements[$name] = $this->elements[$name]; diff --git a/src/FieldDescription/TypeGuesserChain.php b/src/FieldDescription/TypeGuesserChain.php index 1eb80eac88..f24e692325 100644 --- a/src/FieldDescription/TypeGuesserChain.php +++ b/src/FieldDescription/TypeGuesserChain.php @@ -34,7 +34,7 @@ public function __construct(array $guessers) foreach ($guessers as $guesser) { if (!$guesser instanceof TypeGuesserInterface) { - throw new \InvalidArgumentException(sprintf( + throw new \InvalidArgumentException(\sprintf( 'Expected argument of type "%s", "%s" given', TypeGuesserInterface::class, get_debug_type($guesser) diff --git a/src/Filter/Filter.php b/src/Filter/Filter.php index 00198f7d5b..00d9dec826 100644 --- a/src/Filter/Filter.php +++ b/src/Filter/Filter.php @@ -50,7 +50,7 @@ final public function initialize(string $name, array $options = []): void final public function getName(): string { if (null === $this->name) { - throw new \LogicException(sprintf( + throw new \LogicException(\sprintf( 'Seems like you didn\'t call `initialize()` on the filter `%s`. Did you create it through `%s::create()`?', static::class, FilterFactory::class @@ -125,7 +125,7 @@ final public function getFieldName(): string $fieldName = $this->getOption('field_name'); if (null === $fieldName) { - throw new \RuntimeException(sprintf( + throw new \RuntimeException(\sprintf( 'The option `field_name` must be set for field: `%s`', $this->getName() )); @@ -144,7 +144,7 @@ final public function getFieldMapping(): array $fieldMapping = $this->getOption('field_mapping'); if (null === $fieldMapping) { - throw new \RuntimeException(sprintf( + throw new \RuntimeException(\sprintf( 'The option `field_mapping` must be set for field: `%s`', $this->getName() )); @@ -158,7 +158,7 @@ final public function getAssociationMapping(): array $associationMapping = $this->getOption('association_mapping'); if (null === $associationMapping) { - throw new \RuntimeException(sprintf( + throw new \RuntimeException(\sprintf( 'The option `association_mapping` must be set for field: `%s`', $this->getName() )); @@ -215,7 +215,7 @@ final public function setPreviousFilter(FilterInterface $filter): void final public function getPreviousFilter(): FilterInterface { if (!$this->hasPreviousFilter()) { - throw new \LogicException(sprintf('Filter "%s" has no previous filter.', $this->getName())); + throw new \LogicException(\sprintf('Filter "%s" has no previous filter.', $this->getName())); } return $this->previousFilter; diff --git a/src/Filter/FilterFactory.php b/src/Filter/FilterFactory.php index aff8f4a393..f4185a61c4 100644 --- a/src/Filter/FilterFactory.php +++ b/src/Filter/FilterFactory.php @@ -28,13 +28,13 @@ public function __construct( public function create(string $name, string $type, array $options = []): FilterInterface { if (!$this->container->has($type)) { - throw new \RuntimeException(sprintf('No attached service to type named `%s`', $type)); + throw new \RuntimeException(\sprintf('No attached service to type named `%s`', $type)); } $filter = $this->container->get($type); if (!$filter instanceof FilterInterface) { - throw new \RuntimeException(sprintf('The service `%s` must implement `FilterInterface`', $type)); + throw new \RuntimeException(\sprintf('The service `%s` must implement `FilterInterface`', $type)); } $filter->initialize($name, $options); diff --git a/src/Filter/Model/FilterData.php b/src/Filter/Model/FilterData.php index 36660fed97..6ca23f0a65 100644 --- a/src/Filter/Model/FilterData.php +++ b/src/Filter/Model/FilterData.php @@ -47,9 +47,9 @@ public static function fromArray(array $data): self { if (isset($data['type'])) { if (!\is_int($data['type']) && (!\is_string($data['type']) || !is_numeric($data['type']))) { - throw new \InvalidArgumentException(sprintf( + throw new \InvalidArgumentException(\sprintf( 'The "type" parameter MUST be of type "integer" or "null", "%s" given.', - \gettype($data['type']) // @phpstan-ignore-line https://github.com/phpstan/phpstan/issues/11207 + \gettype($data['type']) )); } diff --git a/src/Filter/Persister/SessionFilterPersister.php b/src/Filter/Persister/SessionFilterPersister.php index 56b5f0c224..86a97d0d20 100644 --- a/src/Filter/Persister/SessionFilterPersister.php +++ b/src/Filter/Persister/SessionFilterPersister.php @@ -48,6 +48,6 @@ public function reset(string $adminCode): void */ private function buildStorageKey(string $adminCode): string { - return sprintf('%s.filter.parameters', $adminCode); + return \sprintf('%s.filter.parameters', $adminCode); } } diff --git a/src/Form/ChoiceList/ModelChoiceLoader.php b/src/Form/ChoiceList/ModelChoiceLoader.php index 4862f6cbed..fb38afa792 100644 --- a/src/Form/ChoiceList/ModelChoiceLoader.php +++ b/src/Form/ChoiceList/ModelChoiceLoader.php @@ -67,7 +67,7 @@ public function loadChoiceList($value = null): ChoiceListInterface // Otherwise expect a __toString() method in the entity $valueObject = (string) $model; } else { - throw new TransformationFailedException(sprintf( + throw new TransformationFailedException(\sprintf( 'Unable to convert the model "%s" to string, provide "property" option' .' or implement "__toString()" method in your model.', $this->class @@ -80,7 +80,7 @@ public function loadChoiceList($value = null): ChoiceListInterface $identifier = $this->modelManager->getNormalizedIdentifier($model); if (null === $identifier) { - throw new TransformationFailedException(sprintf( + throw new TransformationFailedException(\sprintf( 'No identifier was found for the model "%s".', $this->class )); @@ -93,7 +93,7 @@ public function loadChoiceList($value = null): ChoiceListInterface foreach ($choices as $valueObject => $idx) { if (\count($idx) > 1) { // avoid issue with identical values ... foreach ($idx as $id) { - $finalChoices[sprintf('%s (id: %s)', $valueObject, $id)] = $id; + $finalChoices[\sprintf('%s (id: %s)', $valueObject, $id)] = $id; } } else { $finalChoices[$valueObject] = current($idx); diff --git a/src/Form/DataTransformer/ModelToIdPropertyTransformer.php b/src/Form/DataTransformer/ModelToIdPropertyTransformer.php index 0eb1390959..4b22c05cc4 100644 --- a/src/Form/DataTransformer/ModelToIdPropertyTransformer.php +++ b/src/Form/DataTransformer/ModelToIdPropertyTransformer.php @@ -158,7 +158,7 @@ public function transform($value): array foreach ($collection as $model) { $id = $this->modelManager->getNormalizedIdentifier($model); if (null === $id) { - throw new TransformationFailedException(sprintf( + throw new TransformationFailedException(\sprintf( 'No identifier was found for the model "%s".', $this->className )); @@ -169,7 +169,7 @@ public function transform($value): array } elseif ($model instanceof \Stringable) { $label = $model->__toString(); } else { - throw new TransformationFailedException(sprintf( + throw new TransformationFailedException(\sprintf( 'Unable to convert the model %s to String, model must have a \'__toString()\' method defined', $this->className )); diff --git a/src/Form/DataTransformer/ModelsToArrayTransformer.php b/src/Form/DataTransformer/ModelsToArrayTransformer.php index 61c3053b6f..128bab53e4 100644 --- a/src/Form/DataTransformer/ModelsToArrayTransformer.php +++ b/src/Form/DataTransformer/ModelsToArrayTransformer.php @@ -55,7 +55,7 @@ public function transform($value): array foreach ($value as $model) { $identifier = $this->modelManager->getNormalizedIdentifier($model); if (null === $identifier) { - throw new TransformationFailedException(sprintf( + throw new TransformationFailedException(\sprintf( 'No identifier was found for the model "%s".', $this->class )); @@ -101,7 +101,7 @@ public function reverseTransform($value): ?Collection foreach ($queryResult as $model) { $identifier = $this->modelManager->getNormalizedIdentifier($model); if (null === $identifier) { - throw new TransformationFailedException(sprintf( + throw new TransformationFailedException(\sprintf( 'No identifier was found for the model "%s".', $this->class )); @@ -112,7 +112,7 @@ public function reverseTransform($value): ?Collection foreach ($value as $identifier) { if (!isset($modelsById[$identifier])) { - throw new TransformationFailedException(sprintf( + throw new TransformationFailedException(\sprintf( 'No model was found for the identifier "%s".', $identifier, )); diff --git a/src/Form/Extension/Field/Type/FormTypeFieldExtension.php b/src/Form/Extension/Field/Type/FormTypeFieldExtension.php index be7324e04e..383d9705c0 100644 --- a/src/Form/Extension/Field/Type/FormTypeFieldExtension.php +++ b/src/Form/Extension/Field/Type/FormTypeFieldExtension.php @@ -106,9 +106,9 @@ public function buildView(FormView $view, FormInterface $form, array $options): $blockSuffix = preg_replace('#^_([a-z0-9]{14})_(.++)$#', '$2', $lastBlockPrefix); - $blockPrefixes[] = sprintf('%s_%s', $baseName, $baseType); - $blockPrefixes[] = sprintf('%s_%s_%s_%s', $baseName, $baseType, $view->parent->vars['name'], $view->vars['name']); - $blockPrefixes[] = sprintf('%s_%s_%s_%s', $baseName, $baseType, $view->parent->vars['name'], $blockSuffix); + $blockPrefixes[] = \sprintf('%s_%s', $baseName, $baseType); + $blockPrefixes[] = \sprintf('%s_%s_%s_%s', $baseName, $baseType, $view->parent->vars['name'], $view->vars['name']); + $blockPrefixes[] = \sprintf('%s_%s_%s_%s', $baseName, $baseType, $view->parent->vars['name'], $blockSuffix); $view->vars['block_prefixes'] = array_unique($blockPrefixes); $view->vars['sonata_admin_enabled'] = true; @@ -145,9 +145,9 @@ public function buildView(FormView $view, FormInterface $form, array $options): $blockSuffix = preg_replace('#^_([a-z0-9]{14})_(.++)$#', '$2', $lastBlockPrefix); - $blockPrefixes[] = sprintf('%s_%s', $baseName, $baseType); - $blockPrefixes[] = sprintf('%s_%s_%s', $baseName, $sonataAdmin['name'], $baseType); - $blockPrefixes[] = sprintf('%s_%s_%s_%s', $baseName, $sonataAdmin['name'], $baseType, $blockSuffix); + $blockPrefixes[] = \sprintf('%s_%s', $baseName, $baseType); + $blockPrefixes[] = \sprintf('%s_%s_%s', $baseName, $sonataAdmin['name'], $baseType); + $blockPrefixes[] = \sprintf('%s_%s_%s_%s', $baseName, $sonataAdmin['name'], $baseType, $blockSuffix); if (isset($sonataAdmin['block_name']) && false !== $sonataAdmin['block_name']) { $blockPrefixes[] = $sonataAdmin['block_name']; @@ -204,7 +204,7 @@ public function configureOptions(OptionsResolver $resolver): void */ public function getValueFromFieldDescription(?object $object, FieldDescriptionInterface $fieldDescription): mixed { - @trigger_error(sprintf( + @trigger_error(\sprintf( 'The method "%s()" is deprecated since sonata-project/admin-bundle 4.3 and will be removed in 5.0.', __METHOD__ ), \E_USER_DEPRECATED); diff --git a/src/Form/FormMapper.php b/src/Form/FormMapper.php index 543a12a60c..988690ba05 100644 --- a/src/Form/FormMapper.php +++ b/src/Form/FormMapper.php @@ -174,7 +174,7 @@ public function getFormBuilder(): FormBuilderInterface */ public function create(string $name, ?string $type = null, array $options = []): FormBuilderInterface { - @trigger_error(sprintf( + @trigger_error(\sprintf( 'The "%s()" method is deprecated since sonata-project/admin-bundle version 4.15 and will be' .' removed in 5.0 version.', __METHOD__ diff --git a/src/Form/Type/AdminType.php b/src/Form/Type/AdminType.php index 07946c1aab..371f4199a0 100644 --- a/src/Form/Type/AdminType.php +++ b/src/Form/Type/AdminType.php @@ -78,7 +78,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $parentPath = implode( '', array_map( - static fn (array $associationMapping): string => sprintf('%s.', $associationMapping['fieldName']), + static fn (array $associationMapping): string => \sprintf('%s.', $associationMapping['fieldName']), $this->getFieldDescription($options)->getParentAssociationMappings() ) ); diff --git a/src/Maker/AdminMaker.php b/src/Maker/AdminMaker.php index e3a1d294d4..c1d4261428 100644 --- a/src/Maker/AdminMaker.php +++ b/src/Maker/AdminMaker.php @@ -90,7 +90,7 @@ public function __construct( private array $availableModelManagers, private string $defaultController ) { - $this->skeletonDirectory = sprintf('%s/../Resources/skeleton', __DIR__); + $this->skeletonDirectory = \sprintf('%s/../Resources/skeleton', __DIR__); } public static function getCommandName(): string @@ -128,7 +128,7 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma $this->adminClassBasename = $io->ask( 'The admin class basename', - $input->getOption('admin') ?? sprintf('%sAdmin', $this->modelClassBasename), + $input->getOption('admin') ?? \sprintf('%sAdmin', $this->modelClassBasename), [Validators::class, 'validateAdminClassBasename'] ); if (\count($this->availableModelManagers) > 1) { @@ -140,13 +140,13 @@ public function interact(InputInterface $input, ConsoleStyle $io, Command $comma if ($io->confirm('Do you want to generate a controller?', false)) { $this->controllerClassBasename = $io->ask( 'The controller class basename', - $input->getOption('controller') ?? sprintf('%sAdminController', $this->modelClassBasename), + $input->getOption('controller') ?? \sprintf('%sAdminController', $this->modelClassBasename), [Validators::class, 'validateControllerClassBasename'] ); $input->setOption('controller', $this->controllerClassBasename); } if ($io->confirm('Do you want to update the services YAML configuration file?', true)) { - $path = sprintf('%s/config/', $this->projectDirectory); + $path = \sprintf('%s/config/', $this->projectDirectory); $servicesFile = $io->ask( 'The services YAML configuration file', $input->getOption('services') ?? (is_file($path.'admin.yaml') ? 'admin.yaml' : 'services.yaml'), @@ -206,7 +206,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen private function getAdminServiceId(string $adminClassBasename): string { - return Container::underscore(sprintf( + return Container::underscore(\sprintf( 'admin.%s', str_replace('\\', '.', str_ends_with($adminClassBasename, 'Admin') ? substr($adminClassBasename, 0, -5) : $adminClassBasename) @@ -224,7 +224,7 @@ private function generateService( ): void { $servicesFile = $input->getOption('services'); if (null !== $servicesFile) { - $file = sprintf('%s/config/%s', $this->projectDirectory, $servicesFile); + $file = \sprintf('%s/config/%s', $this->projectDirectory, $servicesFile); $servicesManipulator = new ServicesManipulator($file); $controllerName = null !== $this->controllerClassBasename ? $controllerClassFullName : '~'; @@ -238,7 +238,7 @@ private function generateService( substr($this->managerType, \strlen('sonata.admin.manager.')) ); - $io->writeln(sprintf( + $io->writeln(\sprintf( '%sThe service "%s" has been appended to the file "%s".', \PHP_EOL, $id, @@ -255,14 +255,14 @@ private function generateController( $controllerClassFullName = $controllerClassNameDetails->getFullName(); $generator->generateClass( $controllerClassFullName, - sprintf('%s/AdminController.tpl.php', $this->skeletonDirectory), + \sprintf('%s/AdminController.tpl.php', $this->skeletonDirectory), [ 'default_controller' => $this->defaultController, 'default_controller_short_name' => Str::getShortClassName($this->defaultController), ] ); $generator->writeChanges(); - $io->writeln(sprintf( + $io->writeln(\sprintf( '%sThe controller class "%s" has been generated under the file "%s".', \PHP_EOL, $controllerClassNameDetails->getShortName(), @@ -280,20 +280,20 @@ private function generateAdmin( $fields = $this->modelManager->getExportFields($this->modelClass); $fieldString = ''; foreach ($fields as $field) { - $fieldString = $fieldString.sprintf('%12s', '')."->add('".$field."')".\PHP_EOL; + $fieldString = $fieldString.\sprintf('%12s', '')."->add('".$field."')".\PHP_EOL; } - $fieldString .= sprintf('%12s', ''); + $fieldString .= \sprintf('%12s', ''); $generator->generateClass( $adminClassFullName, - sprintf('%s/Admin.tpl.php', $this->skeletonDirectory), + \sprintf('%s/Admin.tpl.php', $this->skeletonDirectory), ['fields' => $fieldString] ); $generator->writeChanges(); - $io->writeln(sprintf( + $io->writeln(\sprintf( '%sThe admin class "%s" has been generated under the file "%s".', \PHP_EOL, $adminClassNameDetails->getShortName(), @@ -306,7 +306,7 @@ private function configure(InputInterface $input): void $this->modelClass = Validators::validateClass($input->getArgument('model')); $this->modelClassBasename = (new \ReflectionClass($this->modelClass))->getShortName(); $this->adminClassBasename = Validators::validateAdminClassBasename( - $input->getOption('admin') ?? sprintf('%sAdmin', $this->modelClassBasename) + $input->getOption('admin') ?? \sprintf('%sAdmin', $this->modelClassBasename) ); $this->controllerClassBasename = $input->getOption('controller'); diff --git a/src/Manipulator/ServicesManipulator.php b/src/Manipulator/ServicesManipulator.php index 8fdbc2b23a..ea967d78ad 100644 --- a/src/Manipulator/ServicesManipulator.php +++ b/src/Manipulator/ServicesManipulator.php @@ -45,7 +45,7 @@ public function addResource(string $serviceId, string $modelClass, string $admin if (is_file($this->file)) { $content = file_get_contents($this->file); if (false === $content) { - throw new \RuntimeException(sprintf('Cannot read the file "%s".', realpath($this->file))); + throw new \RuntimeException(\sprintf('Cannot read the file "%s".', realpath($this->file))); } $code = rtrim($content); @@ -57,7 +57,7 @@ public function addResource(string $serviceId, string $modelClass, string $admin if (\array_key_exists('services', $data)) { if (\array_key_exists($serviceId, (array) $data['services'])) { - throw new \RuntimeException(sprintf( + throw new \RuntimeException(\sprintf( 'The service "%s" is already defined in the file "%s".', $serviceId, realpath($this->file) @@ -73,7 +73,7 @@ public function addResource(string $serviceId, string $modelClass, string $admin } } - $code .= sprintf( + $code .= \sprintf( $this->template, $serviceId, $adminClass, @@ -85,7 +85,7 @@ public function addResource(string $serviceId, string $modelClass, string $admin @mkdir(\dirname($this->file), 0777, true); if (false === @file_put_contents($this->file, $code)) { - throw new \RuntimeException(sprintf( + throw new \RuntimeException(\sprintf( 'Unable to append service "%s" to the file "%s". You will have to do it manually.', $serviceId, $this->file diff --git a/src/Mapper/BaseGroupedMapper.php b/src/Mapper/BaseGroupedMapper.php index dbdd34170a..e56d74540e 100644 --- a/src/Mapper/BaseGroupedMapper.php +++ b/src/Mapper/BaseGroupedMapper.php @@ -96,7 +96,7 @@ final public function with(string $name, array $options = []): self throw new \LogicException('New tab was added automatically when you have added field or group. You should close current tab before adding new one OR add tabs before adding groups and fields.'); } - throw new \LogicException(sprintf( + throw new \LogicException(\sprintf( 'You should close previous tab "%s" with end() before adding new tab "%s".', $this->currentTab, $name @@ -104,7 +104,7 @@ final public function with(string $name, array $options = []): self } if (null !== $this->currentGroup) { - throw new \LogicException(sprintf('You should open tab before adding new group "%s".', $name)); + throw new \LogicException(\sprintf('You should open tab before adding new group "%s".', $name)); } if (!isset($tabs[$name])) { @@ -119,7 +119,7 @@ final public function with(string $name, array $options = []): self $this->currentTab = $code; } else { if (null !== $this->currentGroup) { - throw new \LogicException(sprintf( + throw new \LogicException(\sprintf( 'You should close previous group "%s" with end() before adding new tab "%s".', $this->currentGroup, $name @@ -139,7 +139,7 @@ final public function with(string $name, array $options = []): self // if no tab is selected, we go the the main one named '_' .. if ('default' !== $this->currentTab) { // groups with the same name can be on different tabs, so we prefix them in order to make unique group name - $code = sprintf('%s.%s', $this->currentTab, $name); + $code = \sprintf('%s.%s', $this->currentTab, $name); } $groups = $this->getGroups(); @@ -264,7 +264,7 @@ final public function removeGroup(string $group, string $tab = 'default', bool $ // When the default tab is used, the tabname is not prepended to the index in the group array if ('default' !== $tab) { - $group = sprintf('%s.%s', $tab, $group); + $group = \sprintf('%s.%s', $tab, $group); } if (isset($groups[$group])) { diff --git a/src/Model/AuditManager.php b/src/Model/AuditManager.php index dc50e7e4eb..873fd39ff1 100644 --- a/src/Model/AuditManager.php +++ b/src/Model/AuditManager.php @@ -59,7 +59,7 @@ public function getReader(string $class): AuditReaderInterface if (\in_array($class, $classes, true)) { $service = $this->container->get($readerId); if (!$service instanceof AuditReaderInterface) { - throw new \LogicException(sprintf( + throw new \LogicException(\sprintf( 'Service "%s" MUST implement interface "%s".', $readerId, AuditReaderInterface::class, @@ -73,6 +73,6 @@ public function getReader(string $class): AuditReaderInterface } } - throw new \LogicException(sprintf('The class "%s" does not have any reader manager', $class)); + throw new \LogicException(\sprintf('The class "%s" does not have any reader manager', $class)); } } diff --git a/src/Request/AdminFetcher.php b/src/Request/AdminFetcher.php index 24d7e7ed8a..51366a4d26 100644 --- a/src/Request/AdminFetcher.php +++ b/src/Request/AdminFetcher.php @@ -32,7 +32,7 @@ public function get(Request $request): AdminInterface $route = $request->get('_route', ''); \assert(\is_string($route)); - throw new \InvalidArgumentException(sprintf( + throw new \InvalidArgumentException(\sprintf( 'There is no `_sonata_admin` defined for the current route `%s`.', $route )); diff --git a/src/Route/DefaultRouteGenerator.php b/src/Route/DefaultRouteGenerator.php index 70705090b1..12beaf749e 100644 --- a/src/Route/DefaultRouteGenerator.php +++ b/src/Route/DefaultRouteGenerator.php @@ -106,7 +106,7 @@ public function generateMenuUrl( $code = $this->getCode($admin, $name); if (!\array_key_exists($code, $this->caches)) { - throw new \RuntimeException(sprintf('unable to find the route `%s`', $code)); + throw new \RuntimeException(\sprintf('unable to find the route `%s`', $code)); } return [ @@ -132,18 +132,18 @@ private function getCode(AdminInterface $admin, string $name): string // Someone provided the full name if ( - str_starts_with($name, sprintf('%s|', $codePrefix)) // Child admin route already prefixed - || str_starts_with($name, sprintf('%s.', $codePrefix)) // admin route already prefixed + str_starts_with($name, \sprintf('%s|', $codePrefix)) // Child admin route already prefixed + || str_starts_with($name, \sprintf('%s.', $codePrefix)) // admin route already prefixed ) { return $name; } // Someone provided a code, so it is a child if (strpos($name, '.') > 0) { - return sprintf('%s|%s', $codePrefix, $name); + return \sprintf('%s|%s', $codePrefix, $name); } - return sprintf('%s.%s', $codePrefix, $name); + return \sprintf('%s.%s', $codePrefix, $name); } /** diff --git a/src/Route/PathInfoBuilder.php b/src/Route/PathInfoBuilder.php index 000f7493eb..0fb019c195 100644 --- a/src/Route/PathInfoBuilder.php +++ b/src/Route/PathInfoBuilder.php @@ -32,19 +32,19 @@ public function build(AdminInterface $admin, RouteCollectionInterface $collectio $collection->add('list'); $collection->add('create'); $collection->add('batch'); - $collection->add('edit', sprintf('%s/edit', $admin->getRouterIdParameter())); - $collection->add('delete', sprintf('%s/delete', $admin->getRouterIdParameter())); - $collection->add('show', sprintf('%s/show', $admin->getRouterIdParameter())); + $collection->add('edit', \sprintf('%s/edit', $admin->getRouterIdParameter())); + $collection->add('delete', \sprintf('%s/delete', $admin->getRouterIdParameter())); + $collection->add('show', \sprintf('%s/show', $admin->getRouterIdParameter())); $collection->add('export'); if ($this->manager->hasReader($admin->getClass())) { - $collection->add('history', sprintf('%s/history', $admin->getRouterIdParameter())); - $collection->add('history_view_revision', sprintf('%s/history/{revision}/view', $admin->getRouterIdParameter())); - $collection->add('history_compare_revisions', sprintf('%s/history/{baseRevision}/{compareRevision}/compare', $admin->getRouterIdParameter())); + $collection->add('history', \sprintf('%s/history', $admin->getRouterIdParameter())); + $collection->add('history_view_revision', \sprintf('%s/history/{revision}/view', $admin->getRouterIdParameter())); + $collection->add('history_compare_revisions', \sprintf('%s/history/{baseRevision}/{compareRevision}/compare', $admin->getRouterIdParameter())); } if ($admin->isAclEnabled()) { - $collection->add('acl', sprintf('%s/acl', $admin->getRouterIdParameter())); + $collection->add('acl', \sprintf('%s/acl', $admin->getRouterIdParameter())); } // add children urls diff --git a/src/Route/RouteCollection.php b/src/Route/RouteCollection.php index 69d6ea44d0..d0e48ee355 100644 --- a/src/Route/RouteCollection.php +++ b/src/Route/RouteCollection.php @@ -40,7 +40,7 @@ public function __construct( public function getRouteName(string $name): string { - return sprintf('%s_%s', $this->baseRouteName, $name); + return \sprintf('%s_%s', $this->baseRouteName, $name); } public function add( @@ -54,7 +54,7 @@ public function add( array $methods = [], string $condition = '' ): self { - $pattern = sprintf('%s/%s', $this->baseRoutePattern, $pattern ?? $name); + $pattern = \sprintf('%s/%s', $this->baseRoutePattern, $pattern ?? $name); $code = $this->getCode($name); if (!isset($defaults['_controller'])) { @@ -81,7 +81,7 @@ public function getCode(string $name): string return $name; } - return sprintf('%s.%s', $this->baseCodeRoute, $name); + return \sprintf('%s.%s', $this->baseCodeRoute, $name); } public function addCollection(RouteCollectionInterface $collection): self @@ -124,7 +124,7 @@ public function get(string $name): Route return $this->elements[$code]; } - throw new \InvalidArgumentException(sprintf('Element "%s" does not exist.', $name)); + throw new \InvalidArgumentException(\sprintf('Element "%s" does not exist.', $name)); } public function remove(string $name): self @@ -143,7 +143,7 @@ public function restore(string $name): self return $this; } - throw new \InvalidArgumentException(sprintf('Element "%s" does not exist in cache.', $name)); + throw new \InvalidArgumentException(\sprintf('Element "%s" does not exist in cache.', $name)); } public function clearExcept($routeList): self @@ -230,7 +230,7 @@ private function resolveElement(string $code): void if (\is_callable($element)) { $resolvedElement = $element(); if (!$resolvedElement instanceof Route) { - throw new \TypeError(sprintf( + throw new \TypeError(\sprintf( 'Element resolved by code "%s" must be an instance of "%s"', $code, Route::class diff --git a/src/Route/RoutesCache.php b/src/Route/RoutesCache.php index a8b559345c..d21e4d10b4 100644 --- a/src/Route/RoutesCache.php +++ b/src/Route/RoutesCache.php @@ -40,7 +40,7 @@ public function __construct( */ public function load(AdminInterface $admin): array { - $filename = sprintf('%s/route_%s', $this->cacheFolder, md5($admin->getCode())); + $filename = \sprintf('%s/route_%s', $this->cacheFolder, md5($admin->getCode())); $cache = new ConfigCache($filename, $this->debug); if ($cache->isFresh()) { diff --git a/src/Security/Handler/AclSecurityHandler.php b/src/Security/Handler/AclSecurityHandler.php index 3338266d07..6d1a644edc 100644 --- a/src/Security/Handler/AclSecurityHandler.php +++ b/src/Security/Handler/AclSecurityHandler.php @@ -63,7 +63,7 @@ public function __construct( ) { // NEXT_MAJOR: Keep only the elseif part and add typehint. if (\is_array($superAdminRoles)) { - @trigger_error(sprintf( + @trigger_error(\sprintf( 'Passing an array as argument 1 of "%s()" is deprecated since sonata-project/admin-bundle 4.6' .' and will throw an error in 5.0. You MUST pass a string instead.', __METHOD__ @@ -73,7 +73,7 @@ public function __construct( } elseif (\is_string($superAdminRoles)) { $this->superAdminRoles = [$superAdminRoles]; } else { - throw new \TypeError(sprintf( + throw new \TypeError(\sprintf( 'Argument 1 passed to "%s()" must be of type "array" or "string", "%s" given.', __METHOD__, \gettype($superAdminRoles) @@ -105,7 +105,7 @@ public function isGranted(AdminInterface $admin, $attributes, ?object $object = { // NEXT_MAJOR: Remove this and add string typehint to $attributes and rename it $attribute. if (\is_array($attributes)) { - @trigger_error(sprintf( + @trigger_error(\sprintf( 'Passing an array as argument 1 of "%s()" is deprecated since sonata-project/admin-bundle 4.6' .' and will throw an error in 5.0. You MUST pass a string instead.', __METHOD__ @@ -128,7 +128,7 @@ public function isGranted(AdminInterface $admin, $attributes, ?object $object = public function getBaseRole(AdminInterface $admin): string { - return sprintf('ROLE_%s_%%s', str_replace('.', '_', strtoupper($admin->getCode()))); + return \sprintf('ROLE_%s_%%s', str_replace('.', '_', strtoupper($admin->getCode()))); } public function buildSecurityInformation(AdminInterface $admin): array @@ -137,7 +137,7 @@ public function buildSecurityInformation(AdminInterface $admin): array $results = []; foreach ($admin->getSecurityInformation() as $role => $permissions) { - $results[sprintf($baseRole, $role)] = $permissions; + $results[\sprintf($baseRole, $role)] = $permissions; } return $results; diff --git a/src/Security/Handler/RoleSecurityHandler.php b/src/Security/Handler/RoleSecurityHandler.php index e986a87f76..47ab0db126 100644 --- a/src/Security/Handler/RoleSecurityHandler.php +++ b/src/Security/Handler/RoleSecurityHandler.php @@ -37,7 +37,7 @@ public function __construct( ) { // NEXT_MAJOR: Keep only the elseif part and add typehint. if (\is_array($superAdminRoles)) { - @trigger_error(sprintf( + @trigger_error(\sprintf( 'Passing an array as argument 1 of "%s()" is deprecated since sonata-project/admin-bundle 4.6' .' and will throw an error in 5.0. You MUST pass a string instead.', __METHOD__ @@ -47,7 +47,7 @@ public function __construct( } elseif (\is_string($superAdminRoles)) { $this->superAdminRoles = [$superAdminRoles]; } else { - throw new \TypeError(sprintf( + throw new \TypeError(\sprintf( 'Argument 1 passed to "%s()" must be of type "array" or "string", "%s" given.', __METHOD__, \gettype($superAdminRoles) @@ -59,7 +59,7 @@ public function isGranted(AdminInterface $admin, $attributes, ?object $object = { // NEXT_MAJOR: Remove this and add string typehint to $attributes and rename it $attribute. if (\is_array($attributes)) { - @trigger_error(sprintf( + @trigger_error(\sprintf( 'Passing an array as argument 1 of "%s()" is deprecated since sonata-project/admin-bundle 4.6' .' and will throw an error in 5.0. You MUST pass a string instead.', __METHOD__ @@ -73,7 +73,7 @@ public function isGranted(AdminInterface $admin, $attributes, ?object $object = $useAll = $this->hasOnlyAdminRoles($attributes); $attributes = $this->mapAttributes($attributes, $admin); - $allRole = sprintf($this->getBaseRole($admin), 'ALL'); + $allRole = \sprintf($this->getBaseRole($admin), 'ALL'); try { // NEXT_MAJOR: Remove the method isAnyGranted and use $this->authorizationChecker->isGranted instead. @@ -87,7 +87,7 @@ public function isGranted(AdminInterface $admin, $attributes, ?object $object = public function getBaseRole(AdminInterface $admin): string { - return sprintf('ROLE_%s_%%s', str_replace('.', '_', strtoupper($admin->getCode()))); + return \sprintf('ROLE_%s_%%s', str_replace('.', '_', strtoupper($admin->getCode()))); } public function buildSecurityInformation(AdminInterface $admin): array @@ -152,11 +152,11 @@ private function mapAttributes(array $attributes, AdminInterface $admin): array $baseRole = $this->getBaseRole($admin); - $mappedAttributes[] = sprintf($baseRole, $attribute); + $mappedAttributes[] = \sprintf($baseRole, $attribute); foreach ($admin->getSecurityInformation() as $role => $permissions) { if (\in_array($attribute, $permissions, true)) { - $mappedAttributes[] = sprintf($baseRole, $role); + $mappedAttributes[] = \sprintf($baseRole, $role); } } } diff --git a/src/Show/ShowMapper.php b/src/Show/ShowMapper.php index 1d10104f36..2f2a3a318c 100644 --- a/src/Show/ShowMapper.php +++ b/src/Show/ShowMapper.php @@ -76,7 +76,7 @@ public function add(string $name, ?string $type = null, array $fieldDescriptionO $fieldDescriptionOptions ); } else { - throw new \LogicException(sprintf( + throw new \LogicException(\sprintf( 'Duplicate field name "%s" in show mapper. Names should be unique.', $name )); diff --git a/src/Templating/AbstractTemplateRegistry.php b/src/Templating/AbstractTemplateRegistry.php index 04349a8f98..6e7e98c6be 100644 --- a/src/Templating/AbstractTemplateRegistry.php +++ b/src/Templating/AbstractTemplateRegistry.php @@ -44,6 +44,6 @@ final public function getTemplate(string $name): string return $this->templates[$name]; } - throw new \InvalidArgumentException(sprintf('Template named "%s" doesn\'t exist.', $name)); + throw new \InvalidArgumentException(\sprintf('Template named "%s" doesn\'t exist.', $name)); } } diff --git a/src/Translator/BCLabelTranslatorStrategy.php b/src/Translator/BCLabelTranslatorStrategy.php index 8ea85fdee2..0cdadc396f 100644 --- a/src/Translator/BCLabelTranslatorStrategy.php +++ b/src/Translator/BCLabelTranslatorStrategy.php @@ -24,14 +24,14 @@ final class BCLabelTranslatorStrategy implements LabelTranslatorStrategyInterfac { public function getLabel(string $label, string $context = '', string $type = ''): string { - @trigger_error(sprintf( + @trigger_error(\sprintf( 'The "%s" class is deprecated since sonata-project/admin-bundle version 4.19 and will be' .' removed in 5.0 version.', self::class ), \E_USER_DEPRECATED); if ('breadcrumb' === $context) { - return sprintf('%s.%s_%s', $context, $type, strtolower($label)); + return \sprintf('%s.%s_%s', $context, $type, strtolower($label)); } return ucfirst(strtolower($label)); diff --git a/src/Translator/UnderscoreLabelTranslatorStrategy.php b/src/Translator/UnderscoreLabelTranslatorStrategy.php index 147e5e9e00..7124c80eca 100644 --- a/src/Translator/UnderscoreLabelTranslatorStrategy.php +++ b/src/Translator/UnderscoreLabelTranslatorStrategy.php @@ -22,6 +22,6 @@ public function getLabel(string $label, string $context = '', string $type = '') { $label = str_replace('.', '_', $label); - return sprintf('%s.%s_%s', $context, $type, strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $label) ?? '')); + return \sprintf('%s.%s_%s', $context, $type, strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $label) ?? '')); } } diff --git a/src/Twig/Extension/BreadcrumbsExtension.php b/src/Twig/Extension/BreadcrumbsExtension.php index 0ef5d8f08a..8e5df3241a 100644 --- a/src/Twig/Extension/BreadcrumbsExtension.php +++ b/src/Twig/Extension/BreadcrumbsExtension.php @@ -63,7 +63,7 @@ public function renderBreadcrumbs( AdminInterface $admin, string $action ): string { - @trigger_error(sprintf( + @trigger_error(\sprintf( 'The method "%s()" is deprecated since sonata-project/admin-bundle 4.7 and will be removed in 5.0.' .' Use "%s::%s()" instead.', __METHOD__, @@ -89,7 +89,7 @@ public function renderBreadcrumbsForTitle( AdminInterface $admin, string $action ): string { - @trigger_error(sprintf( + @trigger_error(\sprintf( 'The method "%s()" is deprecated since sonata-project/admin-bundle 4.7 and will be removed in 5.0.' .' Use "%s::%s()" instead.', __METHOD__, diff --git a/src/Twig/Extension/CanonicalizeExtension.php b/src/Twig/Extension/CanonicalizeExtension.php index fbde2ec131..834a7a6aef 100644 --- a/src/Twig/Extension/CanonicalizeExtension.php +++ b/src/Twig/Extension/CanonicalizeExtension.php @@ -50,7 +50,7 @@ public function getFunctions(): array */ public function getCanonicalizedLocaleForMoment(): ?string { - @trigger_error(sprintf( + @trigger_error(\sprintf( 'The method "%s()" is deprecated since sonata-project/admin-bundle 4.7 and will be removed in 5.0.' .' Use "%s::%s()" instead.', __METHOD__, @@ -71,7 +71,7 @@ public function getCanonicalizedLocaleForMoment(): ?string */ public function getCanonicalizedLocaleForSelect2(): ?string { - @trigger_error(sprintf( + @trigger_error(\sprintf( 'The method "%s()" is deprecated since sonata-project/admin-bundle 4.7 and will be removed in 5.0.' .' Use "%s::%s()" instead.', __METHOD__, diff --git a/src/Twig/Extension/GroupExtension.php b/src/Twig/Extension/GroupExtension.php index d99eaeecd6..165bda1645 100644 --- a/src/Twig/Extension/GroupExtension.php +++ b/src/Twig/Extension/GroupExtension.php @@ -63,7 +63,7 @@ public function getFunctions(): array */ public function getDashboardGroupsWithCreatableAdmins(): array { - @trigger_error(sprintf( + @trigger_error(\sprintf( 'The method "%s()" is deprecated since sonata-project/admin-bundle 4.7 and will be removed in 5.0.' .' Use "%s::%s()" instead.', __METHOD__, diff --git a/src/Twig/Extension/IconExtension.php b/src/Twig/Extension/IconExtension.php index d0ed4f38b4..ae9f4dfc31 100644 --- a/src/Twig/Extension/IconExtension.php +++ b/src/Twig/Extension/IconExtension.php @@ -43,7 +43,7 @@ public function getFilters(): array */ public function parseIcon(string $icon): string { - @trigger_error(sprintf( + @trigger_error(\sprintf( 'The method "%s()" is deprecated since sonata-project/admin-bundle 4.7 and will be removed in 5.0.' .' Use "%s::%s()" instead.', __METHOD__, diff --git a/src/Twig/Extension/RenderElementExtension.php b/src/Twig/Extension/RenderElementExtension.php index 538c918081..44beb9c767 100644 --- a/src/Twig/Extension/RenderElementExtension.php +++ b/src/Twig/Extension/RenderElementExtension.php @@ -84,7 +84,7 @@ public function renderListElement( FieldDescriptionInterface $fieldDescription, array $params = [] ): string { - @trigger_error(sprintf( + @trigger_error(\sprintf( 'The method "%s()" is deprecated since sonata-project/admin-bundle 4.7 and will be removed in 5.0.' .' Use "%s::%s()" instead.', __METHOD__, @@ -105,7 +105,7 @@ public function renderViewElement( FieldDescriptionInterface $fieldDescription, object $object ): string { - @trigger_error(sprintf( + @trigger_error(\sprintf( 'The method "%s()" is deprecated since sonata-project/admin-bundle 4.7 and will be removed in 5.0.' .' Use "%s::%s()" instead.', __METHOD__, @@ -129,7 +129,7 @@ public function renderViewElementCompare( mixed $baseObject, mixed $compareObject ): string { - @trigger_error(sprintf( + @trigger_error(\sprintf( 'The method "%s()" is deprecated since sonata-project/admin-bundle 4.7 and will be removed in 5.0.' .' Use "%s::%s()" instead.', __METHOD__, @@ -149,7 +149,7 @@ public function renderViewElementCompare( */ public function renderRelationElement(mixed $element, FieldDescriptionInterface $fieldDescription): mixed { - @trigger_error(sprintf( + @trigger_error(\sprintf( 'The method "%s()" is deprecated since sonata-project/admin-bundle 4.7 and will be removed in 5.0.' .' Use "%s::%s()" instead.', __METHOD__, diff --git a/src/Twig/Extension/SecurityExtension.php b/src/Twig/Extension/SecurityExtension.php index c3b4f28ff8..9ec688c658 100644 --- a/src/Twig/Extension/SecurityExtension.php +++ b/src/Twig/Extension/SecurityExtension.php @@ -48,7 +48,7 @@ public function getFunctions(): array */ public function isGrantedAffirmative(string|array $role, ?object $object = null, ?string $field = null): bool { - @trigger_error(sprintf( + @trigger_error(\sprintf( 'The method "%s()" is deprecated since sonata-project/admin-bundle 4.7 and will be removed in 5.0.' .' Use "%s::%s()" instead.', __METHOD__, diff --git a/src/Twig/Extension/SonataAdminExtension.php b/src/Twig/Extension/SonataAdminExtension.php index 1779c037c2..8c9be89111 100644 --- a/src/Twig/Extension/SonataAdminExtension.php +++ b/src/Twig/Extension/SonataAdminExtension.php @@ -66,7 +66,7 @@ public function getName(): string */ public function getUrlSafeIdentifier(object $model, ?AdminInterface $admin = null): ?string { - @trigger_error(sprintf( + @trigger_error(\sprintf( 'The method "%s()" is deprecated since sonata-project/admin-bundle 4.7 and will be removed in 5.0.' .' Use "%s::%s()" instead.', __METHOD__, diff --git a/src/Twig/Extension/TemplateRegistryExtension.php b/src/Twig/Extension/TemplateRegistryExtension.php index 8d87fed8b4..6d71d0217e 100644 --- a/src/Twig/Extension/TemplateRegistryExtension.php +++ b/src/Twig/Extension/TemplateRegistryExtension.php @@ -52,7 +52,7 @@ public function getFunctions(): array */ public function getAdminTemplate(string $name, string $adminCode): string { - @trigger_error(sprintf( + @trigger_error(\sprintf( 'The method "%s()" is deprecated since sonata-project/admin-bundle 4.7 and will be removed in 5.0.' .' Use "%s::%s()" instead.', __METHOD__, @@ -70,7 +70,7 @@ public function getAdminTemplate(string $name, string $adminCode): string */ public function getGlobalTemplate(string $name): string { - @trigger_error(sprintf( + @trigger_error(\sprintf( 'The method "%s()" is deprecated since sonata-project/admin-bundle 4.7 and will be removed in 5.0.' .' Use "%s::%s()" instead.', __METHOD__, diff --git a/src/Twig/Extension/XEditableExtension.php b/src/Twig/Extension/XEditableExtension.php index dcce29ad13..8ff273e207 100644 --- a/src/Twig/Extension/XEditableExtension.php +++ b/src/Twig/Extension/XEditableExtension.php @@ -69,7 +69,7 @@ public function getFilters(): array */ public function getXEditableType(?string $type): string|bool { - @trigger_error(sprintf( + @trigger_error(\sprintf( 'The method "%s()" is deprecated since sonata-project/admin-bundle 4.7 and will be removed in 5.0.' .' Use "%s::%s()" instead.', __METHOD__, @@ -95,7 +95,7 @@ public function getXEditableType(?string $type): string|bool */ public function getXEditableChoices(FieldDescriptionInterface $fieldDescription): array { - @trigger_error(sprintf( + @trigger_error(\sprintf( 'The method "%s()" is deprecated since sonata-project/admin-bundle 4.7 and will be removed in 5.0.' .' Use "%s::%s()" instead.', __METHOD__, diff --git a/src/Twig/IconRuntime.php b/src/Twig/IconRuntime.php index db8e83df11..2b77660517 100644 --- a/src/Twig/IconRuntime.php +++ b/src/Twig/IconRuntime.php @@ -31,9 +31,9 @@ public function parseIcon(string $icon): string && !str_starts_with($icon, 'fal ') && !str_starts_with($icon, 'fad ') ) { - throw new \InvalidArgumentException(sprintf('The icon format "%s" is not supported.', $icon)); + throw new \InvalidArgumentException(\sprintf('The icon format "%s" is not supported.', $icon)); } - return sprintf('', $icon); + return \sprintf('', $icon); } } diff --git a/src/Twig/RenderElementRuntime.php b/src/Twig/RenderElementRuntime.php index 5aa7b61c02..2ee61d98b7 100644 --- a/src/Twig/RenderElementRuntime.php +++ b/src/Twig/RenderElementRuntime.php @@ -136,7 +136,7 @@ public function renderRelationElement(mixed $element, FieldDescriptionInterface if (null === $propertyPath) { if (!method_exists($element, '__toString')) { - throw new \RuntimeException(sprintf( + throw new \RuntimeException(\sprintf( 'You must define an `associated_property` option or create a `%s::__toString` method' .' to the field option %s from service %s is ', $element::class, @@ -153,7 +153,7 @@ public function renderRelationElement(mixed $element, FieldDescriptionInterface } if (!\is_string($propertyPath) && !$propertyPath instanceof PropertyPathInterface) { - throw new \TypeError(sprintf( + throw new \TypeError(\sprintf( 'The option "associated_property" must be a string, a callable or a %s, %s given.', PropertyPathInterface::class, \is_object($propertyPath) ? 'instance of '.$propertyPath::class : \gettype($propertyPath) @@ -180,12 +180,12 @@ private function getObjectAndValueFromListElement( $object = $listElement; } elseif (\is_array($listElement)) { if (!isset($listElement[0]) || !\is_object($listElement[0])) { - throw new \TypeError(sprintf('If argument 1 passed to %s() is an array it must contain an object at offset 0.', __METHOD__)); + throw new \TypeError(\sprintf('If argument 1 passed to %s() is an array it must contain an object at offset 0.', __METHOD__)); } $object = $listElement[0]; } else { - throw new \TypeError(sprintf('Argument 1 passed to %s() must be an object or an array, %s given.', __METHOD__, \gettype($listElement))); + throw new \TypeError(\sprintf('Argument 1 passed to %s() must be an object or an array, %s given.', __METHOD__, \gettype($listElement))); } if (\is_array($listElement) && \array_key_exists($fieldDescription->getName(), $listElement)) { @@ -220,7 +220,7 @@ private function render( EOT; - return sprintf( + return \sprintf( $commentTemplate, $fieldDescription->getFieldName(), $fieldDescription->getTemplate() ?? '', diff --git a/src/Util/AdminAclManipulator.php b/src/Util/AdminAclManipulator.php index 178cf51f1c..e0e8bb5c23 100644 --- a/src/Util/AdminAclManipulator.php +++ b/src/Util/AdminAclManipulator.php @@ -38,7 +38,7 @@ public function configureAcls(OutputInterface $output, AdminInterface $admin): v { $securityHandler = $admin->getSecurityHandler(); if (!$securityHandler instanceof AclSecurityHandlerInterface) { - $output->writeln(sprintf('Admin `%s` is not configured to use ACL : ignoring', $admin->getCode())); + $output->writeln(\sprintf('Admin `%s` is not configured to use ACL : ignoring', $admin->getCode())); return; } @@ -51,13 +51,13 @@ public function configureAcls(OutputInterface $output, AdminInterface $admin): v } // create admin ACL - $output->writeln(sprintf(' > install ACL for %s', $admin->getCode())); + $output->writeln(\sprintf(' > install ACL for %s', $admin->getCode())); $configResult = $this->addAdminClassAces($output, $acl, $securityHandler, $admin); if ($configResult) { $securityHandler->updateAcl($acl); } else { - $output->writeln(sprintf(' - %s , no roles and permissions found', $newAcl ? 'skip' : 'removed')); + $output->writeln(\sprintf(' - %s , no roles and permissions found', $newAcl ? 'skip' : 'removed')); $securityHandler->deleteAcl($objectIdentity); } } @@ -92,13 +92,13 @@ public function addAdminClassAces( $action = 'update'; } - $output->writeln(sprintf(' - %s role: %s, permissions: %s', $action, $role, json_encode($roleAdminPermissions, \JSON_THROW_ON_ERROR))); + $output->writeln(\sprintf(' - %s role: %s, permissions: %s', $action, $role, json_encode($roleAdminPermissions, \JSON_THROW_ON_ERROR))); $builder->reset(); } elseif (false !== $aceIndex) { $acl->deleteClassAce($aceIndex); - $output->writeln(sprintf(' - remove role: %s', $role)); + $output->writeln(\sprintf(' - remove role: %s', $role)); } } diff --git a/src/Util/AdminObjectAclData.php b/src/Util/AdminObjectAclData.php index 6e7d721576..6df44773cd 100644 --- a/src/Util/AdminObjectAclData.php +++ b/src/Util/AdminObjectAclData.php @@ -221,7 +221,7 @@ private function updateMasks(): void $reflectionClass = new \ReflectionClass(new $this->maskBuilderClass()); $this->masks = []; foreach ($permissions as $permission) { - $this->masks[$permission] = $reflectionClass->getConstant(sprintf('MASK_%s', $permission)); + $this->masks[$permission] = $reflectionClass->getConstant(\sprintf('MASK_%s', $permission)); } } } diff --git a/src/Util/FormBuilderIterator.php b/src/Util/FormBuilderIterator.php index f6881afd49..2e1bc9b21e 100644 --- a/src/Util/FormBuilderIterator.php +++ b/src/Util/FormBuilderIterator.php @@ -52,7 +52,7 @@ public function key(): string { $name = $this->iterator->current(); - return sprintf('%s_%s', $this->prefix, $name); + return \sprintf('%s_%s', $this->prefix, $name); } public function next(): void diff --git a/src/Util/ObjectAclManipulator.php b/src/Util/ObjectAclManipulator.php index 3cbb7d4449..442c9a9e83 100644 --- a/src/Util/ObjectAclManipulator.php +++ b/src/Util/ObjectAclManipulator.php @@ -47,7 +47,7 @@ final public function configureAcls( $countUpdated = 0; $securityHandler = $admin->getSecurityHandler(); if (!$securityHandler instanceof AclSecurityHandlerInterface) { - $output->writeln(sprintf('Admin `%s` is not configured to use ACL : ignoring', $admin->getCode())); + $output->writeln(\sprintf('Admin `%s` is not configured to use ACL : ignoring', $admin->getCode())); return [0, 0]; } @@ -73,7 +73,7 @@ final public function configureAcls( try { $securityHandler->updateAcl($acl); } catch (\Exception $e) { - $output->writeln(sprintf('Error saving ObjectIdentity (%s, %s) ACL : %s ignoring', $oid->getIdentifier(), $oid->getType(), $e->getMessage())); + $output->writeln(\sprintf('Error saving ObjectIdentity (%s, %s) ACL : %s ignoring', $oid->getIdentifier(), $oid->getType(), $e->getMessage())); } } diff --git a/src/Util/TraversableToCollection.php b/src/Util/TraversableToCollection.php index 434a794042..fce2e01f17 100644 --- a/src/Util/TraversableToCollection.php +++ b/src/Util/TraversableToCollection.php @@ -50,7 +50,7 @@ public static function transform($value): Collection return new ArrayCollection($value); } - throw new \TypeError(sprintf( + throw new \TypeError(\sprintf( 'Argument 1 passed to "%s()" must be an iterable, "%s" given.', __METHOD__, \gettype($value) diff --git a/tests/Admin/AdminHelperTest.php b/tests/Admin/AdminHelperTest.php index 5268a4587f..c765f8f6f4 100644 --- a/tests/Admin/AdminHelperTest.php +++ b/tests/Admin/AdminHelperTest.php @@ -120,7 +120,7 @@ public function testItThrowsExceptionWhenDoesNotFindTheFullPath(): void $subObject->expects(static::atLeastOnce())->method('getMore')->willReturn('Value'); $this->expectException(\Exception::class); - $this->expectExceptionMessage(sprintf('Could not get element id from %s Failing part: calls', $path)); + $this->expectExceptionMessage(\sprintf('Could not get element id from %s Failing part: calls', $path)); $this->getMethodAsPublic('getElementAccessPath')->invoke( $this->helper, @@ -183,7 +183,7 @@ public function testAppendFormFieldElement(): void ->method('getRequest') ->willReturn($request); - $foo = new class() { + $foo = new class { /** @var object[] */ public array $bar = []; }; @@ -326,7 +326,7 @@ public function testAppendFormFieldElementWithoutFormFieldDescriptionInAdminAndN $admin->method('getFormBuilder')->willReturn($formBuilder); $this->expectException(\TypeError::class); - $this->expectExceptionMessage(sprintf('Collection must be an instance of %s or array, "%s" given.', \ArrayAccess::class, \gettype(null))); + $this->expectExceptionMessage(\sprintf('Collection must be an instance of %s or array, "%s" given.', \ArrayAccess::class, \gettype(null))); $this->helper->appendFormFieldElement($admin, $foo, 'test_bar'); } @@ -386,7 +386,7 @@ public function testAppendFormFieldElementWithCollection(): void ->method('getRequest') ->willReturn($request); - $foo = new class() { + $foo = new class { /** @var Collection */ private Collection $bar; @@ -497,7 +497,7 @@ public function testAppendFormFieldElementWithArray(): void ->method('getRequest') ->willReturn($request); - $foo = new class() { + $foo = new class { /** @var Collection */ private Collection $bar; @@ -606,14 +606,14 @@ public function testAppendFormFieldElementNested(): void $admin->expects(static::once())->method('getFormBuilder')->willReturn($formBuilder); $this->expectException(\TypeError::class); - $this->expectExceptionMessage(sprintf('Collection must be an instance of %s or array, "string" given.', \ArrayAccess::class)); + $this->expectExceptionMessage(\sprintf('Collection must be an instance of %s or array, "string" given.', \ArrayAccess::class)); $this->helper->appendFormFieldElement($admin, $object, 'uniquePartOfId_sub_object_0_and_more_0_final_data'); } public function testAppendFormFieldElementOnNestedWithSameNamedCollection(): void { - $subObject = new class() { + $subObject = new class { /** @var Collection */ private Collection $collection; diff --git a/tests/Admin/AdminTest.php b/tests/Admin/AdminTest.php index df1a68c10a..199c2dd39c 100644 --- a/tests/Admin/AdminTest.php +++ b/tests/Admin/AdminTest.php @@ -91,7 +91,7 @@ final class AdminTest extends TestCase protected function setUp(): void { - $this->cacheTempFolder = sprintf('%s/sonata_test_route', sys_get_temp_dir()); + $this->cacheTempFolder = \sprintf('%s/sonata_test_route', sys_get_temp_dir()); $filesystem = new Filesystem(); $filesystem->remove($this->cacheTempFolder); } @@ -436,7 +436,7 @@ public function testGetBaseRoutePatternWithChildAdmin(string $objFqn, string $ex $commentAdmin->setModelClass(Comment::class); $commentAdmin->setParent($postAdmin, 'post'); - static::assertSame(sprintf('%s/{id}/comment', $expected), $commentAdmin->getBaseRoutePattern()); + static::assertSame(\sprintf('%s/{id}/comment', $expected), $commentAdmin->getBaseRoutePattern()); } /** @@ -458,7 +458,7 @@ public function testGetBaseRoutePatternWithTwoNestedChildAdmin(string $objFqn, s $commentAdmin->setParent($postAdmin, 'post'); $commentVoteAdmin->setParent($commentAdmin, 'comment'); - static::assertSame(sprintf('%s/{id}/comment/{childId}/commentvote', $expected), $commentVoteAdmin->getBaseRoutePattern()); + static::assertSame(\sprintf('%s/{id}/comment/{childId}/commentvote', $expected), $commentVoteAdmin->getBaseRoutePattern()); } public function testGetBaseRoutePatternWithSpecifiedPattern(): void @@ -744,7 +744,7 @@ public function testSubClass(): void $request->query->set('subclass', 'inject'); $this->expectException(\LogicException::class); - $this->expectExceptionMessage(sprintf('Admin "%s" has no active subclass.', PostAdmin::class)); + $this->expectExceptionMessage(\sprintf('Admin "%s" has no active subclass.', PostAdmin::class)); $admin->getActiveSubclassCode(); } @@ -811,7 +811,7 @@ public function testGetLabelTranslatorStrategyWithException(): void $admin = new PostAdmin(); $this->expectException(\LogicException::class); - $this->expectExceptionMessage(sprintf( + $this->expectExceptionMessage(\sprintf( 'Admin "%s" has no label translator strategy.', PostAdmin::class )); @@ -934,7 +934,7 @@ public function testGetModelManagerWithException(): void $admin = new PostAdmin(); $this->expectException(\LogicException::class); - $this->expectExceptionMessage(sprintf( + $this->expectExceptionMessage(\sprintf( 'Admin "%s" has no model manager.', PostAdmin::class )); @@ -975,7 +975,7 @@ public function testGetRouteGeneratorWithException(): void $admin = new PostAdmin(); $this->expectException(\LogicException::class); - $this->expectExceptionMessage(sprintf('Admin "%s" has no route generator.', PostAdmin::class)); + $this->expectExceptionMessage(\sprintf('Admin "%s" has no route generator.', PostAdmin::class)); $admin->getRouteGenerator(); } @@ -995,7 +995,7 @@ public function testGetConfigurationPoolWithException(): void $admin = new PostAdmin(); $this->expectException(\LogicException::class); - $this->expectExceptionMessage(sprintf('Admin "%s" has no pool.', PostAdmin::class)); + $this->expectExceptionMessage(\sprintf('Admin "%s" has no pool.', PostAdmin::class)); $admin->getConfigurationPool(); } @@ -1579,7 +1579,7 @@ public function testGetFilterFieldDescription(): void 'foo' => $fooFieldDescription, 'bar' => $barFieldDescription, 'baz' => $bazFieldDescription, - default => throw new \RuntimeException(sprintf('Unknown filter name "%s"', $name)), + default => throw new \RuntimeException(\sprintf('Unknown filter name "%s"', $name)), }; $fieldDescription->setName($name); @@ -1672,7 +1672,7 @@ public function provideGetSubject(): iterable yield ['azerty']; yield ['4f69bbb5f14a13347f000092']; yield ['0779ca8d-e2be-11e4-ac58-0242ac11000b']; - yield [sprintf('123%smy_type', AdapterInterface::ID_SEPARATOR)]; + yield [\sprintf('123%smy_type', AdapterInterface::ID_SEPARATOR)]; } /** @@ -1738,7 +1738,7 @@ public function testSetSubjectNotAllowed(): void $admin->setModelClass(Post::class); $this->expectException(\LogicException::class); - $this->expectExceptionMessage(sprintf( + $this->expectExceptionMessage(\sprintf( 'Admin "%s" does not allow this subject: %s, use the one register with this admin class %s', PostAdmin::class, Comment::class, @@ -1887,7 +1887,7 @@ public function testGetBatchActions(): void $labelTranslatorStrategy = $this->createMock(LabelTranslatorStrategyInterface::class); $labelTranslatorStrategy ->method('getLabel') - ->willReturnCallback(static fn (string $label, string $context = '', string $type = ''): string => sprintf('%s.%s_%s', $context, $type, $label)); + ->willReturnCallback(static fn (string $label, string $context = '', string $type = ''): string => \sprintf('%s.%s_%s', $context, $type, $label)); $admin = new PostAdmin(); $admin->setRouteBuilder($pathInfo); @@ -2293,7 +2293,7 @@ public function testGetDataSourceIterator(): void $formFactory = new FormFactory(new FormRegistry([], new ResolvedFormTypeFactory())); $datagridBuilder = new DatagridBuilder($formFactory, $pager, $proxyQuery); - $translator->method('trans')->willReturnCallback(static fn (string $label): string => sprintf('trans(%s)', $label)); + $translator->method('trans')->willReturnCallback(static fn (string $label): string => \sprintf('trans(%s)', $label)); $modelManager->expects(static::once())->method('getExportFields')->willReturn([ 'key' => 'field', diff --git a/tests/Admin/PoolTest.php b/tests/Admin/PoolTest.php index bb7ff6e158..143c6e7aab 100644 --- a/tests/Admin/PoolTest.php +++ b/tests/Admin/PoolTest.php @@ -276,7 +276,7 @@ public function testGetAdminByAdminCodeWithInvalidChildCode(string $adminId): vo $pool = new Pool($this->container, ['admin1']); $this->expectException(AdminCodeNotFoundException::class); - $this->expectExceptionMessageMatches(sprintf( + $this->expectExceptionMessageMatches(\sprintf( '{^Argument 1 passed to Sonata\\\AdminBundle\\\Admin\\\Pool::getAdminByAdminCode\(\) must contain a valid admin reference, "[^"]+" found at "%s"\.$}', $adminId )); diff --git a/tests/App/AppKernel.php b/tests/App/AppKernel.php index 037d35a185..89d0b313bd 100644 --- a/tests/App/AppKernel.php +++ b/tests/App/AppKernel.php @@ -51,12 +51,12 @@ public function registerBundles(): iterable public function getCacheDir(): string { - return sprintf('%scache', $this->getBaseDir()); + return \sprintf('%scache', $this->getBaseDir()); } public function getLogDir(): string { - return sprintf('%slog', $this->getBaseDir()); + return \sprintf('%slog', $this->getBaseDir()); } public function getProjectDir(): string @@ -66,7 +66,7 @@ public function getProjectDir(): string protected function configureRoutes(RoutingConfigurator $routes): void { - $routes->import(sprintf('%s/config/routes.yml', $this->getProjectDir())); + $routes->import(\sprintf('%s/config/routes.yml', $this->getProjectDir())); } protected function configureContainer(ContainerBuilder $containerBuilder, LoaderInterface $loader): void @@ -100,13 +100,13 @@ protected function configureContainer(ContainerBuilder $containerBuilder, Loader $containerBuilder->loadFromExtension('security', $securityConfig); $containerBuilder->loadFromExtension('twig', [ - 'default_path' => sprintf('%s/templates', $this->getProjectDir()), + 'default_path' => \sprintf('%s/templates', $this->getProjectDir()), 'strict_variables' => true, 'exception_controller' => null, 'form_themes' => ['@SonataAdmin/Form/form_admin_fields.html.twig'], ]); - $loader->load(sprintf('%s/config/services.yml', $this->getProjectDir())); + $loader->load(\sprintf('%s/config/services.yml', $this->getProjectDir())); /* * TODO: Remove when support for SonataBlockBundle 4 is dropped. @@ -116,6 +116,6 @@ protected function configureContainer(ContainerBuilder $containerBuilder, Loader private function getBaseDir(): string { - return sprintf('%s/sonata-admin-bundle/var/', sys_get_temp_dir()); + return \sprintf('%s/sonata-admin-bundle/var/', sys_get_temp_dir()); } } diff --git a/tests/App/EventListener/ConfigureMenu.php b/tests/App/EventListener/ConfigureMenu.php index 864d88fa3e..46d3adf941 100644 --- a/tests/App/EventListener/ConfigureMenu.php +++ b/tests/App/EventListener/ConfigureMenu.php @@ -29,6 +29,6 @@ public static function getSubscribedEvents(): array public function configureMenu(ConfigureMenuEvent $configureMenuEvent): void { - $configureMenuEvent->getMenu()->addChild(sprintf('Dynamic Menu %s', ++$this->counter))->setAttribute('class', 'dynamic-menu'); + $configureMenuEvent->getMenu()->addChild(\sprintf('Dynamic Menu %s', ++$this->counter))->setAttribute('class', 'dynamic-menu'); } } diff --git a/tests/Command/ExplainAdminCommandTest.php b/tests/Command/ExplainAdminCommandTest.php index 4d1c5a37f6..7dc7194827 100644 --- a/tests/Command/ExplainAdminCommandTest.php +++ b/tests/Command/ExplainAdminCommandTest.php @@ -169,10 +169,10 @@ public function testExecute(): void $commandTester = new CommandTester($command); $commandTester->execute(['command' => $command->getName(), 'admin' => 'acme.admin.foo']); - $explainAdminText = file_get_contents(sprintf('%s/../Fixtures/Command/explain_admin.txt', __DIR__)); + $explainAdminText = file_get_contents(\sprintf('%s/../Fixtures/Command/explain_admin.txt', __DIR__)); static::assertNotFalse($explainAdminText); - static::assertSame(sprintf( + static::assertSame(\sprintf( str_replace("\n", \PHP_EOL, $explainAdminText), $this->admin::class, $modelManager::class, diff --git a/tests/Controller/CRUDControllerTest.php b/tests/Controller/CRUDControllerTest.php index 96e33e2603..63e383e8c2 100644 --- a/tests/Controller/CRUDControllerTest.php +++ b/tests/Controller/CRUDControllerTest.php @@ -194,11 +194,11 @@ protected function setUp(): void $this->csrfProvider ->method('getToken') - ->willReturnCallback(static fn (string $intention): CsrfToken => new CsrfToken($intention, sprintf('csrf-token-123_%s', $intention))); + ->willReturnCallback(static fn (string $intention): CsrfToken => new CsrfToken($intention, \sprintf('csrf-token-123_%s', $intention))); $this->csrfProvider ->method('isTokenValid') - ->willReturnCallback(static fn (CsrfToken $token): bool => $token->getValue() === sprintf('csrf-token-123_%s', $token->getId())); + ->willReturnCallback(static fn (CsrfToken $token): bool => $token->getValue() === \sprintf('csrf-token-123_%s', $token->getId())); $this->logger = $this->createMock(LoggerInterface::class); @@ -275,7 +275,7 @@ static function (string $name, array $parameters = []): string { ->method('generateObjectUrl') ->willReturnCallback( static function (string $name, object $object, array $parameters = []): string { - $result = sprintf('%s_%s', $object::class, $name); + $result = \sprintf('%s_%s', $object::class, $name); if ([] !== $parameters) { $result .= '?'.http_build_query($parameters); } @@ -3528,7 +3528,7 @@ public function testAclActionSuccessfulUpdate(): void static::assertInstanceOf(RedirectResponse::class, $response); static::assertSame(['flash_acl_edit_success'], $this->session->getFlashBag()->get('sonata_flash_success')); - static::assertSame(sprintf('%s_acl', DummyDomainObject::class), $response->getTargetUrl()); + static::assertSame(\sprintf('%s_acl', DummyDomainObject::class), $response->getTargetUrl()); } public function testHistoryViewRevisionActionAccessDenied(): void diff --git a/tests/Datagrid/DatagridMapperTest.php b/tests/Datagrid/DatagridMapperTest.php index b4f40de686..637e805b46 100644 --- a/tests/Datagrid/DatagridMapperTest.php +++ b/tests/Datagrid/DatagridMapperTest.php @@ -101,7 +101,7 @@ protected function setUp(): void $labelTranslatorStrategy = $this->createStub(LabelTranslatorStrategyInterface::class); $labelTranslatorStrategy->method('getLabel')->willReturnCallback( - static fn (string $label, string $context = '', string $type = ''): string => sprintf('%s.%s_%s', $context, $type, $label) + static fn (string $label, string $context = '', string $type = ''): string => \sprintf('%s.%s_%s', $context, $type, $label) ); $this->admin diff --git a/tests/Datagrid/ListMapperTest.php b/tests/Datagrid/ListMapperTest.php index ebbf8839d9..7acc6fd85e 100644 --- a/tests/Datagrid/ListMapperTest.php +++ b/tests/Datagrid/ListMapperTest.php @@ -199,13 +199,13 @@ public function testAddDuplicateNameException(): void public function testAutoAddVirtualOption(): void { foreach (['actions', 'batch', 'select'] as $type) { - $this->listMapper->add(sprintf('_%s', $type), $type); + $this->listMapper->add(\sprintf('_%s', $type), $type); } foreach ($this->fieldDescriptionCollection->getElements() as $field) { static::assertTrue( $field->getOption('virtual_field', false), - sprintf('Failed asserting that FieldDescription with name "%s" is tagged with virtual flag.', $field->getName()) + \sprintf('Failed asserting that FieldDescription with name "%s" is tagged with virtual flag.', $field->getName()) ); } } diff --git a/tests/DependencyInjection/Compiler/ExtensionCompilerPassTest.php b/tests/DependencyInjection/Compiler/ExtensionCompilerPassTest.php index c00bc9c769..ab66a2db40 100644 --- a/tests/DependencyInjection/Compiler/ExtensionCompilerPassTest.php +++ b/tests/DependencyInjection/Compiler/ExtensionCompilerPassTest.php @@ -70,8 +70,8 @@ public function testAdminExtensionLoad(): void { $this->extension->load([], $container = $this->getContainer()); - static::assertTrue($container->hasParameter(sprintf('%s.extension.map', $this->root))); - static::assertIsArray($extensionMap = $container->getParameter(sprintf('%s.extension.map', $this->root))); + static::assertTrue($container->hasParameter(\sprintf('%s.extension.map', $this->root))); + static::assertIsArray($extensionMap = $container->getParameter(\sprintf('%s.extension.map', $this->root))); static::assertSame([], $extensionMap); } @@ -82,7 +82,7 @@ public function testAdminExtensionLoad(): void public function testFlattenEmptyExtensionConfiguration(): void { $this->extension->load([], $container = $this->getContainer()); - $extensionMap = $container->getParameter(sprintf('%s.extension.map', $this->root)); + $extensionMap = $container->getParameter(\sprintf('%s.extension.map', $this->root)); $method = new \ReflectionMethod( ExtensionCompilerPass::class, @@ -116,7 +116,7 @@ public function testFlattenExtensionConfiguration(): void { $config = $this->getConfig(); $this->extension->load([$config], $container = $this->getContainer()); - $extensionMap = $container->getParameter(sprintf('%s.extension.map', $this->root)); + $extensionMap = $container->getParameter(\sprintf('%s.extension.map', $this->root)); $method = new \ReflectionMethod( ExtensionCompilerPass::class, diff --git a/tests/DependencyInjection/Compiler/ModelManagerCompilerPassTest.php b/tests/DependencyInjection/Compiler/ModelManagerCompilerPassTest.php index 3dd4127336..bb7d1d1eb9 100644 --- a/tests/DependencyInjection/Compiler/ModelManagerCompilerPassTest.php +++ b/tests/DependencyInjection/Compiler/ModelManagerCompilerPassTest.php @@ -91,7 +91,7 @@ public function testProcessWithInvalidTaggedManagerDefinition(): void $compilerPass = new ModelManagerCompilerPass(); $this->expectException(LogicException::class); - $this->expectExceptionMessage(sprintf('Service "sonata.admin.manager.test" must implement `%s`.', ModelManagerInterface::class)); + $this->expectExceptionMessage(\sprintf('Service "sonata.admin.manager.test" must implement `%s`.', ModelManagerInterface::class)); $compilerPass->process($containerBuilder); } diff --git a/tests/DependencyInjection/SonataAdminExtensionTest.php b/tests/DependencyInjection/SonataAdminExtensionTest.php index 04c31b94f6..5e393f4a3a 100644 --- a/tests/DependencyInjection/SonataAdminExtensionTest.php +++ b/tests/DependencyInjection/SonataAdminExtensionTest.php @@ -398,7 +398,7 @@ private function getDefaultStylesheets(?string $skin = 'skin-black'): array $skin = $options['skin']; $defaultStylesheets = $this->defaultConfiguration['assets']['stylesheets']; - $defaultStylesheets[] = sprintf( + $defaultStylesheets[] = \sprintf( 'bundles/sonataadmin/admin-lte-skins/%s.min.css', $skin ); diff --git a/tests/Filter/FilterTest.php b/tests/Filter/FilterTest.php index f00cc83c48..8810957641 100644 --- a/tests/Filter/FilterTest.php +++ b/tests/Filter/FilterTest.php @@ -107,7 +107,7 @@ public function testExceptionOnNonDefinedFilterName(): void $filter = new FooFilter(); $this->expectException(\LogicException::class); - $this->expectExceptionMessage(sprintf( + $this->expectExceptionMessage(\sprintf( 'Seems like you didn\'t call `initialize()` on the filter `%s`. Did you create it through `%s::create()`?', FooFilter::class, FilterFactory::class diff --git a/tests/Filter/Model/FilterDataTest.php b/tests/Filter/Model/FilterDataTest.php index 762f0ad041..c6b1af3ba8 100644 --- a/tests/Filter/Model/FilterDataTest.php +++ b/tests/Filter/Model/FilterDataTest.php @@ -24,7 +24,7 @@ final class FilterDataTest extends TestCase public function testTypeMustBeNumericOrNull(mixed $type): void { $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage(sprintf( + $this->expectExceptionMessage(\sprintf( 'The "type" parameter MUST be of type "integer" or "null", "%s" given.', \gettype($type) )); diff --git a/tests/Fixtures/Controller/PreCRUDController.php b/tests/Fixtures/Controller/PreCRUDController.php index f39123129e..44d14d6a45 100644 --- a/tests/Fixtures/Controller/PreCRUDController.php +++ b/tests/Fixtures/Controller/PreCRUDController.php @@ -31,22 +31,22 @@ final class PreCRUDController extends CRUDController { protected function preCreate(Request $request, object $object): Response { - return new Response(sprintf('preCreate called: %s', $object->getId())); + return new Response(\sprintf('preCreate called: %s', $object->getId())); } protected function preEdit(Request $request, object $object): Response { - return new Response(sprintf('preEdit called: %s', $object->getId())); + return new Response(\sprintf('preEdit called: %s', $object->getId())); } protected function preDelete(Request $request, object $object): Response { - return new Response(sprintf('preDelete called: %s', $object->getId())); + return new Response(\sprintf('preDelete called: %s', $object->getId())); } protected function preShow(Request $request, object $object): Response { - return new Response(sprintf('preShow called: %s', $object->getId())); + return new Response(\sprintf('preShow called: %s', $object->getId())); } protected function preList(Request $request): Response diff --git a/tests/Fixtures/Entity/FooArrayAccess.php b/tests/Fixtures/Entity/FooArrayAccess.php index d1c8554030..cfdf1cbb03 100644 --- a/tests/Fixtures/Entity/FooArrayAccess.php +++ b/tests/Fixtures/Entity/FooArrayAccess.php @@ -46,12 +46,12 @@ public function offsetGet($offset): ?string public function offsetSet($offset, $value): void { - throw new \BadMethodCallException(sprintf('Array access of class %s is read-only!', self::class)); + throw new \BadMethodCallException(\sprintf('Array access of class %s is read-only!', self::class)); } public function offsetUnset($offset): void { - throw new \BadMethodCallException(sprintf('Array access of class %s is read-only!', self::class)); + throw new \BadMethodCallException(\sprintf('Array access of class %s is read-only!', self::class)); } public function getBar(): ?string diff --git a/tests/Fixtures/FieldDescription/FieldDescription.php b/tests/Fixtures/FieldDescription/FieldDescription.php index 4201afb419..b739e45af8 100644 --- a/tests/Fixtures/FieldDescription/FieldDescription.php +++ b/tests/Fixtures/FieldDescription/FieldDescription.php @@ -19,22 +19,22 @@ final class FieldDescription extends BaseFieldDescription { public function getTargetEntity(): ?string { - throw new \BadMethodCallException(sprintf('Implement %s() method.', __METHOD__)); + throw new \BadMethodCallException(\sprintf('Implement %s() method.', __METHOD__)); } public function getTargetModel(): ?string { - throw new \BadMethodCallException(sprintf('Implement %s() method.', __METHOD__)); + throw new \BadMethodCallException(\sprintf('Implement %s() method.', __METHOD__)); } public function isIdentifier(): bool { - throw new \BadMethodCallException(sprintf('Implement %s() method.', __METHOD__)); + throw new \BadMethodCallException(\sprintf('Implement %s() method.', __METHOD__)); } public function getValue(object $object): void { - throw new \BadMethodCallException(sprintf('Implement %s() method.', __METHOD__)); + throw new \BadMethodCallException(\sprintf('Implement %s() method.', __METHOD__)); } public function describesSingleValuedAssociation(): bool diff --git a/tests/Fixtures/StubTranslator.php b/tests/Fixtures/StubTranslator.php index 1336057f63..8cf1122769 100644 --- a/tests/Fixtures/StubTranslator.php +++ b/tests/Fixtures/StubTranslator.php @@ -28,7 +28,7 @@ public function trans($id, array $parameters = [], $domain = null, $locale = nul $transOpeningTag = '[trans]'; if (null !== $domain) { - $transOpeningTag = sprintf('[trans domain=%s]', $domain); + $transOpeningTag = \sprintf('[trans domain=%s]', $domain); } return $transOpeningTag.strtr($id, $parameters).'[/trans]'; diff --git a/tests/Fixtures/TestExtension.php b/tests/Fixtures/TestExtension.php index cbf014c891..d856d40951 100644 --- a/tests/Fixtures/TestExtension.php +++ b/tests/Fixtures/TestExtension.php @@ -44,7 +44,7 @@ public function addType(FormTypeInterface $type): void public function getType($name): FormTypeInterface { if (!isset($this->types[$name])) { - throw new InvalidArgumentException(sprintf('Type "%s" is not supported.', $name)); + throw new InvalidArgumentException(\sprintf('Type "%s" is not supported.', $name)); } return $this->types[$name]; diff --git a/tests/Form/AbstractLayoutTestCase.php b/tests/Form/AbstractLayoutTestCase.php index 714d458a2c..7b8401b78d 100644 --- a/tests/Form/AbstractLayoutTestCase.php +++ b/tests/Form/AbstractLayoutTestCase.php @@ -82,7 +82,7 @@ final protected function assertMatchesXpath(string $html, string $expression, in // the top level $dom->loadXML(''.$html.''); } catch (\Exception $e) { - static::fail(sprintf( + static::fail(\sprintf( "Failed loading HTML:\n\n%s\n\nError: %s", $html, $e->getMessage() @@ -96,7 +96,7 @@ final protected function assertMatchesXpath(string $html, string $expression, in $dom->formatOutput = true; $savedHtml = $dom->saveHTML(); - static::fail(sprintf( + static::fail(\sprintf( "Failed asserting that \n\n%s\n\nmatches exactly %s. Matches %s in \n\n%s", $expression, 1 === $count ? 'once' : $count.' times', diff --git a/tests/Form/DataTransformer/ModelToIdPropertyTransformerTest.php b/tests/Form/DataTransformer/ModelToIdPropertyTransformerTest.php index 3ae9323cd0..ba608a429a 100644 --- a/tests/Form/DataTransformer/ModelToIdPropertyTransformerTest.php +++ b/tests/Form/DataTransformer/ModelToIdPropertyTransformerTest.php @@ -154,7 +154,7 @@ public function testReverseTransformMultipleInvalidTypeTests(mixed $params, stri $transformer = new ModelToIdPropertyTransformer($this->modelManager, Foo::class, 'bar', true); $this->expectException(UnexpectedTypeException::class); - $this->expectExceptionMessage(sprintf('Expected argument of type "array", "%s" given', $type)); + $this->expectExceptionMessage(\sprintf('Expected argument of type "array", "%s" given', $type)); $transformer->reverseTransform($params); } diff --git a/tests/Form/Type/AdminTypeTest.php b/tests/Form/Type/AdminTypeTest.php index 48a8f40253..868f73fce1 100644 --- a/tests/Form/Type/AdminTypeTest.php +++ b/tests/Form/Type/AdminTypeTest.php @@ -188,7 +188,7 @@ public function testArrayCollection(): void public function testArrayCollectionNotFound(): void { - $parentSubject = new class() { + $parentSubject = new class { /** @var mixed[] */ public $foo = []; }; @@ -204,7 +204,7 @@ public function testArrayCollectionNotFound(): void $modelManager = $this->createStub(ModelManagerInterface::class); - $newInstance = new class() { + $newInstance = new class { private ?object $bar = null; public function setBar(object $bar): void @@ -250,7 +250,7 @@ public function getBar(): ?object public function testArrayCollectionByReferenceNotFound(): void { - $parentSubject = new class() { + $parentSubject = new class { /** @var mixed[] */ public $foo = []; @@ -270,7 +270,7 @@ public function addFoo(): void $modelManager = $this->createStub(ModelManagerInterface::class); - $newInstance = new class() { + $newInstance = new class { private ?object $bar = null; public function setBar(object $bar): void diff --git a/tests/Form/Widget/BaseWidgetTest.php b/tests/Form/Widget/BaseWidgetTest.php index 5b2133d575..e07e29fc0f 100644 --- a/tests/Form/Widget/BaseWidgetTest.php +++ b/tests/Form/Widget/BaseWidgetTest.php @@ -75,7 +75,7 @@ protected function getRenderingEngine(Environment $environment): TwigRendererEng } return new TwigRendererEngine( - [sprintf('%s_admin_fields.html.twig', $this->type)], + [\sprintf('%s_admin_fields.html.twig', $this->type)], $environment ); } @@ -91,8 +91,8 @@ protected function getSonataAdmin(): array protected function getTemplatePaths(): array { $twigPaths = array_filter([ - sprintf('%s/../../../vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form', __DIR__), - sprintf('%s/../../../src/Resources/views/Form', __DIR__), + \sprintf('%s/../../../vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form', __DIR__), + \sprintf('%s/../../../src/Resources/views/Form', __DIR__), ], 'is_dir'); return array_merge(parent::getTemplatePaths(), $twigPaths); diff --git a/tests/Functional/Controller/MenuTest.php b/tests/Functional/Controller/MenuTest.php index 4fbdb3a8de..59e91065ea 100644 --- a/tests/Functional/Controller/MenuTest.php +++ b/tests/Functional/Controller/MenuTest.php @@ -34,7 +34,7 @@ public function testDynamicMenuInLongRunningProcess(): void $menu = $crawler->filter('.sidebar-menu .dynamic-menu a'); static::assertCount(1, $menu); - static::assertSame(sprintf('Dynamic Menu %s', $i), trim($menu->text())); + static::assertSame(\sprintf('Dynamic Menu %s', $i), trim($menu->text())); } } } diff --git a/tests/Maker/AdminMakerTest.php b/tests/Maker/AdminMakerTest.php index 06007c4181..deba3193ae 100644 --- a/tests/Maker/AdminMakerTest.php +++ b/tests/Maker/AdminMakerTest.php @@ -60,8 +60,8 @@ protected function setUp(): void ->willReturn(['bar', 'baz']); $this->modelManagers = ['sonata.admin.manager.orm' => $managerOrmProxy]; - $this->servicesFile = sprintf('%s.yml', lcg_value()); - $this->projectDirectory = sprintf('%s/sonata-admin-bundle/', sys_get_temp_dir()); + $this->servicesFile = \sprintf('%s.yml', lcg_value()); + $this->projectDirectory = \sprintf('%s/sonata-admin-bundle/', sys_get_temp_dir()); $this->filesystem = new Filesystem(); } @@ -100,7 +100,7 @@ public function testExecute(): void $autoloaderUtil = $this->createMock(AutoloaderUtil::class); $autoloaderUtil ->method('getPathForFutureClass') - ->willReturnCallback(fn (string $className): string => sprintf('%s/%s.php', $this->projectDirectory, str_replace('\\', '/', $className))); + ->willReturnCallback(fn (string $className): string => \sprintf('%s/%s.php', $this->projectDirectory, str_replace('\\', '/', $className))); $fileManager = new FileManager( $this->filesystem, diff --git a/tests/Manipulator/ObjectManipulatorTest.php b/tests/Manipulator/ObjectManipulatorTest.php index b09c4718cd..543758d35d 100644 --- a/tests/Manipulator/ObjectManipulatorTest.php +++ b/tests/Manipulator/ObjectManipulatorTest.php @@ -27,7 +27,7 @@ public function testAddInstance(): void $instance = new \stdClass(); - $object = new class() { + $object = new class { /** @var object[] */ private array $fooBars = []; @@ -62,7 +62,7 @@ public function testAddInstanceWithParentAssociation(): void $instance = new \stdClass(); - $object2 = new class() { + $object2 = new class { /** @var object[] */ private array $fooBars = []; @@ -84,7 +84,7 @@ public function getFooBars(): array } }; - $object1 = new class() { + $object1 = new class { private ?object $parent = null; public function setParent(object $parent): void @@ -112,7 +112,7 @@ public function testAddInstanceInflector(): void $instance = new \stdClass(); - $object = new class() { + $object = new class { /** @var object[] */ private array $entries = []; @@ -147,7 +147,7 @@ public function testSetObject(): void $object = new \stdClass(); - $instance = new class() { + $instance = new class { private ?object $parent = null; public function setParent(object $parent): void @@ -190,7 +190,7 @@ public function testSetObjectWithParentAssociation(): void $object2 = new \stdClass(); - $instance = new class() { + $instance = new class { private ?object $fooBar = null; public function setFooBar(object $foobar): void @@ -204,7 +204,7 @@ public function getFooBar(): ?object } }; - $object1 = new class() { + $object1 = new class { private ?object $parent = null; public function setParent(object $parent): void @@ -231,7 +231,7 @@ public function testSetObjectProperty(): void $fieldDescription->expects(static::once())->method('getParentAssociationMappings')->willReturn([]); $object = new \stdClass(); - $instance = new class() { + $instance = new class { /** @var object|null */ public $parent; }; @@ -248,7 +248,7 @@ public function testSetObjectPropertyWithParentAssociation(): void $fieldDescription->expects(static::once())->method('getParentAssociationMappings')->willReturn([['fieldName' => 'parent']]); $object2 = new \stdClass(); - $instance = new class() { + $instance = new class { /** @var object|null */ public $fooBar; }; diff --git a/tests/Manipulator/ServicesManipulatorTest.php b/tests/Manipulator/ServicesManipulatorTest.php index f3526548fb..b7bdad2b8e 100644 --- a/tests/Manipulator/ServicesManipulatorTest.php +++ b/tests/Manipulator/ServicesManipulatorTest.php @@ -28,7 +28,7 @@ final class ServicesManipulatorTest extends TestCase protected function setUp(): void { - $this->file = sprintf('%s/%s.yml', sys_get_temp_dir(), lcg_value()); + $this->file = \sprintf('%s/%s.yml', sys_get_temp_dir(), lcg_value()); $this->servicesManipulator = new ServicesManipulator($this->file); } diff --git a/tests/Mapper/BaseGroupedMapperTest.php b/tests/Mapper/BaseGroupedMapperTest.php index 8835662c00..0098ba6176 100644 --- a/tests/Mapper/BaseGroupedMapperTest.php +++ b/tests/Mapper/BaseGroupedMapperTest.php @@ -48,7 +48,7 @@ protected function setUp(): void $labelStrategy = $this->createMock(LabelTranslatorStrategyInterface::class); $labelStrategy ->method('getLabel') - ->willReturnCallback(static fn (string $label): string => sprintf('label_%s', strtolower($label))); + ->willReturnCallback(static fn (string $label): string => \sprintf('label_%s', strtolower($label))); $admin->setLabelTranslatorStrategy($labelStrategy); diff --git a/tests/Menu/Integration/BaseMenuTest.php b/tests/Menu/Integration/BaseMenuTest.php index 5db2fdc219..cb2701068f 100644 --- a/tests/Menu/Integration/BaseMenuTest.php +++ b/tests/Menu/Integration/BaseMenuTest.php @@ -36,9 +36,9 @@ protected function setUp(): void { // Adapt to both bundle and project-wide test strategy $twigPaths = array_filter([ - sprintf('%s/../../../../../../vendor/knplabs/knp-menu/src/Knp/Menu/Resources/views', __DIR__), - sprintf('%s/../../../vendor/knplabs/knp-menu/src/Knp/Menu/Resources/views', __DIR__), - sprintf('%s/../../../src/Resources/views', __DIR__), + \sprintf('%s/../../../../../../vendor/knplabs/knp-menu/src/Knp/Menu/Resources/views', __DIR__), + \sprintf('%s/../../../vendor/knplabs/knp-menu/src/Knp/Menu/Resources/views', __DIR__), + \sprintf('%s/../../../src/Resources/views', __DIR__), ], 'is_dir'); $loader = new FilesystemLoader($twigPaths); @@ -73,7 +73,7 @@ protected function renderMenu(ItemInterface $item, array $options = []): string */ protected function cleanHtmlWhitespace(string $html): string { - $html = preg_replace_callback('/>([^<]+) sprintf('>%s<', trim($value[1])), $html); + $html = preg_replace_callback('/>([^<]+) \sprintf('>%s<', trim($value[1])), $html); return $html ?? ''; } diff --git a/tests/Menu/Matcher/Voter/AdminVoterTest.php b/tests/Menu/Matcher/Voter/AdminVoterTest.php index 9f4ee5e177..306e96038f 100644 --- a/tests/Menu/Matcher/Voter/AdminVoterTest.php +++ b/tests/Menu/Matcher/Voter/AdminVoterTest.php @@ -117,7 +117,7 @@ private function getChildAdmin( $childAdmin = $this->createMock(AdminInterface::class); $childAdmin ->method('getBaseCodeRoute') - ->willReturn(sprintf('%s|%s', $parentCode, $childCode)); + ->willReturn(\sprintf('%s|%s', $parentCode, $childCode)); $parentAdmin ->method('getChildren') @@ -152,7 +152,7 @@ private function getNestedChildAdmin( $parentAdmin = $this->createMock(AdminInterface::class); $parentAdmin ->method('getBaseCodeRoute') - ->willReturn(sprintf('%s|%s', $grandParentCode, $parentCode)); + ->willReturn(\sprintf('%s|%s', $grandParentCode, $parentCode)); $grandParentAdmin ->method('getChildren') @@ -161,7 +161,7 @@ private function getNestedChildAdmin( $childAdmin = $this->createMock(AdminInterface::class); $childAdmin ->method('getBaseCodeRoute') - ->willReturn(sprintf('%s|%s|%s', $grandParentCode, $parentCode, $childCode)); + ->willReturn(\sprintf('%s|%s|%s', $grandParentCode, $parentCode, $childCode)); $parentAdmin ->method('getChildren') diff --git a/tests/Menu/Provider/GroupMenuProviderTest.php b/tests/Menu/Provider/GroupMenuProviderTest.php index c6fd9b208c..38938be6b1 100644 --- a/tests/Menu/Provider/GroupMenuProviderTest.php +++ b/tests/Menu/Provider/GroupMenuProviderTest.php @@ -58,9 +58,9 @@ protected function setUp(): void array $parameters = [], int $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH ): string => match ($referenceType) { - UrlGeneratorInterface::ABSOLUTE_URL => sprintf('http://sonata-project/%s%s', $name, [] !== $parameters ? '?'.http_build_query($parameters) : ''), - UrlGeneratorInterface::ABSOLUTE_PATH => sprintf('/%s%s', $name, [] !== $parameters ? '?'.http_build_query($parameters) : ''), - default => throw new \InvalidArgumentException(sprintf( + UrlGeneratorInterface::ABSOLUTE_URL => \sprintf('http://sonata-project/%s%s', $name, [] !== $parameters ? '?'.http_build_query($parameters) : ''), + UrlGeneratorInterface::ABSOLUTE_PATH => \sprintf('/%s%s', $name, [] !== $parameters ? '?'.http_build_query($parameters) : ''), + default => throw new \InvalidArgumentException(\sprintf( 'Dummy router does not support the reference type "%s".', $referenceType )), @@ -688,7 +688,7 @@ private function getAdminMock(bool $hasRoute = true, bool $isGranted = true): Ad ->method('generateMenuUrl') ->willReturnCallback(static function (string $name, array $parameters = [], int $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH): array { if (!\in_array($referenceType, [UrlGeneratorInterface::ABSOLUTE_URL, UrlGeneratorInterface::ABSOLUTE_PATH], true)) { - throw new \InvalidArgumentException(sprintf( + throw new \InvalidArgumentException(\sprintf( 'Dummy router does not support the reference type "%s".', $referenceType )); diff --git a/tests/Model/AuditManagerTest.php b/tests/Model/AuditManagerTest.php index 371b9fc2d0..07cc456534 100644 --- a/tests/Model/AuditManagerTest.php +++ b/tests/Model/AuditManagerTest.php @@ -49,7 +49,7 @@ public function testGetReader(): void public function testGetReaderWithException(): void { $this->expectException(\LogicException::class); - $this->expectExceptionMessage(sprintf('The class "%s" does not have any reader manager', Foo1::class)); + $this->expectExceptionMessage(\sprintf('The class "%s" does not have any reader manager', Foo1::class)); $auditManager = new AuditManager(new Container()); diff --git a/tests/Route/DefaultRouteGeneratorTest.php b/tests/Route/DefaultRouteGeneratorTest.php index baf2151ffd..8bbdeca3c2 100644 --- a/tests/Route/DefaultRouteGeneratorTest.php +++ b/tests/Route/DefaultRouteGeneratorTest.php @@ -32,7 +32,7 @@ final class DefaultRouteGeneratorTest extends TestCase protected function setUp(): void { - $this->cacheTempFolder = sprintf('%s/sonata_test_route', sys_get_temp_dir()); + $this->cacheTempFolder = \sprintf('%s/sonata_test_route', sys_get_temp_dir()); $filesystem = new Filesystem(); $filesystem->remove($this->cacheTempFolder); @@ -90,8 +90,8 @@ public function testGenerateUrl( } return match ($name) { - 'admin_acme_foo' => sprintf('%s/foo%s', $domain, $params), - 'admin_acme_child_bar' => sprintf('%s/foo/bar%s', $domain, $params), + 'admin_acme_foo' => \sprintf('%s/foo%s', $domain, $params), + 'admin_acme_child_bar' => \sprintf('%s/foo/bar%s', $domain, $params), default => throw new \LogicException('Not implemented'), }; }); @@ -112,7 +112,7 @@ public function provideGenerateUrlCases(): iterable yield ['/foo/bar?abc=a123&efg=e456&default_param=default_val', 'base.Code.Bar.bar', ['default_param' => 'default_val']]; yield ['/foo/bar?abc=a123&efg=e456&default_param=default_val', 'base.Code.Bar.bar', ['default_param' => 'default_val'], RouterInterface::ABSOLUTE_PATH]; yield [ - sprintf('%s/foo/bar?abc=a123&efg=e456&default_param=default_val', self::ROUTER_DOMAIN), + \sprintf('%s/foo/bar?abc=a123&efg=e456&default_param=default_val', self::ROUTER_DOMAIN), 'base.Code.Bar.bar', ['default_param' => 'default_val'], RouterInterface::ABSOLUTE_URL, @@ -208,9 +208,9 @@ public function testGenerateUrlChild(string $type, string $expected, string $nam } return match ($name) { - 'admin_acme_foo' => sprintf('/foo%s', $params), - 'admin_acme_child_bar' => sprintf('/foo/bar%s', $params), - 'admin_child_bar' => sprintf('/bar%s', $params), + 'admin_acme_foo' => \sprintf('/foo%s', $params), + 'admin_acme_child_bar' => \sprintf('/foo/bar%s', $params), + 'admin_child_bar' => \sprintf('/bar%s', $params), default => throw new \LogicException('Not implemented'), }; }); @@ -271,8 +271,8 @@ public function testGenerateUrlParentFieldDescription(string $expected, string $ } return match ($name) { - 'admin_acme_foo' => sprintf('/foo%s', $params), - 'admin_acme_child_bar' => sprintf('/foo/bar%s', $params), + 'admin_acme_foo' => \sprintf('/foo%s', $params), + 'admin_acme_child_bar' => \sprintf('/foo/bar%s', $params), default => throw new \LogicException('Not implemented'), }; }); @@ -380,8 +380,8 @@ public function testGenerateUrlLoadCache(string $expected, string $name, array $ } return match ($name) { - 'admin_acme_child_bar' => sprintf('/foo/bar%s', $params), - 'admin_acme_child_standalone_bar' => sprintf('/bar%s', $params), + 'admin_acme_child_bar' => \sprintf('/foo/bar%s', $params), + 'admin_acme_child_standalone_bar' => \sprintf('/bar%s', $params), default => throw new \LogicException('Not implemented'), }; }); diff --git a/tests/Route/RouteCollectionTest.php b/tests/Route/RouteCollectionTest.php index 9b1d546757..2b93787fff 100644 --- a/tests/Route/RouteCollectionTest.php +++ b/tests/Route/RouteCollectionTest.php @@ -171,7 +171,7 @@ public function testRouteWithAllConstructorParameters(): void $route = $routeCollection->get($name); - $combinedPattern = sprintf('/%s/%s', $baseRoutePattern, $pattern); + $combinedPattern = \sprintf('/%s/%s', $baseRoutePattern, $pattern); static::assertSame($combinedPattern, $route->getPath()); static::assertArrayHasKey('_controller', $route->getDefaults()); diff --git a/tests/Security/Acl/Permission/MaskBuilderTest.php b/tests/Security/Acl/Permission/MaskBuilderTest.php index 6275e18dd1..21a0ce6240 100644 --- a/tests/Security/Acl/Permission/MaskBuilderTest.php +++ b/tests/Security/Acl/Permission/MaskBuilderTest.php @@ -24,18 +24,18 @@ public function testGetPattern(): void static::assertSame(MaskBuilder::ALL_OFF, $builder->getPattern()); $builder->add('view'); - static::assertSame(sprintf('%sV', str_repeat('.', 31)), $builder->getPattern()); + static::assertSame(\sprintf('%sV', str_repeat('.', 31)), $builder->getPattern()); $builder->add('owner'); - static::assertSame(sprintf('%sN......V', str_repeat('.', 24)), $builder->getPattern()); + static::assertSame(\sprintf('%sN......V', str_repeat('.', 24)), $builder->getPattern()); $builder->add('list'); - static::assertSame(sprintf('%sL....N......V', str_repeat('.', 19)), $builder->getPattern()); + static::assertSame(\sprintf('%sL....N......V', str_repeat('.', 19)), $builder->getPattern()); $builder->add('export'); - static::assertSame(sprintf('%sEL....N......V', str_repeat('.', 18)), $builder->getPattern()); + static::assertSame(\sprintf('%sEL....N......V', str_repeat('.', 18)), $builder->getPattern()); $builder->add(1 << 10); - static::assertSame(sprintf('%sEL.%s..N......V', str_repeat('.', 18), MaskBuilder::ON), $builder->getPattern()); + static::assertSame(\sprintf('%sEL.%s..N......V', str_repeat('.', 18), MaskBuilder::ON), $builder->getPattern()); } } diff --git a/tests/Show/ShowMapperTest.php b/tests/Show/ShowMapperTest.php index 93261a97e8..5e3e6f8b58 100644 --- a/tests/Show/ShowMapperTest.php +++ b/tests/Show/ShowMapperTest.php @@ -369,7 +369,7 @@ public function testAddDuplicateFieldNameException(): void $name = 'name'; $this->expectException(\LogicException::class); $this->expectExceptionMessage( - sprintf('Duplicate field %s "name" in show mapper. Names should be unique.', $name) + \sprintf('Duplicate field %s "name" in show mapper. Names should be unique.', $name) ); $this->showMapper->add($name); diff --git a/tests/Twig/Extension/FakeTemplateRegistryExtension.php b/tests/Twig/Extension/FakeTemplateRegistryExtension.php index 62717d53c2..176d7e53ee 100644 --- a/tests/Twig/Extension/FakeTemplateRegistryExtension.php +++ b/tests/Twig/Extension/FakeTemplateRegistryExtension.php @@ -35,7 +35,7 @@ public function getAdminTemplate(string $name, string $adminCode): string return $templates[$name]; } - throw new \Exception(sprintf( + throw new \Exception(\sprintf( 'Template "%s" of Admin "%s" not found in FakeTemplateRegistry', $name, $adminCode diff --git a/tests/Twig/Extension/RenderElementExtensionTest.php b/tests/Twig/Extension/RenderElementExtensionTest.php index 01774dc7b4..ec458f6944 100644 --- a/tests/Twig/Extension/RenderElementExtensionTest.php +++ b/tests/Twig/Extension/RenderElementExtensionTest.php @@ -81,7 +81,7 @@ protected function setUp(): void $translator->addLoader('xlf', new XliffFileLoader()); $translator->addResource( 'xlf', - sprintf('%s/../../../src/Resources/translations/SonataAdminBundle.en.xliff', __DIR__), + \sprintf('%s/../../../src/Resources/translations/SonataAdminBundle.en.xliff', __DIR__), 'en', 'SonataAdminBundle' ); @@ -444,7 +444,7 @@ public function testRenderRelationElementCustomToString(): void return $default; }); - $element = new class() { + $element = new class { public function customToString(): string { return 'fooBar'; @@ -507,7 +507,7 @@ public function testRenderRelationElementWithClosure(): void ->method('getOption') ->willReturnCallback(static function (string $value, mixed $default = null): mixed { if ('associated_property' === $value) { - return static fn (object $element): string => property_exists($element, 'foo') ? sprintf('closure %s', $element->foo) : ''; + return static fn (object $element): string => property_exists($element, 'foo') ? \sprintf('closure %s', $element->foo) : ''; } return $default; @@ -2148,12 +2148,12 @@ private function registerRequiredTwigExtensions(): void private function registerRoutingExtension(): void { $xmlFileLoader = new XmlFileLoader(new FileLocator([ - sprintf('%s/../../../src/Resources/config/routing', __DIR__), + \sprintf('%s/../../../src/Resources/config/routing', __DIR__), ])); $routeCollection = $xmlFileLoader->load('sonata_admin.xml'); $xmlFileLoader = new XmlFileLoader(new FileLocator([ - sprintf('%s/../../Fixtures/Resources/config/routing', __DIR__), + \sprintf('%s/../../Fixtures/Resources/config/routing', __DIR__), ])); $testRouteCollection = $xmlFileLoader->load('routing.xml'); diff --git a/tests/Twig/Extension/SonataAdminExtensionTest.php b/tests/Twig/Extension/SonataAdminExtensionTest.php index 45a3a1b4a7..88e61ea325 100644 --- a/tests/Twig/Extension/SonataAdminExtensionTest.php +++ b/tests/Twig/Extension/SonataAdminExtensionTest.php @@ -85,10 +85,10 @@ protected function setUp(): void $this->environment->addExtension(new FakeTemplateRegistryExtension()); // routing extension - $xmlFileLoader = new XmlFileLoader(new FileLocator([sprintf('%s/../../../src/Resources/config/routing', __DIR__)])); + $xmlFileLoader = new XmlFileLoader(new FileLocator([\sprintf('%s/../../../src/Resources/config/routing', __DIR__)])); $routeCollection = $xmlFileLoader->load('sonata_admin.xml'); - $xmlFileLoader = new XmlFileLoader(new FileLocator([sprintf('%s/../../Fixtures/Resources/config/routing', __DIR__)])); + $xmlFileLoader = new XmlFileLoader(new FileLocator([\sprintf('%s/../../Fixtures/Resources/config/routing', __DIR__)])); $testRouteCollection = $xmlFileLoader->load('routing.xml'); $routeCollection->addCollection($testRouteCollection); diff --git a/tests/Twig/RenderElementRuntimeTest.php b/tests/Twig/RenderElementRuntimeTest.php index 4a53ee43c7..dafaa77b73 100644 --- a/tests/Twig/RenderElementRuntimeTest.php +++ b/tests/Twig/RenderElementRuntimeTest.php @@ -77,7 +77,7 @@ protected function setUp(): void $translator->addLoader('xlf', new XliffFileLoader()); $translator->addResource( 'xlf', - sprintf('%s/../../src/Resources/translations/SonataAdminBundle.en.xliff', __DIR__), + \sprintf('%s/../../src/Resources/translations/SonataAdminBundle.en.xliff', __DIR__), 'en', 'SonataAdminBundle' ); @@ -419,7 +419,7 @@ public function testRenderRelationElementCustomToString(): void return $default; }); - $element = new class() { + $element = new class { public function customToString(): string { return 'fooBar'; @@ -472,7 +472,7 @@ public function testRenderRelationElementWithClosure(): void ->method('getOption') ->willReturnCallback(static function (string $value, mixed $default = null): mixed { if ('associated_property' === $value) { - return static fn (object $element): string => property_exists($element, 'foo') ? sprintf('closure %s', $element->foo) : ''; + return static fn (object $element): string => property_exists($element, 'foo') ? \sprintf('closure %s', $element->foo) : ''; } return $default; @@ -2067,12 +2067,12 @@ private function registerRequiredTwigExtensions(): void private function registerRoutingExtension(): void { $xmlFileLoader = new XmlFileLoader(new FileLocator([ - sprintf('%s/../../src/Resources/config/routing', __DIR__), + \sprintf('%s/../../src/Resources/config/routing', __DIR__), ])); $routeCollection = $xmlFileLoader->load('sonata_admin.xml'); $xmlFileLoader = new XmlFileLoader(new FileLocator([ - sprintf('%s/../Fixtures/Resources/config/routing', __DIR__), + \sprintf('%s/../Fixtures/Resources/config/routing', __DIR__), ])); $testRouteCollection = $xmlFileLoader->load('routing.xml'); diff --git a/tests/Twig/SonataAdminRuntimeTest.php b/tests/Twig/SonataAdminRuntimeTest.php index 8cdffa4fdf..1d31755e10 100644 --- a/tests/Twig/SonataAdminRuntimeTest.php +++ b/tests/Twig/SonataAdminRuntimeTest.php @@ -81,10 +81,10 @@ protected function setUp(): void $this->environment->addExtension(new FakeTemplateRegistryExtension()); // routing extension - $xmlFileLoader = new XmlFileLoader(new FileLocator([sprintf('%s/../../src/Resources/config/routing', __DIR__)])); + $xmlFileLoader = new XmlFileLoader(new FileLocator([\sprintf('%s/../../src/Resources/config/routing', __DIR__)])); $routeCollection = $xmlFileLoader->load('sonata_admin.xml'); - $xmlFileLoader = new XmlFileLoader(new FileLocator([sprintf('%s/../Fixtures/Resources/config/routing', __DIR__)])); + $xmlFileLoader = new XmlFileLoader(new FileLocator([\sprintf('%s/../Fixtures/Resources/config/routing', __DIR__)])); $testRouteCollection = $xmlFileLoader->load('routing.xml'); $routeCollection->addCollection($testRouteCollection); diff --git a/tests/Util/TraversableToCollectionTest.php b/tests/Util/TraversableToCollectionTest.php index 1dd6f1a958..bcfa5788d8 100644 --- a/tests/Util/TraversableToCollectionTest.php +++ b/tests/Util/TraversableToCollectionTest.php @@ -56,7 +56,7 @@ public function provideTransformCases(): iterable public function testFailedTransform(string $invalidType, mixed $value): void { $this->expectException(\TypeError::class); - $this->expectExceptionMessage(sprintf( + $this->expectExceptionMessage(\sprintf( 'Argument 1 passed to "Sonata\AdminBundle\Util\TraversableToCollection::transform()" must be an iterable, %s given.', $invalidType ));