Skip to content

Commit

Permalink
using sprintf() is preferred over string concatenation
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-gribanov committed May 12, 2020
1 parent 4993aeb commit b3f1666
Show file tree
Hide file tree
Showing 72 changed files with 395 additions and 491 deletions.
6 changes: 2 additions & 4 deletions src/Action/RetrieveAutocompleteItemsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ public function __invoke(Request $request): JsonResponse
foreach ($property as $prop) {
if (!$datagrid->hasFilter($prop)) {
throw new \RuntimeException(sprintf(
'To retrieve autocomplete items,'
.' you should add filter "%s" to "%s" in configureDatagridFilters() method.',
'To retrieve autocomplete items, you should add filter "%s" to "%s" in configureDatagridFilters() method.',
$prop,
\get_class($targetAdmin)
));
Expand All @@ -130,8 +129,7 @@ public function __invoke(Request $request): JsonResponse
} else {
if (!$datagrid->hasFilter($property)) {
throw new \RuntimeException(sprintf(
'To retrieve autocomplete items,'
.' you should add filter "%s" to "%s" in configureDatagridFilters() method.',
'To retrieve autocomplete items, you should add filter "%s" to "%s" in configureDatagridFilters() method.',
$property,
\get_class($targetAdmin)
));
Expand Down
9 changes: 5 additions & 4 deletions src/Action/SetObjectFieldValueAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ public function __construct(Environment $twig, Pool $pool, $validator)
{
// NEXT_MAJOR: Move ValidatorInterface check to method signature
if (!($validator instanceof ValidatorInterface)) {
throw new \InvalidArgumentException(
'Argument 3 is an instance of '.\get_class($validator).', expecting an instance of'
.' \Symfony\Component\Validator\Validator\ValidatorInterface'
);
throw new \InvalidArgumentException(sprintf(
'Argument 3 is an instance of %s, expecting an instance of %s',
\get_class($validator),
ValidatorInterface::class
));
}
$this->pool = $pool;
$this->twig = $twig;
Expand Down
141 changes: 64 additions & 77 deletions src/Admin/AbstractAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1099,8 +1099,7 @@ public function getActiveSubClass()
{
if (!$this->hasActiveSubClass()) {
@trigger_error(sprintf(
'Calling %s() when there is no active subclass is deprecated since sonata-project/admin-bundle 3.52 and will throw an exception in 4.0. '.
'Use %s::hasActiveSubClass() to know if there is an active subclass.',
'Calling %s() when there is no active subclass is deprecated since sonata-project/admin-bundle 3.52 and will throw an exception in 4.0. Use %s::hasActiveSubClass() to know if there is an active subclass.',
__METHOD__,
__CLASS__
), E_USER_DEPRECATED);
Expand All @@ -1120,8 +1119,7 @@ public function getActiveSubclassCode()
{
if (!$this->hasActiveSubClass()) {
@trigger_error(sprintf(
'Calling %s() when there is no active subclass is deprecated since sonata-project/admin-bundle 3.52 and will throw an exception in 4.0. '.
'Use %s::hasActiveSubClass() to know if there is an active subclass.',
'Calling %s() when there is no active subclass is deprecated since sonata-project/admin-bundle 3.52 and will throw an exception in 4.0. Use %s::hasActiveSubClass() to know if there is an active subclass.',
__METHOD__,
__CLASS__
), E_USER_DEPRECATED);
Expand All @@ -1138,8 +1136,7 @@ public function getActiveSubclassCode()

if (!$this->hasSubClass($subClass)) {
@trigger_error(sprintf(
'Calling %s() when there is no active subclass is deprecated since sonata-project/admin-bundle 3.52 and will throw an exception in 4.0. '.
'Use %s::hasActiveSubClass() to know if there is an active subclass.',
'Calling %s() when there is no active subclass is deprecated since sonata-project/admin-bundle 3.52 and will throw an exception in 4.0. Use %s::hasActiveSubClass() to know if there is an active subclass.',
__METHOD__,
__CLASS__
), E_USER_DEPRECATED);
Expand Down Expand Up @@ -1198,15 +1195,15 @@ public function getRoutes()

public function getRouterIdParameter()
{
return '{'.$this->getIdParameter().'}';
return sprintf('{%s}', $this->getIdParameter());
}

public function getIdParameter()
{
$parameter = 'id';

for ($i = 0; $i < $this->getChildDepth(); ++$i) {
$parameter = 'child'.ucfirst($parameter);
$parameter = sprintf('child%s', ucfirst($parameter));
}

return $parameter;
Expand Down Expand Up @@ -1246,7 +1243,7 @@ public function isCurrentRoute($name, $adminCode = null)
return false;
}

return ($admin->getBaseRouteName().'_'.$name) === $route;
return sprintf('%s_%s', $admin->getBaseRouteName(), $name) === $route;
}

public function generateObjectUrl($name, $object, array $parameters = [], $referenceType = RoutingUrlGeneratorInterface::ABSOLUTE_PATH)
Expand Down Expand Up @@ -1348,8 +1345,7 @@ public function defineFormBuilder(FormBuilderInterface $formBuilder)
{
if (!$this->hasSubject()) {
@trigger_error(sprintf(
'Calling %s() when there is no subject is deprecated since sonata-project/admin-bundle 3.65 and will throw an exception in 4.0. '.
'Use %s::setSubject() to set the subject.',
'Calling %s() when there is no subject is deprecated since sonata-project/admin-bundle 3.65 and will throw an exception in 4.0. Use %s::setSubject() to set the subject.',
__METHOD__,
__CLASS__
), E_USER_DEPRECATED);
Expand Down Expand Up @@ -1424,10 +1420,10 @@ public function getList()
public function createQuery($context = 'list')
{
if (\func_num_args() > 0) {
@trigger_error(
'The $context argument of '.__METHOD__.' is deprecated since 3.3, to be removed in 4.0.',
E_USER_DEPRECATED
);
@trigger_error(sprintf(
'The $context argument of %s is deprecated since 3.3, to be removed in 4.0.',
__METHOD__
), E_USER_DEPRECATED);
}

$query = $this->getModelManager()->createQuery($this->getClass());
Expand Down Expand Up @@ -1552,10 +1548,10 @@ public function getLabel()
*/
public function setPersistFilters($persist)
{
@trigger_error(
'The '.__METHOD__.' method is deprecated since version 3.34 and will be removed in 4.0.',
E_USER_DEPRECATED
);
@trigger_error(sprintf(
'The %s method is deprecated since version 3.34 and will be removed in 4.0.',
__METHOD__
), E_USER_DEPRECATED);

$this->persistFilters = $persist;
}
Expand Down Expand Up @@ -1961,8 +1957,7 @@ public function addChild(AdminInterface $child)
$child->addParentAssociationMapping($this->getCode(), $args[1]);
} else {
@trigger_error(
'Calling "addChild" without second argument is deprecated since'
.' sonata-project/admin-bundle 3.35 and will not be allowed in 4.0.',
'Calling "addChild" without second argument is deprecated since sonata-project/admin-bundle 3.35 and will not be allowed in 4.0.',
E_USER_DEPRECATED
);
}
Expand Down Expand Up @@ -2071,7 +2066,7 @@ public function setUniqid($uniqid)
public function getUniqid()
{
if (!$this->uniqid) {
$this->uniqid = 's'.uniqid();
$this->uniqid = sprintf('s%s', uniqid());
}

return $this->uniqid;
Expand Down Expand Up @@ -2118,11 +2113,11 @@ public function getPersistentParameter($name)

public function getBreadcrumbs($action)
{
@trigger_error(
'The '.__METHOD__.' method is deprecated since version 3.2 and will be removed in 4.0.'.
' Use Sonata\AdminBundle\Admin\BreadcrumbsBuilder::getBreadcrumbs instead.',
E_USER_DEPRECATED
);
@trigger_error(sprintf(
'The %s method is deprecated since version 3.2 and will be removed in 4.0. Use %s::getBreadcrumbs instead.',
__METHOD__,
BreadcrumbsBuilder::class
), E_USER_DEPRECATED);

return $this->getBreadcrumbsBuilder()->getBreadcrumbs($this, $action);
}
Expand All @@ -2138,10 +2133,10 @@ public function getBreadcrumbs($action)
*/
public function buildBreadcrumbs($action, ?ItemInterface $menu = null)
{
@trigger_error(
'The '.__METHOD__.' method is deprecated since version 3.2 and will be removed in 4.0.',
E_USER_DEPRECATED
);
@trigger_error(sprintf(
'The %s method is deprecated since version 3.2 and will be removed in 4.0.',
__METHOD__
), E_USER_DEPRECATED);

if (isset($this->breadcrumbs[$action])) {
return $this->breadcrumbs[$action];
Expand All @@ -2158,11 +2153,10 @@ public function buildBreadcrumbs($action, ?ItemInterface $menu = null)
*/
final public function getBreadcrumbsBuilder()
{
@trigger_error(
'The '.__METHOD__.' method is deprecated since version 3.2 and will be removed in 4.0.'.
' Use the sonata.admin.breadcrumbs_builder service instead.',
E_USER_DEPRECATED
);
@trigger_error(sprintf(
'The %s method is deprecated since version 3.2 and will be removed in 4.0. Use the sonata.admin.breadcrumbs_builder service instead.',
__METHOD__
), E_USER_DEPRECATED);
if (null === $this->breadcrumbsBuilder) {
$this->breadcrumbsBuilder = new BreadcrumbsBuilder(
$this->getConfigurationPool()->getContainer()->getParameter('sonata.admin.configuration.breadcrumbs')
Expand All @@ -2179,11 +2173,10 @@ final public function getBreadcrumbsBuilder()
*/
final public function setBreadcrumbsBuilder(BreadcrumbsBuilderInterface $value)
{
@trigger_error(
'The '.__METHOD__.' method is deprecated since version 3.2 and will be removed in 4.0.'.
' Use the sonata.admin.breadcrumbs_builder service instead.',
E_USER_DEPRECATED
);
@trigger_error(sprintf(
'The %s method is deprecated since version 3.2 and will be removed in 4.0. Use the sonata.admin.breadcrumbs_builder service instead.',
__METHOD__
), E_USER_DEPRECATED);
$this->breadcrumbsBuilder = $value;

return $this;
Expand All @@ -2201,14 +2194,11 @@ public function setCurrentChild($currentChild)
*/
public function getCurrentChild()
{
@trigger_error(
sprintf(
'The %s() method is deprecated since version 3.65 and will be removed in 4.0. Use %s::isCurrentChild() instead.',
__METHOD__,
__CLASS__
),
E_USER_DEPRECATED
);
@trigger_error(sprintf(
'The %s() method is deprecated since version 3.65 and will be removed in 4.0. Use %s::isCurrentChild() instead.',
__METHOD__,
__CLASS__
), E_USER_DEPRECATED);

return $this->currentChild;
}
Expand Down Expand Up @@ -2236,10 +2226,10 @@ public function getCurrentChildAdmin()

public function trans($id, array $parameters = [], $domain = null, $locale = null)
{
@trigger_error(
'The '.__METHOD__.' method is deprecated since version 3.9 and will be removed in 4.0.',
E_USER_DEPRECATED
);
@trigger_error(sprintf(
'The %s method is deprecated since version 3.9 and will be removed in 4.0.',
__METHOD__
), E_USER_DEPRECATED);

$domain = $domain ?: $this->getTranslationDomain();

Expand All @@ -2262,10 +2252,10 @@ public function trans($id, array $parameters = [], $domain = null, $locale = nul
*/
public function transChoice($id, $count, array $parameters = [], $domain = null, $locale = null)
{
@trigger_error(
'The '.__METHOD__.' method is deprecated since version 3.9 and will be removed in 4.0.',
E_USER_DEPRECATED
);
@trigger_error(sprintf(
'The %s method is deprecated since version 3.9 and will be removed in 4.0.',
__METHOD__
), E_USER_DEPRECATED);

$domain = $domain ?: $this->getTranslationDomain();

Expand Down Expand Up @@ -2293,10 +2283,10 @@ public function setTranslator(TranslatorInterface $translator)
{
$args = \func_get_args();
if (isset($args[1]) && $args[1]) {
@trigger_error(
'The '.__METHOD__.' method is deprecated since version 3.9 and will be removed in 4.0.',
E_USER_DEPRECATED
);
@trigger_error(sprintf(
'The %s method is deprecated since version 3.9 and will be removed in 4.0.',
__METHOD__
), E_USER_DEPRECATED);
}

$this->translator = $translator;
Expand All @@ -2311,10 +2301,10 @@ public function setTranslator(TranslatorInterface $translator)
*/
public function getTranslator()
{
@trigger_error(
'The '.__METHOD__.' method is deprecated since version 3.9 and will be removed in 4.0.',
E_USER_DEPRECATED
);
@trigger_error(sprintf(
'The %s method is deprecated since version 3.9 and will be removed in 4.0.',
__METHOD__
), E_USER_DEPRECATED);

return $this->translator;
}
Expand Down Expand Up @@ -2434,10 +2424,10 @@ public function getCode()
*/
public function setBaseCodeRoute($baseCodeRoute)
{
@trigger_error(
'The '.__METHOD__.' is deprecated since 3.24 and will be removed in 4.0.',
E_USER_DEPRECATED
);
@trigger_error(sprintf(
'The %s is deprecated since 3.24 and will be removed in 4.0.',
__METHOD__
), E_USER_DEPRECATED);

$this->baseCodeRoute = $baseCodeRoute;
}
Expand All @@ -2446,7 +2436,7 @@ public function getBaseCodeRoute()
{
// NEXT_MAJOR: Uncomment the following lines.
// if ($this->isChild()) {
// return $this->getParent()->getBaseCodeRoute().'|'.$this->getCode();
// return sprintf('%s|%s', $this->getParent()->getBaseCodeRoute(), $this->getCode());
// }
//
// return $this->getCode();
Expand All @@ -2459,7 +2449,7 @@ public function getBaseCodeRoute()
$parentCode = $this->getParent()->getBaseCodeRoute();
}

return $parentCode.'|'.$this->getCode();
return sprintf('%s|%s', $parentCode, $this->getCode());
}

return $this->baseCodeRoute;
Expand Down Expand Up @@ -2550,7 +2540,7 @@ public function getSecurityHandler()

public function isGranted($name, $object = null)
{
$objectRef = $object ? '/'.spl_object_hash($object).'#'.$this->id($object) : '';
$objectRef = $object ? sprintf('/%s#%s', spl_object_hash($object), $this->id($object)) : '';
$key = md5(json_encode($name).$objectRef);

if (!\array_key_exists($key, $this->cacheIsGranted)) {
Expand Down Expand Up @@ -2579,9 +2569,7 @@ public function setValidator($validator)
{
// NEXT_MAJOR: Move ValidatorInterface check to method signature
if (!$validator instanceof ValidatorInterface) {
throw new \InvalidArgumentException(
'Argument 1 must be an instance of Symfony\Component\Validator\Validator\ValidatorInterface'
);
throw new \InvalidArgumentException(sprintf('Argument 1 must be an instance of %s', ValidatorInterface::class));
}

$this->validator = $validator;
Expand Down Expand Up @@ -2771,8 +2759,7 @@ public function checkAccess($action, $object = null)

if (!\array_key_exists($action, $access)) {
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 "%s" could not be found in access mapping. Please make sure your action is defined into your admin class accessMapping property.',
$action
));
}
Expand Down
10 changes: 5 additions & 5 deletions src/Admin/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

namespace Sonata\AdminBundle\Admin;

@trigger_error(
'The '.__NAMESPACE__.'\Admin class is deprecated since version 3.1 and will be removed in 4.0.'
.' Use '.__NAMESPACE__.'\AbstractAdmin instead.',
E_USER_DEPRECATED
);
@trigger_error(sprintf(
'The %s\Admin class is deprecated since version 3.1 and will be removed in 4.0. Use %s\AbstractAdmin instead.',
__NAMESPACE__,
__NAMESPACE__
), E_USER_DEPRECATED);

/**
* NEXT_MAJOR: remove this class.
Expand Down
10 changes: 5 additions & 5 deletions src/Admin/AdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

namespace Sonata\AdminBundle\Admin;

@trigger_error(
'The '.__NAMESPACE__.'\AdminExtension class is deprecated since version 3.1 and will be removed in 4.0.'
.' Use '.__NAMESPACE__.'\AbstractAdminExtension instead.',
E_USER_DEPRECATED
);
@trigger_error(sprintf(
'The %s\AdminExtension class is deprecated since version 3.1 and will be removed in 4.0. Use %s\AbstractAdminExtension instead.',
__NAMESPACE__,
__NAMESPACE__
), E_USER_DEPRECATED);

/**
* NEXT_MAJOR: remove this class.
Expand Down
Loading

0 comments on commit b3f1666

Please sign in to comment.