fix: SA: Fix "...Instantiated class not found..." rules.

SA stands for Static Analysis.
This commit is contained in:
Pol Dellaiera 2021-11-16 15:32:35 +01:00
parent 8879734ea2
commit 68a21fcc0a
No known key found for this signature in database
GPG Key ID: D476DFE9C67467CA
3 changed files with 18 additions and 38 deletions

View File

@ -80,26 +80,11 @@ parameters:
count: 1 count: 1
path: src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php path: src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php
-
message: "#^Instantiated class Chill\\\\PersonBundle\\\\Controller\\\\BadRequestExceptions not found\\.$#"
count: 1
path: src/Bundle/ChillPersonBundle/Controller/HouseholdMemberController.php
- -
message: "#^Variable method call on mixed\\.$#" message: "#^Variable method call on mixed\\.$#"
count: 1 count: 1
path: src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadPeople.php path: src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadPeople.php
-
message: "#^Caught class Chill\\\\PersonBundle\\\\DataFixtures\\\\ORM\\\\Throwable not found\\.$#"
count: 1
path: src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadSocialWorkMetadata.php
-
message: "#^Instantiated class Chill\\\\PersonBundle\\\\DataFixtures\\\\ORM\\\\Exception not found\\.$#"
count: 1
path: src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadSocialWorkMetadata.php
- -
message: "#^Foreach overwrites \\$value with its value variable\\.$#" message: "#^Foreach overwrites \\$value with its value variable\\.$#"
count: 1 count: 1

View File

