mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-04 13:54:59 +00:00
apply more cs rules for php-cs
This commit is contained in:
@@ -16,8 +16,6 @@ use Doctrine\Persistence\ObjectManager;
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
|
||||
use function gettype;
|
||||
|
||||
class CustomFieldsGroupToIdTransformer implements DataTransformerInterface
|
||||
{
|
||||
public function __construct(private readonly ObjectManager $om) {}
|
||||
@@ -25,35 +23,25 @@ class CustomFieldsGroupToIdTransformer implements DataTransformerInterface
|
||||
/**
|
||||
* Transforms a string (id) to an object (CustomFieldsGroup).
|
||||
*
|
||||
* @param string $id
|
||||
* @param string $id
|
||||
*
|
||||
* @throws TransformationFailedException if object (report) is not found.
|
||||
* @throws TransformationFailedException if object (report) is not found
|
||||
*/
|
||||
public function reverseTransform($id): ?\Chill\CustomFieldsBundle\Entity\CustomFieldsGroup
|
||||
public function reverseTransform($id): ?CustomFieldsGroup
|
||||
{
|
||||
if (!$id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($id instanceof CustomFieldsGroup) {
|
||||
throw new TransformationFailedException(
|
||||
'The transformation failed: the expected argument on '
|
||||
. 'reverseTransform is an object of type int,'
|
||||
. 'Chill\CustomFieldsBundle\Entity\CustomFieldsGroup, '
|
||||
. 'given'
|
||||
);
|
||||
throw new TransformationFailedException('The transformation failed: the expected argument on reverseTransform is an object of type int,Chill\CustomFieldsBundle\Entity\CustomFieldsGroup, given');
|
||||
}
|
||||
|
||||
$customFieldsGroup = $this->om
|
||||
->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;
|
||||
@@ -62,7 +50,7 @@ class CustomFieldsGroupToIdTransformer implements DataTransformerInterface
|
||||
/**
|
||||
* Transforms an custom_field_group to a string (id).
|
||||
*
|
||||
* @param CustomFieldsGroup|null $customFieldsGroup
|
||||
* @param CustomFieldsGroup|null $customFieldsGroup
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -73,14 +61,7 @@ class CustomFieldsGroupToIdTransformer implements DataTransformerInterface
|
||||
}
|
||||
|
||||
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),
|
||||
$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), $customFieldsGroup));
|
||||
}
|
||||
|
||||
return $customFieldsGroup->getId();
|
||||
|
@@ -15,10 +15,6 @@ use Chill\CustomFieldsBundle\Entity\CustomField;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
|
||||
use function array_key_exists;
|
||||
|
||||
use const JSON_THROW_ON_ERROR;
|
||||
|
||||
/**
|
||||
* Not in use ? Deprecated ?
|
||||
*/
|
||||
@@ -58,22 +54,22 @@ class JsonCustomFieldToArrayTransformer implements DataTransformerInterface
|
||||
echo "<br> - - 9 - <br>";
|
||||
*/
|
||||
|
||||
//var_dump($customFieldsArray);
|
||||
// var_dump($customFieldsArray);
|
||||
|
||||
$customFieldsArrayRet = [];
|
||||
|
||||
foreach ($customFieldsArray as $key => $value) {
|
||||
$traited = false;
|
||||
|
||||
if (array_key_exists($key, $this->customField)) {
|
||||
if (\array_key_exists($key, $this->customField)) {
|
||||
$type = $this->customField[$key]->getType();
|
||||
|
||||
if (str_starts_with((string) $type, 'ManyToOne')) {
|
||||
// pour le manytoone() faire
|
||||
// un update du form en js ? : http://symfony.com/fr/doc/current/cookbook/form/form_collections.html
|
||||
//
|
||||
//$entityClass = substr($type, 10, -1);
|
||||
//echo $entityClasss;
|
||||
// $entityClass = substr($type, 10, -1);
|
||||
// echo $entityClasss;
|
||||
if (str_starts_with((string) $type, 'ManyToOnePersist')) {
|
||||
// PEUT ETRE A FAIRE SI SEULEMENT $value->getId() ne renvoie rien...
|
||||
//
|
||||
@@ -100,9 +96,9 @@ class JsonCustomFieldToArrayTransformer implements DataTransformerInterface
|
||||
}
|
||||
}
|
||||
|
||||
//echo json_encode($customFieldsArrayRet);
|
||||
// echo json_encode($customFieldsArrayRet);
|
||||
|
||||
return json_encode($customFieldsArrayRet, JSON_THROW_ON_ERROR);
|
||||
return json_encode($customFieldsArrayRet, \JSON_THROW_ON_ERROR);
|
||||
}
|
||||
|
||||
public function transform($customFieldsJSON)
|
||||
@@ -112,7 +108,7 @@ class JsonCustomFieldToArrayTransformer implements DataTransformerInterface
|
||||
if (null === $customFieldsJSON) {
|
||||
$customFieldsArray = [];
|
||||
} else {
|
||||
$customFieldsArray = json_decode((string) $customFieldsJSON, true, 512, JSON_THROW_ON_ERROR);
|
||||
$customFieldsArray = json_decode((string) $customFieldsJSON, true, 512, \JSON_THROW_ON_ERROR);
|
||||
}
|
||||
|
||||
$customFieldsArrayRet = [];
|
||||
@@ -120,7 +116,7 @@ class JsonCustomFieldToArrayTransformer implements DataTransformerInterface
|
||||
foreach ($customFieldsArray as $key => $value) {
|
||||
$traited = false;
|
||||
|
||||
if (array_key_exists($key, $this->customField)) {
|
||||
if (\array_key_exists($key, $this->customField)) {
|
||||
$type = $this->customField[$key]->getType();
|
||||
|
||||
if (str_starts_with((string) $type, 'ManyToOne')) {
|
||||
@@ -131,7 +127,7 @@ class JsonCustomFieldToArrayTransformer implements DataTransformerInterface
|
||||
}
|
||||
|
||||
$customFieldsArrayRet[$key] = $this->om
|
||||
->getRepository('ChillCustomFieldsBundle:' . $entityClass)
|
||||
->getRepository('ChillCustomFieldsBundle:'.$entityClass)
|
||||
->findOneById($value);
|
||||
$traited = true;
|
||||
} elseif ('ManyToMany(Adress)' === $type) {
|
||||
|
Reference in New Issue
Block a user