cs: Fix code style (safe rules only).

This commit is contained in:
Pol Dellaiera
2021-11-23 14:06:38 +01:00
parent 149d7ce991
commit 8f96a1121d
1223 changed files with 65199 additions and 64625 deletions

View File

@@ -1,43 +1,49 @@
<?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 Symfony\Component\Form\DataTransformerInterface;
use Chill\CustomFieldsBundle\CustomFields\CustomFieldInterface;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Symfony\Component\Form\DataTransformerInterface;
/**
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class CustomFieldDataTransformer implements DataTransformerInterface
{
private $customFieldDefinition;
/**
*
* @var \Chill\CustomFieldsBundle\Entity\CustomField
*/
private $customField;
public function __construct(CustomFieldInterface $customFieldDefinition,
CustomField $customField)
private $customFieldDefinition;
public function __construct(
CustomFieldInterface $customFieldDefinition,
CustomField $customField
)
{
$this->customFieldDefinition = $customFieldDefinition;
$this->customField = $customField;
}
public function reverseTransform($value)
{
return $this->customFieldDefinition->serialize($value,
$this->customField);
return $this->customFieldDefinition->serialize(
$value,
$this->customField
);
}
public function transform($value)
{
return $this->customFieldDefinition->deserialize($value,
$this->customField);
return $this->customFieldDefinition->deserialize(
$value,
$this->customField
);
}
}

View File

@@ -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();
}
}

View File

@@ -1,18 +1,26 @@
<?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.
*/
declare(strict_types=1);
namespace Chill\CustomFieldsBundle\Form\DataTransformer;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Symfony\Component\Form\DataTransformerInterface;
use Doctrine\Persistence\ObjectManager;
use Symfony\Component\Form\DataTransformerInterface;
class JsonCustomFieldToArrayTransformer implements DataTransformerInterface {
private ObjectManager $om;
class JsonCustomFieldToArrayTransformer implements DataTransformerInterface
{
private array $customField;
private ObjectManager $om;
public function __construct(ObjectManager $om)
{
$this->om = $om;
@@ -23,56 +31,15 @@ class JsonCustomFieldToArrayTransformer implements DataTransformerInterface {
// @TODO: in the array_map callback, CustomField::getLabel() does not exist. What do we do here?
$customFieldsLablels = array_map(
function($e) { return $e->getLabel(); },
$customFields);
function ($e) { return $e->getLabel(); },
$customFields
);
$customFieldsByLabel = array_combine($customFieldsLablels, $customFields);
$this->customField = $customFieldsByLabel;
}
public function transform($customFieldsJSON)
{
echo $customFieldsJSON;
if($customFieldsJSON === null) {
$customFieldsArray = [];
} else {
$customFieldsArray = json_decode($customFieldsJSON, true, 512, JSON_THROW_ON_ERROR);
}
$customFieldsArrayRet = array();
foreach ($customFieldsArray as $key => $value) {
$traited = false;
if(array_key_exists($key, $this->customField)) {
$type = $this->customField[$key]->getType();
if(strpos($type,'ManyToOne') === 0) {
if(strpos($type,'ManyToOnePersist') ===0) {
$entityClass = substr($type, 17, -1);
} else {
$entityClass = substr($type, 10, -1);
}
$customFieldsArrayRet[$key] = $this->om
->getRepository('ChillCustomFieldsBundle:' . $entityClass)
->findOneById($value);
$traited = true;
} else if ($type === 'ManyToMany(Adress)') {
$customFieldsArrayRet[$key] = $value;
}
}
if(! $traited) {
$customFieldsArrayRet[$key] = $value;
}
}
var_dump($customFieldsArrayRet);
return $customFieldsArrayRet;
}
public function reverseTransform($customFieldsArray)
{
/*
@@ -86,23 +53,25 @@ class JsonCustomFieldToArrayTransformer implements DataTransformerInterface {
var_dump(array_keys($this->customField));
echo "<br> - - 9 - <br>";
*/
*/
//var_dump($customFieldsArray);
$customFieldsArrayRet = array();
$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(strpos($type,'ManyToOne') === 0) {
if (strpos($type, 'ManyToOne') === 0) {
// 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;
if(strpos($type, 'ManyToOnePersist') === 0) {
if (strpos($type, 'ManyToOnePersist') === 0) {
// PEUT ETRE A FAIRE SI SEULEMENT $value->getId() ne renvoie rien...
//
//
@@ -123,14 +92,57 @@ class JsonCustomFieldToArrayTransformer implements DataTransformerInterface {
}
}
if(! $traited) {
if (!$traited) {
$customFieldsArrayRet[$key] = $value;
}
}
//echo json_encode($customFieldsArrayRet);
return json_encode($customFieldsArrayRet);
}
public function transform($customFieldsJSON)
{
echo $customFieldsJSON;
if (null === $customFieldsJSON) {
$customFieldsArray = [];
} else {
$customFieldsArray = json_decode($customFieldsJSON, true, 512, JSON_THROW_ON_ERROR);
}
$customFieldsArrayRet = [];
foreach ($customFieldsArray as $key => $value) {
$traited = false;
if (array_key_exists($key, $this->customField)) {
$type = $this->customField[$key]->getType();
if (strpos($type, 'ManyToOne') === 0) {
if (strpos($type, 'ManyToOnePersist') === 0) {
$entityClass = substr($type, 17, -1);
} else {
$entityClass = substr($type, 10, -1);
}
$customFieldsArrayRet[$key] = $this->om
->getRepository('ChillCustomFieldsBundle:' . $entityClass)
->findOneById($value);
$traited = true;
} elseif ('ManyToMany(Adress)' === $type) {
$customFieldsArrayRet[$key] = $value;
}
}
if (!$traited) {
$customFieldsArrayRet[$key] = $value;
}
}
var_dump($customFieldsArrayRet);
return $customFieldsArrayRet;
}
}