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 Apr 28, 2020
1 parent 965c6b7 commit c81cb1d
Show file tree
Hide file tree
Showing 72 changed files with 399 additions and 506 deletions.
10 changes: 4 additions & 6 deletions src/Action/RetrieveAutocompleteItemsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,9 @@ 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)
get_class($targetAdmin)
));
}

Expand All @@ -130,10 +129,9 @@ 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)
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
147 changes: 65 additions & 82 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 @@ -1554,10 +1550,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 @@ -1912,8 +1908,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 @@ -2006,7 +2001,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 @@ -2053,11 +2048,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 @@ -2073,10 +2068,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 @@ -2093,11 +2088,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 @@ -2114,11 +2108,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 @@ -2136,14 +2129,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 @@ -2171,10 +2161,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 @@ -2197,10 +2187,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 @@ -2228,10 +2218,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 @@ -2246,10 +2236,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 @@ -2368,10 +2358,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 @@ -2380,7 +2370,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 @@ -2393,7 +2383,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 @@ -2484,7 +2474,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 @@ -2513,9 +2503,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 @@ -2705,8 +2693,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 Expand Up @@ -3162,11 +3149,7 @@ protected function getSubClass($name)
return $this->subClasses[$name];
}

throw new \RuntimeException(sprintf(
'Unable to find the subclass `%s` for admin `%s`',
$name,
static::class
));
throw new \RuntimeException(sprintf('Unable to find the subclass `%s` for admin `%s`', $name, static::class));
}

/**
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
Loading

0 comments on commit c81cb1d

Please sign in to comment.