diff --git a/phpstan-critical.neon b/phpstan-critical.neon index bfbb2dc7c..158c7384b 100644 --- a/phpstan-critical.neon +++ b/phpstan-critical.neon @@ -1,76 +1,6 @@ parameters: ignoreErrors: - - - message: "#^Implicit array creation is not allowed \\- variable \\$centers might not exist\\.$#" - count: 1 - path: src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php - - - - message: "#^Access to an undefined property Chill\\\\PersonBundle\\\\Entity\\\\AccompanyingPeriod\\:\\:\\$work\\.$#" - count: 1 - path: src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php - - - - message: "#^Undefined variable\\: \\$person$#" - count: 1 - path: src/Bundle/ChillActivityBundle/Repository/ActivityACLAwareRepository.php - - - - message: "#^Variable variables are not allowed\\.$#" - count: 4 - path: src/Bundle/ChillPersonBundle/Search/PersonSearch.php - - - - message: "#^Function Chill\\\\PersonBundle\\\\Serializer\\\\Normalizer\\\\·\\\\is_array not found\\.$#" - count: 1 - path: src/Bundle/ChillPersonBundle/Serializer/Normalizer/MembersEditorNormalizer.php - - - - message: "#^Undefined variable\\: \\$choiceSlug$#" - count: 1 - path: src/Bundle/ChillReportBundle/Export/Export/ReportList.php - - - - message: "#^Undefined variable\\: \\$type$#" - count: 1 - path: src/Bundle/ChillTaskBundle/Controller/TaskController.php - - - - message: "#^Call to an undefined method Chill\\\\MainBundle\\\\CRUD\\\\Controller\\\\AbstractCRUDController\\:\\:getRoleFor\\(\\)\\.$#" - count: 1 - path: src/Bundle/ChillMainBundle/CRUD/Controller/AbstractCRUDController.php - - message: "#^Call to an undefined method Chill\\\\MainBundle\\\\Controller\\\\UserController\\:\\:createEditForm\\(\\)\\.$#" count: 1 path: src/Bundle/ChillMainBundle/Controller/UserController.php - - - - message: "#^Undefined variable\\: \\$current$#" - count: 1 - path: src/Bundle/ChillMainBundle/Pagination/PageGenerator.php - - - - message: "#^Call to an undefined method Chill\\\\MainBundle\\\\Security\\\\Authorization\\\\AbstractChillVoter\\:\\:getSupportedAttributes\\(\\)\\.$#" - count: 1 - path: src/Bundle/ChillMainBundle/Security/Authorization/AbstractChillVoter.php - - - - message: "#^Call to an undefined method Chill\\\\MainBundle\\\\Security\\\\Authorization\\\\AbstractChillVoter\\:\\:getSupportedClasses\\(\\)\\.$#" - count: 1 - path: src/Bundle/ChillMainBundle/Security/Authorization/AbstractChillVoter.php - - - - message: "#^Call to an undefined method Chill\\\\MainBundle\\\\Security\\\\Authorization\\\\AbstractChillVoter\\:\\:isGranted\\(\\)\\.$#" - count: 1 - path: src/Bundle/ChillMainBundle/Security/Authorization/AbstractChillVoter.php - - - - message: "#^Access to an undefined property Chill\\\\PersonBundle\\\\Controller\\\\PersonController\\:\\:\\$security\\.$#" - count: 3 - path: src/Bundle/ChillPersonBundle/Controller/PersonController.php - - - - message: "#^Call to an undefined method Chill\\\\ThirdPartyBundle\\\\Form\\\\Type\\\\PickThirdPartyTypeCategoryType\\:\\:transform\\(\\)\\.$#" - count: 1 - path: src/Bundle/ChillThirdPartyBundle/Form/Type/PickThirdPartyTypeCategoryType.php diff --git a/src/Bundle/ChillActivityBundle/Repository/ActivityACLAwareRepository.php b/src/Bundle/ChillActivityBundle/Repository/ActivityACLAwareRepository.php index fa36c8d07..185e008eb 100644 --- a/src/Bundle/ChillActivityBundle/Repository/ActivityACLAwareRepository.php +++ b/src/Bundle/ChillActivityBundle/Repository/ActivityACLAwareRepository.php @@ -225,10 +225,9 @@ final class ActivityACLAwareRepository implements ActivityACLAwareRepositoryInte $personToCenter = $metadataPerson->getAssociationMapping('center')['joinColumns'][0]['name']; // acls: - $role = new Role(ActivityVoter::SEE); $reachableCenters = $this->authorizationHelper->getReachableCenters( $this->tokenStorage->getToken()->getUser(), - $role + ActivityVoter::SEE ); if (count($reachableCenters) === 0) { @@ -239,7 +238,7 @@ final class ActivityACLAwareRepository implements ActivityACLAwareRepositoryInte if ('person' === $context) { // we start with activities having the person_id linked to person $where .= sprintf('%s = ? AND ', $activityToPerson); - $parameters[] = $person->getId(); + $parameters[] = $args['context']->getId(); } // we add acl (reachable center and scopes) @@ -252,7 +251,7 @@ final class ActivityACLAwareRepository implements ActivityACLAwareRepositoryInte continue; } // we get all the reachable scopes for this center - $reachableScopes = $this->authorizationHelper->getReachableScopes($this->tokenStorage->getToken()->getUser(), $role, $center); + $reachableScopes = $this->authorizationHelper->getReachableScopes($this->tokenStorage->getToken()->getUser(), ActivityVoter::SEE, $center); // we get the ids for those scopes $reachablesScopesId = array_map( static function (Scope $scope) { diff --git a/src/Bundle/ChillMainBundle/CRUD/Controller/AbstractCRUDController.php b/src/Bundle/ChillMainBundle/CRUD/Controller/AbstractCRUDController.php index 2ef99ae03..4bc9b4d79 100644 --- a/src/Bundle/ChillMainBundle/CRUD/Controller/AbstractCRUDController.php +++ b/src/Bundle/ChillMainBundle/CRUD/Controller/AbstractCRUDController.php @@ -34,6 +34,29 @@ abstract class AbstractCRUDController extends AbstractController */ protected array $crudConfig = []; + /** + * get the role given from the config. + * + * @param mixed $entity + * @param mixed $_format + */ + protected function getRoleFor(string $action, Request $request, $entity, $_format): string + { + $actionConfig = $this->getActionConfig($action); + + if (null !== $actionConfig['roles'][$request->getMethod()]) { + return $actionConfig['roles'][$request->getMethod()]; + } + + if ($this->crudConfig['base_role']) { + return $this->crudConfig['base_role']; + } + + throw new \RuntimeException(sprintf('the config does not have any role for the ' . + 'method %s nor a global role for the whole action. Add those to your ' . + 'configuration or override the required method', $request->getMethod())); + } + public static function getSubscribedServices(): array { return array_merge( diff --git a/src/Bundle/ChillMainBundle/CRUD/Controller/ApiController.php b/src/Bundle/ChillMainBundle/CRUD/Controller/ApiController.php index be45be681..39e119bac 100644 --- a/src/Bundle/ChillMainBundle/CRUD/Controller/ApiController.php +++ b/src/Bundle/ChillMainBundle/CRUD/Controller/ApiController.php @@ -499,28 +499,6 @@ class ApiController extends AbstractCRUDController return ['groups' => ['read']]; } - /** - * get the role given from the config. - * - * @param mixed $entity - * @param mixed $_format - */ - protected function getRoleFor(string $action, Request $request, $entity, $_format): string - { - $actionConfig = $this->getActionConfig($action); - - if (null !== $actionConfig['roles'][$request->getMethod()]) { - return $actionConfig['roles'][$request->getMethod()]; - } - - if ($this->crudConfig['base_role']) { - return $this->crudConfig['base_role']; - } - - throw new RuntimeException(sprintf('the config does not have any role for the ' . - 'method %s nor a global role for the whole action. Add those to your ' . - 'configuration or override the required method', $request->getMethod())); - } protected function getSerializer(): SerializerInterface { diff --git a/src/Bundle/ChillMainBundle/Phonenumber/PhonenumberHelper.php b/src/Bundle/ChillMainBundle/Phonenumber/PhonenumberHelper.php index 5b52f6819..b14e5e645 100644 --- a/src/Bundle/ChillMainBundle/Phonenumber/PhonenumberHelper.php +++ b/src/Bundle/ChillMainBundle/Phonenumber/PhonenumberHelper.php @@ -183,7 +183,7 @@ final class PhonenumberHelper implements PhoneNumberHelperInterface } // filter only number - $filtered = preg_replace('/[^0-9]/', '', $phonenumber); + $filtered = preg_replace('/[^0-9]/', '', (string) $phonenumber); $item = $this->cachePool->getItem('pnum_' . $filtered); diff --git a/src/Bundle/ChillMainBundle/Security/Authorization/AbstractChillVoter.php b/src/Bundle/ChillMainBundle/Security/Authorization/AbstractChillVoter.php index ee64f3bc0..02ffc9122 100644 --- a/src/Bundle/ChillMainBundle/Security/Authorization/AbstractChillVoter.php +++ b/src/Bundle/ChillMainBundle/Security/Authorization/AbstractChillVoter.php @@ -26,28 +26,4 @@ use const E_USER_DEPRECATED; */ abstract class AbstractChillVoter extends Voter implements ChillVoterInterface { - protected function supports($attribute, $subject) - { - @trigger_error( - 'This voter should implements the new `supports` ' - . 'methods introduced by Symfony 3.0, and do not rely on ' - . 'getSupportedAttributes and getSupportedClasses methods.', - E_USER_DEPRECATED - ); - - // @TODO: getSupportedAttributes() should be created in here and made abstract or in ChillVoterInterface. - // @TODO: getSupportedClasses() should be created in here and made abstract or in ChillVoterInterface. - return in_array($attribute, $this->getSupportedAttributes($attribute), true) - && in_array(get_class($subject), $this->getSupportedClasses(), true); - } - - protected function voteOnAttribute($attribute, $subject, TokenInterface $token) - { - @trigger_error('This voter should implements the new `voteOnAttribute` ' - . 'methods introduced by Symfony 3.0, and do not rely on ' - . 'isGranted method', E_USER_DEPRECATED); - - // @TODO: isGranted() should be created in here and made abstract or in ChillVoterInterface. - return $this->isGranted($attribute, $subject, $token->getUser()); - } } diff --git a/src/Bundle/ChillPersonBundle/Controller/PersonController.php b/src/Bundle/ChillPersonBundle/Controller/PersonController.php index f4e188f96..bb03a6b33 100644 --- a/src/Bundle/ChillPersonBundle/Controller/PersonController.php +++ b/src/Bundle/ChillPersonBundle/Controller/PersonController.php @@ -59,6 +59,8 @@ final class PersonController extends AbstractController */ protected $personRepository; + private Security $security; + /** * @var SimilarPersonMatcher */ diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index ae7b927a6..19c275f17 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -1155,7 +1155,7 @@ class AccompanyingPeriod implements public function removeWork(AccompanyingPeriodWork $work): self { - $this->work->removeElement($work); + $this->works->removeElement($work); $work->setAccompanyingPeriod(null); return $this; diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/MembersEditorNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/MembersEditorNormalizer.php index 08286f1bd..740ea808c 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/MembersEditorNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/MembersEditorNormalizer.php @@ -181,7 +181,7 @@ class MembersEditorNormalizer implements DenormalizerAwareInterface, Denormalize { if ( null === $data['concerned'] ?? null - && false === ·\is_array('concerned') + && false === \is_array('concerned') ) { throw new Exception\UnexpectedValueException("The schema does not have any key 'concerned'"); } diff --git a/src/Bundle/ChillReportBundle/Export/Export/ReportList.php b/src/Bundle/ChillReportBundle/Export/Export/ReportList.php index d06ebb0f6..c2e7bbaf1 100644 --- a/src/Bundle/ChillReportBundle/Export/Export/ReportList.php +++ b/src/Bundle/ChillReportBundle/Export/Export/ReportList.php @@ -541,7 +541,7 @@ class ReportList implements ExportElementValidatedInterface, ListInterface . ' | ' . $label; } - if ('_other' === $slugChoice && $cfType->isChecked($cf, $choiceSlug, $decoded)) { + if ('_other' === $slugChoice && $cfType->isChecked($cf, $slugChoice, $decoded)) { return $cfType->extractOtherValue($cf, $decoded); } diff --git a/src/Bundle/ChillTaskBundle/Controller/TaskController.php b/src/Bundle/ChillTaskBundle/Controller/TaskController.php index 68ae65c99..6525d5572 100644 --- a/src/Bundle/ChillTaskBundle/Controller/TaskController.php +++ b/src/Bundle/ChillTaskBundle/Controller/TaskController.php @@ -83,7 +83,7 @@ class TaskController extends AbstractController if (null === $task) { throw $this->createNotFoundException("task with id '{$taskId}' and type " - . "'{$type}' does not exists"); + . "'{$kind}' does not exists"); } $workflow = $registry->get($task); diff --git a/src/Bundle/ChillThirdPartyBundle/Form/Type/PickThirdPartyTypeCategoryType.php b/src/Bundle/ChillThirdPartyBundle/Form/Type/PickThirdPartyTypeCategoryType.php index b8b19d1d6..eb7966084 100644 --- a/src/Bundle/ChillThirdPartyBundle/Form/Type/PickThirdPartyTypeCategoryType.php +++ b/src/Bundle/ChillThirdPartyBundle/Form/Type/PickThirdPartyTypeCategoryType.php @@ -88,22 +88,12 @@ class PickThirdPartyTypeCategoryType extends \Symfony\Component\Form\AbstractTyp return ChoiceType::class; } - public function reverseTransform($value) + private function reverseTransform($value) { if (null === $value) { return null; } - if (is_array($value)) { - $r = []; - - foreach ($value as $v) { - $r[] = $this->transform($v); - } - - return $r; - } - if ($value instanceof ThirdPartyCategory) { return 'category:' . $value->getId(); }