fix: SA: Fix "...Access to an undefined property..." rule.

SA stands for Static Analysis.
This commit is contained in:
Pol Dellaiera 2021-11-16 16:37:45 +01:00
parent 6cfcf91757
commit db2010082a
No known key found for this signature in database
GPG Key ID: D476DFE9C67467CA
2 changed files with 18 additions and 32 deletions

View File

@ -195,11 +195,6 @@ parameters:
count: 2
path: src/Bundle/ChillCalendarBundle/DataFixtures/ORM/LoadCalendarRange.php
-
message: "#^Access to an undefined property Chill\\\\CustomFieldsBundle\\\\Form\\\\DataTransformer\\\\JsonCustomFieldToArrayTransformer\\:\\:\\$customField\\.$#"
count: 3
path: src/Bundle/ChillCustomFieldsBundle/Form/DataTransformer/JsonCustomFieldToArrayTransformer.php
-
message: "#^Call to an undefined method Chill\\\\ThirdPartyBundle\\\\Form\\\\Type\\\\PickThirdPartyTypeCategoryType\\:\\:transform\\(\\)\\.$#"
count: 1

View File

@ -1,28 +1,27 @@
<?php
declare(strict_types=1);
namespace Chill\CustomFieldsBundle\Form\DataTransformer;
use Chill\CustomFieldsBundle\Entity\CustomField;
use Symfony\Component\Form\DataTransformerInterface;
use Doctrine\Persistence\ObjectManager;
use Doctrine\Common\Collections\ArrayCollection;
class JsonCustomFieldToArrayTransformer implements DataTransformerInterface {
/**
* @var ObjectManager
*/
private $om;
private ObjectManager $om;
private array $customField;
/**
* @param ObjectManager $om
*/
public function __construct(ObjectManager $om)
{
$this->om = $om;
$customFields = $this->om
->getRepository('ChillCustomFieldsBundle:CustomField')
->getRepository(CustomField::class)
->findAll();
// @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);
@ -36,20 +35,12 @@ class JsonCustomFieldToArrayTransformer implements DataTransformerInterface {
{
echo $customFieldsJSON;
if($customFieldsJSON === null) { // lors de la creation
$customFieldsArray = array();
if($customFieldsJSON === null) {
$customFieldsArray = [];
} else {
$customFieldsArray = json_decode($customFieldsJSON,true);
$customFieldsArray = json_decode($customFieldsJSON, true, 512, JSON_THROW_ON_ERROR);
}
/*
echo "<br> - 4 - <br>";
var_dump($customFieldsArray);
echo "<br> - 5 - <br>";
*/
$customFieldsArrayRet = array();
foreach ($customFieldsArray as $key => $value) {