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,25 @@
<?php
/*
/**
* Chill is a software for social workers
*
* Copyright (C) 2016, Champs Libres Cooperative SCRLFS,
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\PersonBundle\Controller;
use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Form\Type\AddressType;
use Chill\PersonBundle\Entity\Person;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Chill\PersonBundle\Entity\Person;
use Chill\MainBundle\Form\Type\AddressType;
use Chill\MainBundle\Entity\Address;
use Doctrine\Common\Collections\Criteria;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Validator\Validator\ValidatorInterface;
/**
* Class PersonAddressController
* Controller for addresses associated with person
*
* @package Chill\PersonBundle\Controller
* @author Julien Fastré <julien.fastre@champs-libres.coop>
* @author Champs Libres <info@champs-libres.coop>
* Controller for addresses associated with person.
*/
class PersonAddressController extends AbstractController
{
@@ -48,78 +30,27 @@ class PersonAddressController extends AbstractController
/**
* PersonAddressController constructor.
*
* @param ValidatorInterface $validator
*/
public function __construct(ValidatorInterface $validator)
{
$this->validator = $validator;
}
public function listAction($person_id)
{
$person = $this->getDoctrine()->getManager()
->getRepository('ChillPersonBundle:Person')
->find($person_id);
if ($person === null) {
throw $this->createNotFoundException("Person with id $person_id not"
. " found ");
}
$this->denyAccessUnlessGranted(
'CHILL_PERSON_SEE',
$person,
"You are not allowed to edit this person."
);
return $this->render('ChillPersonBundle:Address:list.html.twig', array(
'person' => $person
));
}
public function newAction($person_id)
{
$person = $this->getDoctrine()->getManager()
->getRepository('ChillPersonBundle:Person')
->find($person_id);
if ($person === null) {
throw $this->createNotFoundException("Person with id $person_id not"
. " found ");
}
$this->denyAccessUnlessGranted(
'CHILL_PERSON_UPDATE',
$person,
"You are not allowed to edit this person."
);
$address = new Address();
$form = $this->createCreateForm($person, $address);
return $this->render('ChillPersonBundle:Address:new.html.twig', array(
'person' => $person,
'form' => $form->createView()
));
}
public function createAction($person_id, Request $request)
{
$person = $this->getDoctrine()->getManager()
->getRepository('ChillPersonBundle:Person')
->find($person_id);
->getRepository('ChillPersonBundle:Person')
->find($person_id);
if ($person === null) {
throw $this->createNotFoundException("Person with id $person_id not"
. " found ");
if (null === $person) {
throw $this->createNotFoundException("Person with id {$person_id} not"
. ' found ');
}
$this->denyAccessUnlessGranted(
'CHILL_PERSON_UPDATE',
$person,
"You are not allowed to edit this person."
'You are not allowed to edit this person.'
);
$address = new Address();
@@ -137,7 +68,6 @@ class PersonAddressController extends AbstractController
$this->addFlash('error', $error->getMessage());
}
} elseif ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->flush();
@@ -146,47 +76,96 @@ class PersonAddressController extends AbstractController
$this->get('translator')->trans('The new address was created successfully')
);
return $this->redirectToRoute('chill_person_address_list', array(
'person_id' => $person->getId()
));
return $this->redirectToRoute('chill_person_address_list', [
'person_id' => $person->getId(),
]);
} else {
$this->addFlash('error', $this->get('translator')
->trans('Error! Address not created!'));
->trans('Error! Address not created!'));
}
}
return $this->render('ChillPersonBundle:Address:new.html.twig', array(
return $this->render('ChillPersonBundle:Address:new.html.twig', [
'person' => $person,
'form' => $form->createView()
));
'form' => $form->createView(),
]);
}
public function editAction($person_id, $address_id)
{
$person = $this->getDoctrine()->getManager()
->getRepository('ChillPersonBundle:Person')
->find($person_id);
->getRepository('ChillPersonBundle:Person')
->find($person_id);
if ($person === null) {
throw $this->createNotFoundException("Person with id $person_id not"
. " found ");
if (null === $person) {
throw $this->createNotFoundException("Person with id {$person_id} not"
. ' found ');
}
$this->denyAccessUnlessGranted(
'CHILL_PERSON_UPDATE',
$person,
"You are not allowed to edit this person."
'You are not allowed to edit this person.'
);
$address = $this->findAddressById($person, $address_id);
$form = $this->createEditForm($person, $address);
return $this->render('ChillPersonBundle:Address:edit.html.twig', array(
'person' => $person,
'address' => $address,
'form' => $form->createView()
));
return $this->render('ChillPersonBundle:Address:edit.html.twig', [
'person' => $person,
'address' => $address,
'form' => $form->createView(),
]);
}
public function listAction($person_id)
{
$person = $this->getDoctrine()->getManager()
->getRepository('ChillPersonBundle:Person')
->find($person_id);
if (null === $person) {
throw $this->createNotFoundException("Person with id {$person_id} not"
. ' found ');
}
$this->denyAccessUnlessGranted(
'CHILL_PERSON_SEE',
$person,
'You are not allowed to edit this person.'
);
return $this->render('ChillPersonBundle:Address:list.html.twig', [
'person' => $person,
]);
}
public function newAction($person_id)
{
$person = $this->getDoctrine()->getManager()
->getRepository('ChillPersonBundle:Person')
->find($person_id);
if (null === $person) {
throw $this->createNotFoundException("Person with id {$person_id} not"
. ' found ');
}
$this->denyAccessUnlessGranted(
'CHILL_PERSON_UPDATE',
$person,
'You are not allowed to edit this person.'
);
$address = new Address();
$form = $this->createCreateForm($person, $address);
return $this->render('ChillPersonBundle:Address:new.html.twig', [
'person' => $person,
'form' => $form->createView(),
]);
}
public function updateAction($person_id, $address_id, Request $request)
@@ -195,15 +174,15 @@ class PersonAddressController extends AbstractController
->getRepository('ChillPersonBundle:Person')
->find($person_id);
if ($person === null) {
throw $this->createNotFoundException("Person with id $person_id not"
. " found ");
if (null === $person) {
throw $this->createNotFoundException("Person with id {$person_id} not"
. ' found ');
}
$this->denyAccessUnlessGranted(
'CHILL_PERSON_UPDATE',
$person,
"You are not allowed to edit this person."
'You are not allowed to edit this person.'
);
$address = $this->findAddressById($person, $address_id);
@@ -220,90 +199,84 @@ class PersonAddressController extends AbstractController
}
} elseif ($form->isValid()) {
$this->getDoctrine()->getManager()
->flush();
->flush();
$this->addFlash('success', $this->get('translator')->trans(
"The address has been successfully updated"
'The address has been successfully updated'
));
return $this->redirectToRoute('chill_person_address_list', array(
'person_id' => $person->getId()
));
return $this->redirectToRoute('chill_person_address_list', [
'person_id' => $person->getId(),
]);
} else {
$this->addFlash('error', $this->get('translator')
->trans('Error when updating the period'));
}
}
return $this->render('ChillPersonBundle:Address:edit.html.twig', array(
'person' => $person,
'address' => $address,
'form' => $form->createView()
));
return $this->render('ChillPersonBundle:Address:edit.html.twig', [
'person' => $person,
'address' => $address,
'form' => $form->createView(),
]);
}
/**
* @param Person $person
* @param Address $address
* @return \Symfony\Component\Form\Form
*/
protected function createEditForm(Person $person, Address $address)
{
$form = $this->createForm(AddressType::class, $address, array(
'method' => 'POST',
'action' => $this->generateUrl('chill_person_address_update', array(
'person_id' => $person->getId(),
'address_id' => $address->getId()
)),
'has_no_address' => true
));
$form->add('submit', SubmitType::class, array(
'label' => 'Submit'
));
return $form;
}
/**
*
* @param Person $person
* @param Address $address
* @return \Symfony\Component\Form\Form
*/
protected function createCreateForm(Person $person, Address $address)
{
$form = $this->createForm(AddressType::class, $address, array(
'method' => 'POST',
'action' => $this->generateUrl('chill_person_address_create', array(
'person_id' => $person->getId()
)),
'has_no_address' => true
));
$form = $this->createForm(AddressType::class, $address, [
'method' => 'POST',
'action' => $this->generateUrl('chill_person_address_create', [
'person_id' => $person->getId(),
]),
'has_no_address' => true,
]);
$form->add('submit', SubmitType::class, array(
'label' => 'Submit'
));
$form->add('submit', SubmitType::class, [
'label' => 'Submit',
]);
return $form;
}
/**
* @return \Symfony\Component\Form\Form
*/
protected function createEditForm(Person $person, Address $address)
{
$form = $this->createForm(AddressType::class, $address, [
'method' => 'POST',
'action' => $this->generateUrl('chill_person_address_update', [
'person_id' => $person->getId(),
'address_id' => $address->getId(),
]),
'has_no_address' => true,
]);
$form->add('submit', SubmitType::class, [
'label' => 'Submit',
]);
return $form;
}
/**
*
* @param Person $person
* @param int $address_id
* @return Address
*
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException if the address id does not exists or is not associated with given person
*
* @return Address
*/
protected function findAddressById(Person $person, $address_id)
{
$address = $this->getDoctrine()->getManager()
->getRepository(Address::class)
->find($address_id)
;
->find($address_id);
if (!$person->getAddresses()->contains($address)) {
throw $this->createAccessDeniedException("Not allowed to see this address");
throw $this->createAccessDeniedException('Not allowed to see this address');
}
return $address;
@@ -311,16 +284,17 @@ class PersonAddressController extends AbstractController
/**
* @param Chill\PersonBundle\Entity\Person $person
*
* @return \Symfony\Component\Validator\ConstraintViolationListInterface
*/
private function validatePerson(Person $person)
{
$errors = $this->validator
->validate($person, null, array('Default'));
->validate($person, null, ['Default']);
$errors_addresses_consistent = $this->validator
->validate($person, null, array('addresses_consistent'));
->validate($person, null, ['addresses_consistent']);
foreach($errors_addresses_consistent as $error) {
foreach ($errors_addresses_consistent as $error) {
$errors->add($error);
}