@ -38,7 +38,7 @@ class HouseholdMemberController extends ApiController
$this->translator = $translator; $this->translator = $translator;
$this->periodRepository = $periodRepository; $this->periodRepository = $periodRepository;
} }
/** /**
* @Route( * @Route(
* "/api/1.0/person/household/members/move.{_format}", * "/api/1.0/person/household/members/move.{_format}",
@ -75,7 +75,7 @@ class HouseholdMemberController extends ApiController
} }
foreach ($editor->getPersistable() as $el) { foreach ($editor->getPersistable() as $el) {
$em->persist($el); $em->persist($el);
} }
$em->flush(); $em->flush();
@ -89,8 +89,8 @@ class HouseholdMemberController extends ApiController
* *
* * persons[]: an id of the person to add to the form * * persons[]: an id of the person to add to the form
* * household: the id of the destination household * * household: the id of the destination household
* * allow_leave_without_household: if present, the editor will allow * * allow_leave_without_household: if present, the editor will allow
* to leave household without joining another * to leave household without joining another
* *
* @Route( * @Route(
* "/{_locale}/person/household/members/editor", * "/{_locale}/person/household/members/editor",
@ -105,7 +105,7 @@ class HouseholdMemberController extends ApiController
$ids = $request->query->get('persons', []); $ids = $request->query->get('persons', []);
if (0 === count($ids)) { if (0 === count($ids)) {
throw new BadRequestExceptions("parameters persons in query ". throw new BadRequestException("parameters persons in query ".
"is not an array or empty"); "is not an array or empty");
} }
@ -114,7 +114,7 @@ class HouseholdMemberController extends ApiController
; ;
foreach ($persons as $person) { foreach ($persons as $person) {
$this->denyAccessUnlessGranted(PersonVoter::SEE, $person, $this->denyAccessUnlessGranted(PersonVoter::SEE, $person,
"You are not allowed to see person with id {$person->getId()}" "You are not allowed to see person with id {$person->getId()}"
); );
} }
@ -140,11 +140,11 @@ class HouseholdMemberController extends ApiController
; ;
$data = [ $data = [
'persons' => $persons ?? false ? 'persons' => $persons ?? false ?
$this->getSerializer()->normalize($persons, 'json', [ 'groups' => [ 'read' ]]) : [], $this->getSerializer()->normalize($persons, 'json', [ 'groups' => [ 'read' ]]) : [],
'household' => $household ?? false ? 'household' => $household ?? false ?
$this->getSerializer()->normalize($household, 'json', [ 'groups' => [ 'read' ]]) : null, $this->getSerializer()->normalize($household, 'json', [ 'groups' => [ 'read' ]]) : null,
'positions' => 'positions' =>
$this->getSerializer()->normalize($positions, 'json', [ 'groups' => [ 'read' ]]), $this->getSerializer()->normalize($positions, 'json', [ 'groups' => [ 'read' ]]),
'allowHouseholdCreate' => $allowHouseholdCreate ?? true, 'allowHouseholdCreate' => $allowHouseholdCreate ?? true,
'allowHouseholdSearch' => $allowHouseholdSearch ?? true, 'allowHouseholdSearch' => $allowHouseholdSearch ?? true,
@ -182,7 +182,7 @@ class HouseholdMemberController extends ApiController
// TODO ACL // TODO ACL
$form = $this->createForm(HouseholdMemberType::class, $member, [ $form = $this->createForm(HouseholdMemberType::class, $member, [
'validation_groups' => [ 'household_memberships' ] 'validation_groups' => [ 'household_memberships' ]
]); ]);
$form->handleRequest($request); $form->handleRequest($request);
@ -190,12 +190,12 @@ class HouseholdMemberController extends ApiController
$this->getDoctrine()->getManager()->flush(); $this->getDoctrine()->getManager()->flush();
$this->addFlash('success', $this->translator $this->addFlash('success', $this->translator
->trans('household.successfully saved member')) ->trans('household.successfully saved member'))
; ;
return $this->redirect( return $this->redirect(
$request->get('returnPath', null) ?? $request->get('returnPath', null) ??
$this->generator->generate('chill_person_household_summary', [ 'household_id' => $this->generator->generate('chill_person_household_summary', [ 'household_id' =>
$member->getHousehold()->getId() ]) $member->getHousehold()->getId() ])
); );
} }

View File

@ -1,32 +1,30 @@
<?php <?php
declare(strict_types=1);
namespace Chill\PersonBundle\DataFixtures\ORM; namespace Chill\PersonBundle\DataFixtures\ORM;
use Chill\PersonBundle\Service\Import\SocialWorkMetadata; use Chill\PersonBundle\Service\Import\SocialWorkMetadata;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Persistence\ObjectManager; use Doctrine\Persistence\ObjectManager;
use League\Csv\Reader; use League\Csv\Reader;
class LoadSocialWorkMetadata extends \Doctrine\Bundle\FixturesBundle\Fixture implements \Doctrine\Common\DataFixtures\OrderedFixtureInterface class LoadSocialWorkMetadata extends Fixture implements OrderedFixtureInterface
{ {
private SocialWorkMetadata $importer; private SocialWorkMetadata $importer;
/**
* @param SocialWorkMetadata $importer
*/
public function __construct(SocialWorkMetadata $importer) public function __construct(SocialWorkMetadata $importer)
{ {
$this->importer = $importer; $this->importer = $importer;
} }
/**
* @inheritDoc
*/
public function load(ObjectManager $manager) public function load(ObjectManager $manager)
{ {
try { try {
$csv = Reader::createFromPath(__DIR__.'/data/social_work_metadata.csv'); $csv = Reader::createFromPath(__DIR__.'/data/social_work_metadata.csv');
} catch (Throwable $e) { } catch (\Throwable $e) {
throw new Exception('Error while loading CSV.',0, $e); throw new \Exception('Error while loading CSV.',0, $e);
} }
$csv->setDelimiter(";"); $csv->setDelimiter(";");
@ -34,9 +32,6 @@ class LoadSocialWorkMetadata extends \Doctrine\Bundle\FixturesBundle\Fixture imp
$this->importer->import($csv); $this->importer->import($csv);
} }
/**
* @inheritDoc
*/
public function getOrder() public function getOrder()
{ {
return 9500; return 9500;