fix: SA: Fix "Call to sprintf" rule.

SA stands for Static Analysis.
This commit is contained in:
Pol Dellaiera
2021-11-16 11:52:52 +01:00
parent f8aeb08594
commit a3eb23478a
4 changed files with 62 additions and 116 deletions

View File

@@ -33,12 +33,12 @@ class CustomFieldsGroupToIdTransformer implements DataTransformerInterface
if (null === $customFieldsGroup) {
return "";
}
if (!$customFieldsGroup instanceof CustomFieldsGroup) {
throw new TransformationFailedException(sprintf('Transformation failed: '
. 'the expected type of the transforme function is an '
. 'object of type Chill\CustomFieldsBundle\Entity\CustomFieldsGroup, '
. '%s given (value : %s)', gettype($customFieldsGroup),
. '%s given (value : %s)', gettype($customFieldsGroup),
$customFieldsGroup));
}
@@ -57,26 +57,31 @@ class CustomFieldsGroupToIdTransformer implements DataTransformerInterface
if (!$id) {
return null;
}
if ($id instanceof CustomFieldsGroup) {
throw new TransformationFailedException(sprintf(
throw new TransformationFailedException(
sprintf(
'The transformation failed: the expected argument on '
. 'reverseTransform is an object of type int,'
. 'Chill\CustomFieldsBundle\Entity\CustomFieldsGroup, '
. 'given', gettype($id)));
. 'given'
)
);
}
$customFieldsGroup = $this->om
->getRepository('ChillCustomFieldsBundle:customFieldsGroup')->find($id)
->getRepository(CustomFieldsGroup::class)->find($id)
;
if (null === $customFieldsGroup) {
throw new TransformationFailedException(sprintf(
'Le group avec le numéro "%s" ne peut pas être trouvé!',
$id
));
throw new TransformationFailedException(
sprintf(
'Le group avec le numéro "%s" ne peut pas être trouvé!',
$id
)
);
}
return $customFieldsGroup;
}
}
}