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,31 +1,38 @@
<?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\AMLI\FamilyMembersBundle\Controller;
use Chill\AMLI\FamilyMembersBundle\Entity\FamilyMember;
use Chill\AMLI\FamilyMembersBundle\Form\FamilyMemberType;
use Chill\AMLI\FamilyMembersBundle\Repository\FamilyMemberRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Chill\AMLI\FamilyMembersBundle\Security\Voter\FamilyMemberVoter;
use Chill\PersonBundle\Entity\Person;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
use Chill\AMLI\FamilyMembersBundle\Entity\FamilyMember;
use Chill\AMLI\FamilyMembersBundle\Security\Voter\FamilyMemberVoter;
use Chill\AMLI\FamilyMembersBundle\Form\FamilyMemberType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Translation\TranslatorInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Translation\TranslatorInterface;
class FamilyMemberController extends AbstractController
{
private EntityManagerInterface $em;
protected LoggerInterface $chillMainLogger;
protected TranslatorInterface $translator;
protected LoggerInterface $chillMainLogger;
private EntityManagerInterface $em;
private FamilyMemberRepository $familyMemberRepository;
@@ -43,8 +50,82 @@ class FamilyMemberController extends AbstractController
/**
* @Route(
* "{_locale}/family-members/family-members/by-person/{id}",
* name="chill_family_members_family_members_index"
* "{_locale}/family-members/family-members/{id}/delete",
* name="chill_family_members_family_members_delete"
* )
*/
public function deleteAction(FamilyMember $familyMember, Request $request): Response
{
$this->denyAccessUnlessGranted(FamilyMemberVoter::DELETE, $familyMember, 'You are not '
. 'allowed to delete this family membership');
$form = $this->createDeleteForm();
if ($request->getMethod() === Request::METHOD_DELETE) {
$form->handleRequest($request);
if ($form->isValid()) {
$this->chillMainLogger->notice('A family member has been removed', [
'by_user' => $this->getUser()->getUsername(),
'family_member_id' => $familyMember->getId(),
'name' => $familyMember->getFirstname() . ' ' . $familyMember->getLastname(),
'link' => $familyMember->getLink(),
]);
$this->em->remove($familyMember);
$this->em->flush();
$this->addFlash('success', $this->translator
->trans('The family member has been successfully removed.'));
return $this->redirectToRoute('chill_family_members_family_members_index', [
'id' => $familyMember->getPerson()->getId(),
]);
}
}
return $this->render('ChillAMLIFamilyMembersBundle:FamilyMember:confirm_delete.html.twig', [
'familyMember' => $familyMember,
'delete_form' => $form->createView(),
]);
}
/**
* @Route(
* "{_locale}/family-members/family-members/{id}/edit",
* name="chill_family_members_family_members_edit"
* )
*/
public function editAction(FamilyMember $familyMember, Request $request)
{
$this->denyAccessUnlessGranted(FamilyMemberVoter::UPDATE, $familyMember);
$form = $this->createForm(FamilyMemberType::class, $familyMember);
$form->add('submit', SubmitType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->em->flush();
$this->addFlash('success', $this->translator->trans('Family member updated'));
return $this->redirectToRoute('chill_family_members_family_members_index', [
'id' => $familyMember->getPerson()->getId(),
]);
}
return $this->render('ChillAMLIFamilyMembersBundle:FamilyMember:edit.html.twig', [
'familyMember' => $familyMember,
'form' => $form->createView(),
'person' => $familyMember->getPerson(),
]);
}
/**
* @Route(
* "{_locale}/family-members/family-members/by-person/{id}",
* name="chill_family_members_family_members_index"
* )
*/
public function indexAction(Person $person)
@@ -55,14 +136,14 @@ class FamilyMemberController extends AbstractController
return $this->render('ChillAMLIFamilyMembersBundle:FamilyMember:index.html.twig', [
'person' => $person,
'familyMembers' => $familyMembers
'familyMembers' => $familyMembers,
]);
}
/**
* @Route(
* "{_locale}/family-members/family-members/by-person/{id}/new",
* name="chill_family_members_family_members_new"
* "{_locale}/family-members/family-members/by-person/{id}/new",
* name="chill_family_members_family_members_new"
* )
*/
public function newAction(Person $person, Request $request)
@@ -83,96 +164,20 @@ class FamilyMemberController extends AbstractController
$this->addFlash('success', $this->translator->trans('Family member created'));
return $this->redirectToRoute('chill_family_members_family_members_index', [
'id' => $person->getId()
'id' => $person->getId(),
]);
}
return $this->render('ChillAMLIFamilyMembersBundle:FamilyMember:new.html.twig', [
'form' => $form->createView(),
'person' => $person
'person' => $person,
]);
}
/**
* @Route(
* "{_locale}/family-members/family-members/{id}/edit",
* name="chill_family_members_family_members_edit"
* )
*/
public function editAction(FamilyMember $familyMember, Request $request)
{
$this->denyAccessUnlessGranted(FamilyMemberVoter::UPDATE, $familyMember);
$form = $this->createForm(FamilyMemberType::class, $familyMember);
$form->add('submit', SubmitType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->em->flush();
$this->addFlash('success', $this->translator->trans('Family member updated'));
return $this->redirectToRoute('chill_family_members_family_members_index', [
'id' => $familyMember->getPerson()->getId()
]);
}
return $this->render('ChillAMLIFamilyMembersBundle:FamilyMember:edit.html.twig', [
'familyMember' => $familyMember,
'form' => $form->createView(),
'person' => $familyMember->getPerson()
]);
}
/**
*
* @Route(
* "{_locale}/family-members/family-members/{id}/delete",
* name="chill_family_members_family_members_delete"
* )
*/
public function deleteAction(FamilyMember $familyMember, Request $request): Response
{
$this->denyAccessUnlessGranted(FamilyMemberVoter::DELETE, $familyMember, 'You are not '
. 'allowed to delete this family membership');
$form = $this->createDeleteForm();
if ($request->getMethod() === Request::METHOD_DELETE) {
$form->handleRequest($request);
if ($form->isValid()) {
$this->chillMainLogger->notice("A family member has been removed", [
'by_user' => $this->getUser()->getUsername(),
'family_member_id' => $familyMember->getId(),
'name' => $familyMember->getFirstname()." ".$familyMember->getLastname(),
'link' => $familyMember->getLink()
]);
$this->em->remove($familyMember);
$this->em->flush();
$this->addFlash('success', $this->translator
->trans("The family member has been successfully removed."));
return $this->redirectToRoute('chill_family_members_family_members_index', [
'id' => $familyMember->getPerson()->getId()
]);
}
}
return $this->render('ChillAMLIFamilyMembersBundle:FamilyMember:confirm_delete.html.twig', [
'familyMember' => $familyMember,
'delete_form' => $form->createView()
]);
}
/**
* @Route(
* "{_locale}/family-members/family-members/{id}/view",
* name="chill_family_members_family_members_view"
* "{_locale}/family-members/family-members/{id}/view",
* name="chill_family_members_family_members_view"
* )
*/
public function viewAction(FamilyMember $familyMember)
@@ -180,7 +185,7 @@ class FamilyMemberController extends AbstractController
$this->denyAccessUnlessGranted(FamilyMemberVoter::SHOW, $familyMember);
return $this->render('ChillAMLIFamilyMembersBundle:FamilyMember:view.html.twig', [
'familyMember' => $familyMember
'familyMember' => $familyMember,
]);
}
@@ -193,8 +198,6 @@ class FamilyMemberController extends AbstractController
->createFormBuilder()
->setMethod(Request::METHOD_DELETE)
->add('submit', SubmitType::class, ['label' => 'Delete'])
->getForm()
;
->getForm();
}
}