Fix phpstan issues

This commit is contained in:
2023-12-12 22:34:26 +01:00
parent af663cf27c
commit da997badd9
26 changed files with 275 additions and 261 deletions

View File

@@ -14,6 +14,7 @@ namespace Chill\PersonBundle\Controller;
use Chill\ActivityBundle\Entity\Activity;
use Chill\DocStoreBundle\Entity\PersonDocument;
use Chill\EventBundle\Entity\Participation;
use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\Actions\Remove\PersonMove;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Entity\PersonNotDuplicate;
@@ -24,15 +25,21 @@ use Chill\PersonBundle\Repository\PersonNotDuplicateRepository;
use Chill\PersonBundle\Repository\PersonRepository;
use Chill\PersonBundle\Search\SimilarPersonMatcher;
use Chill\TaskBundle\Entity\SingleTask;
use http\Exception\InvalidArgumentException;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\Security\Core\Security;
use function count;
class PersonDuplicateController extends \Symfony\Bundle\FrameworkBundle\Controller\AbstractController
{
public function __construct(private readonly SimilarPersonMatcher $similarPersonMatcher, private readonly TranslatorInterface $translator, private readonly PersonRepository $personRepository, private readonly PersonMove $personMove, private readonly EventDispatcherInterface $eventDispatcher) {}
public function __construct(
private readonly SimilarPersonMatcher $similarPersonMatcher,
private readonly PersonRepository $personRepository,
private readonly PersonMove $personMove,
private readonly EventDispatcherInterface $eventDispatcher,
private readonly Security $security,
) {}
/**
* @\Symfony\Component\Routing\Annotation\Route(path="/{_locale}/person/{person1_id}/duplicate/{person2_id}/confirm", name="chill_person_duplicate_confirm")
@@ -40,7 +47,7 @@ class PersonDuplicateController extends \Symfony\Bundle\FrameworkBundle\Controll
public function confirmAction(mixed $person1_id, mixed $person2_id, Request $request)
{
if ($person1_id === $person2_id) {
throw new InvalidArgumentException('Can not merge same person');
throw new \InvalidArgumentException('Can not merge same person');
}
$person1 = $this->_getPerson($person1_id);
@@ -152,6 +159,12 @@ class PersonDuplicateController extends \Symfony\Bundle\FrameworkBundle\Controll
*/
public function notDuplicateAction(mixed $person1_id, mixed $person2_id)
{
$user = $this->security->getUser();
if (!$user instanceof User) {
throw new AccessDeniedHttpException();
}
[$person1, $person2] = $this->_getPersonsByPriority($person1_id, $person2_id);
$this->denyAccessUnlessGranted(
@@ -167,7 +180,7 @@ class PersonDuplicateController extends \Symfony\Bundle\FrameworkBundle\Controll
$personNotDuplicate = new PersonNotDuplicate();
$personNotDuplicate->setPerson1($person1);
$personNotDuplicate->setPerson2($person2);
$personNotDuplicate->setUser($this->getUser());
$personNotDuplicate->setUser($user);
$this->getDoctrine()->getManager()->persist($personNotDuplicate);
$this->getDoctrine()->getManager()->flush();
@@ -259,7 +272,7 @@ class PersonDuplicateController extends \Symfony\Bundle\FrameworkBundle\Controll
private function _getPersonsByPriority($person1_id, $person2_id)
{
if ($person1_id === $person2_id) {
throw new InvalidArgumentException('Can not merge same person');
throw new \InvalidArgumentException('Can not merge same person');
}
if ($person1_id > $person2_id) {