mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-04 05:44:58 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,11 +1,18 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\CustomFieldsBundle\Form\DataTransformer;
|
||||
|
||||
use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Symfony\Component\Form\DataTransformerInterface;
|
||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup;
|
||||
|
||||
class CustomFieldsGroupToIdTransformer implements DataTransformerInterface
|
||||
{
|
||||
@@ -14,43 +21,19 @@ class CustomFieldsGroupToIdTransformer implements DataTransformerInterface
|
||||
*/
|
||||
private $om;
|
||||
|
||||
/**
|
||||
* @param ObjectManager $om
|
||||
*/
|
||||
public function __construct(ObjectManager $om)
|
||||
{
|
||||
$this->om = $om;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms an custom_field_group to a string (id)
|
||||
*
|
||||
* @param CustomFieldsGroup|null $customFieldsGroup
|
||||
* @return string
|
||||
*/
|
||||
public function transform($customFieldsGroup)
|
||||
{
|
||||
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),
|
||||
$customFieldsGroup));
|
||||
}
|
||||
|
||||
return $customFieldsGroup->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a string (id) to an object (CustomFieldsGroup).
|
||||
*
|
||||
* @param string $id
|
||||
* @return CustomFieldsGroup|null
|
||||
*
|
||||
* @throws TransformationFailedException if object (report) is not found.
|
||||
*
|
||||
* @return CustomFieldsGroup|null
|
||||
*/
|
||||
public function reverseTransform($id)
|
||||
{
|
||||
@@ -61,7 +44,7 @@ class CustomFieldsGroupToIdTransformer implements DataTransformerInterface
|
||||
if ($id instanceof CustomFieldsGroup) {
|
||||
throw new TransformationFailedException(
|
||||
sprintf(
|
||||
'The transformation failed: the expected argument on '
|
||||
'The transformation failed: the expected argument on '
|
||||
. 'reverseTransform is an object of type int,'
|
||||
. 'Chill\CustomFieldsBundle\Entity\CustomFieldsGroup, '
|
||||
. 'given'
|
||||
@@ -70,8 +53,7 @@ class CustomFieldsGroupToIdTransformer implements DataTransformerInterface
|
||||
}
|
||||
|
||||
$customFieldsGroup = $this->om
|
||||
->getRepository(CustomFieldsGroup::class)->find($id)
|
||||
;
|
||||
->getRepository(CustomFieldsGroup::class)->find($id);
|
||||
|
||||
if (null === $customFieldsGroup) {
|
||||
throw new TransformationFailedException(
|
||||
@@ -84,4 +66,31 @@ class CustomFieldsGroupToIdTransformer implements DataTransformerInterface
|
||||
|
||||
return $customFieldsGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms an custom_field_group to a string (id).
|
||||
*
|
||||
* @param CustomFieldsGroup|null $customFieldsGroup
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function transform($customFieldsGroup)
|
||||
{
|
||||
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),
|
||||
$customFieldsGroup
|
||||
));
|
||||
}
|
||||
|
||||
return $customFieldsGroup->getId();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user