From 8ede116cf50578049982bbf3efe457ae425b6c07 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Tue, 16 Nov 2021 13:55:55 +0100 Subject: [PATCH] fix: SA: Split critical issues in its own file. SA stands for Static Analysis. --- phpstan-baseline.neon | 220 ------------------ phpstan-critical.neon | 212 +++++++++++++++++ phpstan.neon.dist | 1 + .../Authorization/AuthorizationHelper.php | 53 ++--- .../AuthorizationHelperInterface.php | 12 +- .../Entity/AccompanyingPeriod.php | 16 +- .../AccompanyingPeriodWorkRepository.php | 4 +- .../ChillPersonBundle/Search/PersonSearch.php | 33 +-- .../Normalizer/MembersEditorNormalizer.php | 24 +- .../Normalizer/PersonNormalizer.php | 46 +++- .../Widget/PersonListWidget.php | 87 ++----- .../PersonFilteringInterface.php | 5 +- 12 files changed, 333 insertions(+), 380 deletions(-) create mode 100644 phpstan-critical.neon diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 7b09a7d50..e7ac9187c 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -70,11 +70,6 @@ parameters: count: 1 path: src/Bundle/ChillActivityBundle/Repository/ActivityACLAwareRepository.php - - - message: "#^Undefined variable\\: \\$person$#" - count: 1 - path: src/Bundle/ChillActivityBundle/Repository/ActivityACLAwareRepository.php - - message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#" count: 1 @@ -85,21 +80,6 @@ parameters: count: 2 path: src/Bundle/ChillActivityBundle/Timeline/TimelineActivityProvider.php - - - message: "#^Access to an undefined property Chill\\\\AsideActivityBundle\\\\Entity\\\\AsideActivityCategory\\:\\:\\$oldParent\\.$#" - count: 2 - path: src/Bundle/ChillAsideActivityBundle/src/Entity/AsideActivityCategory.php - - - - message: "#^Access to an undefined property Chill\\\\AsideActivityBundle\\\\Form\\\\AsideActivityCategoryType\\:\\:\\$categoryRender\\.$#" - count: 2 - path: src/Bundle/ChillAsideActivityBundle/src/Form/AsideActivityCategoryType.php - - - - message: "#^Access to an undefined property Chill\\\\AsideActivityBundle\\\\Form\\\\AsideActivityFormType\\:\\:\\$translatableStringHelper\\.$#" - count: 1 - path: src/Bundle/ChillAsideActivityBundle/src/Form/AsideActivityFormType.php - - message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#" count: 1 @@ -125,11 +105,6 @@ parameters: count: 2 path: src/Bundle/ChillBudgetBundle/Security/Authorization/BudgetElementVoter.php - - - message: "#^Access to an undefined property Chill\\\\CalendarBundle\\\\DataFixtures\\\\ORM\\\\LoadCalendarRange\\:\\:\\$userRepository\\.$#" - count: 2 - path: src/Bundle/ChillCalendarBundle/DataFixtures/ORM/LoadCalendarRange.php - - message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#" count: 1 @@ -225,11 +200,6 @@ parameters: count: 1 path: src/Bundle/ChillCustomFieldsBundle/Form/CustomFieldType.php - - - message: "#^Access to an undefined property Chill\\\\CustomFieldsBundle\\\\Form\\\\DataTransformer\\\\JsonCustomFieldToArrayTransformer\\:\\:\\$customField\\.$#" - count: 3 - path: src/Bundle/ChillCustomFieldsBundle/Form/DataTransformer/JsonCustomFieldToArrayTransformer.php - - message: "#^Instantiated class PhpOffice\\\\PhpWord\\\\TemplateProcessor not found\\.$#" count: 1 @@ -320,11 +290,6 @@ parameters: count: 2 path: src/Bundle/ChillEventBundle/Security/Authorization/ParticipationVoter.php - - - message: "#^Undefined variable\\: \\$id$#" - count: 1 - path: src/Bundle/ChillFamilyMembersBundle/Controller/FamilyMemberController.php - - message: "#^Casting to string something that's already string\\.$#" count: 5 @@ -340,11 +305,6 @@ parameters: count: 2 path: src/Bundle/ChillFamilyMembersBundle/Security/Voter/FamilyMemberVoter.php - - - message: "#^Call to an undefined method Chill\\\\MainBundle\\\\CRUD\\\\Controller\\\\AbstractCRUDController\\:\\:getRoleFor\\(\\)\\.$#" - count: 1 - path: src/Bundle/ChillMainBundle/CRUD/Controller/AbstractCRUDController.php - - message: "#^Variable \\$entity in isset\\(\\) is never defined\\.$#" count: 1 @@ -380,11 +340,6 @@ parameters: count: 1 path: src/Bundle/ChillMainBundle/CRUD/Resolver/Resolver.php - - - message: "#^Access to an undefined property Chill\\\\MainBundle\\\\CRUD\\\\Routing\\\\CRUDRoutesLoader\\:\\:\\$apiConfig\\.$#" - count: 2 - path: src/Bundle/ChillMainBundle/CRUD/Routing/CRUDRoutesLoader.php - - message: "#^Call to function array_search\\(\\) requires parameter \\#3 to be set\\.$#" count: 1 @@ -400,11 +355,6 @@ parameters: count: 1 path: src/Bundle/ChillMainBundle/CRUD/Routing/CRUDRoutesLoader.php - - - message: "#^Call to an undefined method Chill\\\\MainBundle\\\\Command\\\\ChillImportUsersCommand\\:\\:tempOutput\\(\\)\\.$#" - count: 1 - path: src/Bundle/ChillMainBundle/Command/ChillImportUsersCommand.php - - message: "#^Method Chill\\\\MainBundle\\\\Command\\\\ChillImportUsersCommand\\:\\:execute\\(\\) should return int but return statement is missing\\.$#" count: 1 @@ -460,11 +410,6 @@ parameters: count: 1 path: src/Bundle/ChillMainBundle/Command/SetPasswordCommand.php - - - message: "#^Access to an undefined property Chill\\\\MainBundle\\\\Controller\\\\AdminCountryCRUDController\\:\\:\\$paginatorFactory\\.$#" - count: 1 - path: src/Bundle/ChillMainBundle/Controller/AdminCountryCRUDController.php - - message: "#^Cannot unset offset '_token' on array\\{formatter\\: mixed, export\\: mixed, centers\\: mixed, alias\\: string\\}\\.$#" count: 1 @@ -480,11 +425,6 @@ parameters: count: 1 path: src/Bundle/ChillMainBundle/Controller/PostalCodeController.php - - - message: "#^Call to an undefined method Chill\\\\MainBundle\\\\Controller\\\\UserController\\:\\:createEditForm\\(\\)\\.$#" - count: 1 - path: src/Bundle/ChillMainBundle/Controller/UserController.php - - message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#" count: 2 @@ -535,11 +475,6 @@ parameters: count: 1 path: src/Bundle/ChillMainBundle/Entity/Embeddable/CommentEmbeddable.php - - - message: "#^Access to an undefined property Chill\\\\MainBundle\\\\Entity\\\\RoleScope\\:\\:\\$new\\.$#" - count: 1 - path: src/Bundle/ChillMainBundle/Entity/RoleScope.php - - message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#" count: 1 @@ -635,11 +570,6 @@ parameters: count: 1 path: src/Bundle/ChillMainBundle/Form/Type/TranslatableStringFormType.php - - - message: "#^Undefined variable\\: \\$current$#" - count: 1 - path: src/Bundle/ChillMainBundle/Pagination/PageGenerator.php - - message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#" count: 2 @@ -660,36 +590,11 @@ parameters: count: 1 path: src/Bundle/ChillMainBundle/Routing/Loader/ChillRoutesLoader.php - - - message: "#^Access to an undefined property Chill\\\\MainBundle\\\\Routing\\\\MenuComposer\\:\\:\\$routeCollection\\.$#" - count: 1 - path: src/Bundle/ChillMainBundle/Routing/MenuComposer.php - - message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#" count: 1 path: src/Bundle/ChillMainBundle/Search/Entity/SearchUserApiProvider.php - - - message: "#^Access to an undefined property Chill\\\\MainBundle\\\\Search\\\\SearchApiResult\\:\\:\\$relevance\\.$#" - count: 2 - path: src/Bundle/ChillMainBundle/Search/SearchApiResult.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: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#" count: 2 @@ -815,26 +720,11 @@ parameters: count: 1 path: src/Bundle/ChillPersonBundle/Controller/HouseholdMemberController.php - - - message: "#^Access to an undefined property Chill\\\\PersonBundle\\\\Controller\\\\PersonController\\:\\:\\$security\\.$#" - count: 3 - path: src/Bundle/ChillPersonBundle/Controller/PersonController.php - - message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#" count: 1 path: src/Bundle/ChillPersonBundle/Controller/PersonController.php - - - message: "#^Access to an undefined property Chill\\\\PersonBundle\\\\Controller\\\\TimelinePersonController\\:\\:\\$authorizationHelper\\.$#" - count: 1 - path: src/Bundle/ChillPersonBundle/Controller/TimelinePersonController.php - - - - message: "#^Access to an undefined property Chill\\\\PersonBundle\\\\DataFixtures\\\\ORM\\\\LoadHousehold\\:\\:\\$personIds\\.$#" - count: 2 - path: src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadHousehold.php - - message: "#^Variable method call on mixed\\.$#" count: 1 @@ -855,31 +745,11 @@ parameters: count: 1 path: src/Bundle/ChillPersonBundle/DependencyInjection/CompilerPass/AccompanyingPeriodTimelineCompilerPass.php - - - message: "#^Access to an undefined property Chill\\\\PersonBundle\\\\Entity\\\\AccompanyingPeriod\\:\\:\\$work\\.$#" - count: 1 - path: src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php - - message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#" count: 1 path: src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php - - - 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\\\\Household\\\\PersonHouseholdAddress\\:\\:\\$relation\\.$#" - count: 1 - path: src/Bundle/ChillPersonBundle/Entity/Household/PersonHouseholdAddress.php - - - - message: "#^Access to an undefined property Chill\\\\PersonBundle\\\\Entity\\\\Person\\:\\:\\$currentHouseholdParticipationAt\\.$#" - count: 3 - path: src/Bundle/ChillPersonBundle/Entity/Person.php - - message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#" count: 1 @@ -950,11 +820,6 @@ parameters: count: 1 path: src/Bundle/ChillPersonBundle/Export/Export/ListPerson.php - - - message: "#^Undefined variable\\: \\$choiceSlug$#" - count: 1 - path: src/Bundle/ChillPersonBundle/Export/Export/ListPerson.php - - message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#" count: 1 @@ -975,11 +840,6 @@ parameters: count: 1 path: src/Bundle/ChillPersonBundle/Form/ChoiceLoader/PersonChoiceLoader.php - - - message: "#^Access to an undefined property Chill\\\\PersonBundle\\\\Form\\\\CreationPersonType\\:\\:\\$centerTransformer\\.$#" - count: 1 - path: src/Bundle/ChillPersonBundle/Form/CreationPersonType.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 1 @@ -1005,11 +865,6 @@ parameters: count: 1 path: src/Bundle/ChillPersonBundle/Household/MembersEditor.php - - - message: "#^Access to an undefined property Chill\\\\PersonBundle\\\\Household\\\\MembersEditorFactory\\:\\:\\$validator\\.$#" - count: 2 - path: src/Bundle/ChillPersonBundle/Household/MembersEditorFactory.php - - message: "#^Foreach overwrites \\$action with its value variable\\.$#" count: 1 @@ -1020,36 +875,6 @@ parameters: count: 1 path: src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php - - - message: "#^Parameter \\$action of method Chill\\\\PersonBundle\\\\Repository\\\\AccompanyingPeriod\\\\AccompanyingPeriodWorkRepository\\:\\:buildQueryBySocialActionWithDescendants\\(\\) has invalid type Chill\\\\PersonBundle\\\\Repository\\\\AccompanyingPeriod\\\\SocialAction\\.$#" - count: 1 - path: src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php - - - - message: "#^Parameter \\$action of method Chill\\\\PersonBundle\\\\Repository\\\\AccompanyingPeriod\\\\AccompanyingPeriodWorkRepository\\:\\:countBySocialActionWithDescendants\\(\\) has invalid type Chill\\\\PersonBundle\\\\Repository\\\\AccompanyingPeriod\\\\SocialAction\\.$#" - count: 1 - path: src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php - - - - message: "#^Undefined variable\\: \\$action$#" - count: 1 - path: src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php - - - - message: "#^Undefined variable\\: \\$limit$#" - count: 1 - path: src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php - - - - message: "#^Undefined variable\\: \\$offset$#" - count: 1 - path: src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php - - - - message: "#^Undefined variable\\: \\$orderBy$#" - count: 1 - path: src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php - - message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#" count: 2 @@ -1075,11 +900,6 @@ parameters: count: 1 path: src/Bundle/ChillPersonBundle/Search/PersonSearch.php - - - message: "#^Variable variables are not allowed\\.$#" - count: 4 - path: src/Bundle/ChillPersonBundle/Search/PersonSearch.php - - message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#" count: 1 @@ -1095,16 +915,6 @@ parameters: count: 1 path: src/Bundle/ChillPersonBundle/Serializer/Normalizer/AccompanyingPeriodWorkDenormalizer.php - - - message: "#^Function Chill\\\\PersonBundle\\\\Serializer\\\\Normalizer\\\\·\\\\is_array not found\\.$#" - count: 1 - path: src/Bundle/ChillPersonBundle/Serializer/Normalizer/MembersEditorNormalizer.php - - - - message: "#^Variable method call on object\\.$#" - count: 2 - path: src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonNormalizer.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 2 @@ -1115,16 +925,6 @@ parameters: count: 1 path: src/Bundle/ChillPersonBundle/Timeline/AbstractTimelineAccompanyingPeriod.php - - - message: "#^Undefined variable\\: \\$value$#" - count: 1 - path: src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/LocationValidityValidator.php - - - - message: "#^Parameter \\$personRepostory of method Chill\\\\PersonBundle\\\\Widget\\\\PersonListWidget\\:\\:__construct\\(\\) has invalid type Chill\\\\PersonBundle\\\\Widget\\\\PersonRepository\\.$#" - count: 1 - path: src/Bundle/ChillPersonBundle/Widget/PersonListWidget.php - - message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#" count: 1 @@ -1190,11 +990,6 @@ parameters: count: 1 path: src/Bundle/ChillReportBundle/Export/Export/ReportList.php - - - message: "#^Undefined variable\\: \\$choiceSlug$#" - count: 1 - path: src/Bundle/ChillReportBundle/Export/Export/ReportList.php - - message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#" count: 1 @@ -1205,21 +1000,11 @@ parameters: count: 1 path: src/Bundle/ChillReportBundle/Security/Authorization/ReportVoter.php - - - message: "#^Access to an undefined property Chill\\\\ReportBundle\\\\Timeline\\\\TimelineReportProvider\\:\\:\\$security\\.$#" - count: 4 - path: src/Bundle/ChillReportBundle/Timeline/TimelineReportProvider.php - - message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#" count: 4 path: src/Bundle/ChillReportBundle/Timeline/TimelineReportProvider.php - - - message: "#^Undefined variable\\: \\$type$#" - count: 1 - path: src/Bundle/ChillTaskBundle/Controller/TaskController.php - - message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#" count: 1 @@ -1295,11 +1080,6 @@ parameters: count: 1 path: src/Bundle/ChillThirdPartyBundle/Form/ChoiceLoader/ThirdPartyChoiceLoader.php - - - message: "#^Call to an undefined method Chill\\\\ThirdPartyBundle\\\\Form\\\\Type\\\\PickThirdPartyTypeCategoryType\\:\\:transform\\(\\)\\.$#" - count: 1 - path: src/Bundle/ChillThirdPartyBundle/Form/Type/PickThirdPartyTypeCategoryType.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 1 diff --git a/phpstan-critical.neon b/phpstan-critical.neon new file mode 100644 index 000000000..e071ed30c --- /dev/null +++ b/phpstan-critical.neon @@ -0,0 +1,212 @@ +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\\\\Person\\:\\:\\$currentHouseholdParticipationAt\\.$#" + count: 3 + path: src/Bundle/ChillPersonBundle/Entity/Person.php + + - + message: "#^Access to an undefined property Chill\\\\PersonBundle\\\\Entity\\\\Household\\\\PersonHouseholdAddress\\:\\:\\$relation\\.$#" + count: 1 + path: src/Bundle/ChillPersonBundle/Entity/Household/PersonHouseholdAddress.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: "#^Access to an undefined property Chill\\\\PersonBundle\\\\Household\\\\MembersEditorFactory\\:\\:\\$validator\\.$#" + count: 2 + path: src/Bundle/ChillPersonBundle/Household/MembersEditorFactory.php + + - + message: "#^Parameter \\$action of method Chill\\\\PersonBundle\\\\Repository\\\\AccompanyingPeriod\\\\AccompanyingPeriodWorkRepository\\:\\:buildQueryBySocialActionWithDescendants\\(\\) has invalid type Chill\\\\PersonBundle\\\\Repository\\\\AccompanyingPeriod\\\\SocialAction\\.$#" + count: 1 + path: src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php + + - + message: "#^Parameter \\$action of method Chill\\\\PersonBundle\\\\Repository\\\\AccompanyingPeriod\\\\AccompanyingPeriodWorkRepository\\:\\:countBySocialActionWithDescendants\\(\\) has invalid type Chill\\\\PersonBundle\\\\Repository\\\\AccompanyingPeriod\\\\SocialAction\\.$#" + count: 1 + path: src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php + + - + message: "#^Undefined variable\\: \\$action$#" + count: 1 + path: src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php + + - + message: "#^Undefined variable\\: \\$limit$#" + count: 1 + path: src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php + + - + message: "#^Undefined variable\\: \\$offset$#" + count: 1 + path: src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php + + - + message: "#^Undefined variable\\: \\$orderBy$#" + count: 1 + path: src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.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\\: \\$value$#" + count: 1 + path: src/Bundle/ChillPersonBundle/Validator/Constraints/AccompanyingPeriod/LocationValidityValidator.php + + - + message: "#^Undefined variable\\: \\$choiceSlug$#" + count: 1 + path: src/Bundle/ChillPersonBundle/Export/Export/ListPerson.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: "#^Undefined variable\\: \\$id$#" + count: 1 + path: src/Bundle/ChillFamilyMembersBundle/Controller/FamilyMemberController.php + + - + message: "#^Call to an undefined method Chill\\\\MainBundle\\\\CRUD\\\\Controller\\\\AbstractCRUDController\\:\\:getRoleFor\\(\\)\\.$#" + count: 1 + path: src/Bundle/ChillMainBundle/CRUD/Controller/AbstractCRUDController.php + + - + message: "#^Access to an undefined property Chill\\\\MainBundle\\\\CRUD\\\\Routing\\\\CRUDRoutesLoader\\:\\:\\$apiConfig\\.$#" + count: 2 + path: src/Bundle/ChillMainBundle/CRUD/Routing/CRUDRoutesLoader.php + + - + message: "#^Call to an undefined method Chill\\\\MainBundle\\\\Command\\\\ChillImportUsersCommand\\:\\:tempOutput\\(\\)\\.$#" + count: 1 + path: src/Bundle/ChillMainBundle/Command/ChillImportUsersCommand.php + + - + message: "#^Access to an undefined property Chill\\\\MainBundle\\\\Controller\\\\AdminCountryCRUDController\\:\\:\\$paginatorFactory\\.$#" + count: 1 + path: src/Bundle/ChillMainBundle/Controller/AdminCountryCRUDController.php + + - + message: "#^Call to an undefined method Chill\\\\MainBundle\\\\Controller\\\\UserController\\:\\:createEditForm\\(\\)\\.$#" + count: 1 + path: src/Bundle/ChillMainBundle/Controller/UserController.php + + - + message: "#^Access to an undefined property Chill\\\\MainBundle\\\\Entity\\\\RoleScope\\:\\:\\$new\\.$#" + count: 1 + path: src/Bundle/ChillMainBundle/Entity/RoleScope.php + + - + message: "#^Undefined variable\\: \\$current$#" + count: 1 + path: src/Bundle/ChillMainBundle/Pagination/PageGenerator.php + + - + message: "#^Access to an undefined property Chill\\\\MainBundle\\\\Routing\\\\MenuComposer\\:\\:\\$routeCollection\\.$#" + count: 1 + path: src/Bundle/ChillMainBundle/Routing/MenuComposer.php + + - + message: "#^Access to an undefined property Chill\\\\MainBundle\\\\Search\\\\SearchApiResult\\:\\:\\$relevance\\.$#" + count: 2 + path: src/Bundle/ChillMainBundle/Search/SearchApiResult.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: "#^Access to an undefined property Chill\\\\PersonBundle\\\\Controller\\\\TimelinePersonController\\:\\:\\$authorizationHelper\\.$#" + count: 1 + path: src/Bundle/ChillPersonBundle/Controller/TimelinePersonController.php + + - + message: "#^Access to an undefined property Chill\\\\PersonBundle\\\\DataFixtures\\\\ORM\\\\LoadHousehold\\:\\:\\$personIds\\.$#" + count: 2 + path: src/Bundle/ChillPersonBundle/DataFixtures/ORM/LoadHousehold.php + + - + message: "#^Access to an undefined property Chill\\\\PersonBundle\\\\Form\\\\CreationPersonType\\:\\:\\$centerTransformer\\.$#" + count: 1 + path: src/Bundle/ChillPersonBundle/Form/CreationPersonType.php + + - + message: "#^Access to an undefined property Chill\\\\ReportBundle\\\\Timeline\\\\TimelineReportProvider\\:\\:\\$security\\.$#" + count: 4 + path: src/Bundle/ChillReportBundle/Timeline/TimelineReportProvider.php + + - + message: "#^Access to an undefined property Chill\\\\AsideActivityBundle\\\\Entity\\\\AsideActivityCategory\\:\\:\\$oldParent\\.$#" + count: 2 + path: src/Bundle/ChillAsideActivityBundle/src/Entity/AsideActivityCategory.php + + - + message: "#^Access to an undefined property Chill\\\\AsideActivityBundle\\\\Form\\\\AsideActivityCategoryType\\:\\:\\$categoryRender\\.$#" + count: 2 + path: src/Bundle/ChillAsideActivityBundle/src/Form/AsideActivityCategoryType.php + + - + message: "#^Access to an undefined property Chill\\\\AsideActivityBundle\\\\Form\\\\AsideActivityFormType\\:\\:\\$translatableStringHelper\\.$#" + count: 1 + path: src/Bundle/ChillAsideActivityBundle/src/Form/AsideActivityFormType.php + + - + message: "#^Access to an undefined property Chill\\\\CalendarBundle\\\\DataFixtures\\\\ORM\\\\LoadCalendarRange\\:\\:\\$userRepository\\.$#" + count: 2 + path: src/Bundle/ChillCalendarBundle/DataFixtures/ORM/LoadCalendarRange.php + + - + message: "#^Access to an undefined property Chill\\\\CustomFieldsBundle\\\\Form\\\\DataTransformer\\\\JsonCustomFieldToArrayTransformer\\:\\:\\$customField\\.$#" + count: 3 + path: src/Bundle/ChillCustomFieldsBundle/Form/DataTransformer/JsonCustomFieldToArrayTransformer.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/phpstan.neon.dist b/phpstan.neon.dist index 242e35626..2c312943b 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -17,5 +17,6 @@ parameters: - src/Bundle/*/src/Resources/* includes: + - phpstan-critical.neon - phpstan-baseline.neon diff --git a/src/Bundle/ChillMainBundle/Security/Authorization/AuthorizationHelper.php b/src/Bundle/ChillMainBundle/Security/Authorization/AuthorizationHelper.php index 53ee73216..b90556b69 100644 --- a/src/Bundle/ChillMainBundle/Security/Authorization/AuthorizationHelper.php +++ b/src/Bundle/ChillMainBundle/Security/Authorization/AuthorizationHelper.php @@ -23,6 +23,7 @@ use Chill\MainBundle\Security\RoleProvider; use Doctrine\ORM\EntityManagerInterface; use Chill\MainBundle\Entity\GroupCenter; use Chill\MainBundle\Entity\RoleScope; +use Symfony\Component\Security\Core\User\UserInterface; /** * Helper for authorizations. @@ -145,19 +146,21 @@ class AuthorizationHelper implements AuthorizationHelperInterface if ($this->scopeResolverDispatcher->isConcerned($entity)) { $scope = $this->scopeResolverDispatcher->resolveScope($entity); - if (NULL === $scope) { - return true; - } elseif (is_iterable($scope)) { - foreach ($scope as $s) { - if ($s === $roleScope->getScope()) { - return true; - } - } - } else { - if ($scope === $roleScope->getScope()) { - return true; - } - } + if (NULL === $scope) { + return true; + } + + if (is_iterable($scope)) { + foreach ($scope as $s) { + if ($s === $roleScope->getScope()) { + return true; + } + } + } else { + if ($scope === $roleScope->getScope()) { + return true; + } + } } else { return true; } @@ -176,14 +179,11 @@ class AuthorizationHelper implements AuthorizationHelperInterface /** * Get reachable Centers for the given user, role, - * and optionnaly Scope + * and optionally Scope * - * @param User $user - * @param string|Role $role - * @param null|Scope $scope * @return Center[]|array */ - public function getReachableCenters(User $user, string $role, ?Scope $scope = null): array + public function getReachableCenters(UserInterface $user, string $role, ?Scope $scope = null): array { if ($role instanceof Role) { $role = $role->getRole(); @@ -199,11 +199,11 @@ class AuthorizationHelper implements AuthorizationHelperInterface if ($scope === null) { $centers[] = $groupCenter->getCenter(); break 1; - } else { - if ($scope->getId() == $roleScope->getScope()->getId()){ - $centers[] = $groupCenter->getCenter(); - break 1; - } + } + + if ($scope->getId() == $roleScope->getScope()->getId()){ + $centers[] = $groupCenter->getCenter(); + break 1; } } } @@ -242,12 +242,10 @@ class AuthorizationHelper implements AuthorizationHelperInterface * * @deprecated Use getReachableCircles * - * @param User $user - * @param string role * @param Center|Center[] $center * @return Scope[]|array */ - public function getReachableScopes(User $user, string $role, $center): array + public function getReachableScopes(UserInterface $user, string $role, $center): array { if ($role instanceof Role) { $role = $role->getRole(); @@ -259,12 +257,11 @@ class AuthorizationHelper implements AuthorizationHelperInterface /** * Return all reachable circle for a given user, center and role * - * @param User $user * @param string|Role $role * @param Center|Center[] $center * @return Scope[] */ - public function getReachableCircles(User $user, $role, $center) + public function getReachableCircles(UserInterface $user, $role, $center) { $scopes = []; diff --git a/src/Bundle/ChillMainBundle/Security/Authorization/AuthorizationHelperInterface.php b/src/Bundle/ChillMainBundle/Security/Authorization/AuthorizationHelperInterface.php index 31709bcd5..2ad30f8f3 100644 --- a/src/Bundle/ChillMainBundle/Security/Authorization/AuthorizationHelperInterface.php +++ b/src/Bundle/ChillMainBundle/Security/Authorization/AuthorizationHelperInterface.php @@ -4,29 +4,23 @@ namespace Chill\MainBundle\Security\Authorization; use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Entity\Scope; -use Chill\MainBundle\Entity\User; -use Symfony\Component\Security\Core\Role\Role; +use Symfony\Component\Security\Core\User\UserInterface; interface AuthorizationHelperInterface { - /** * Get reachable Centers for the given user, role, * and optionnaly Scope * - * @param User $user - * @param string|Role $role * @param null|Scope $scope * @return Center[] */ - public function getReachableCenters(User $user, string $role, ?Scope $scope = null): array; + public function getReachableCenters(UserInterface $user, string $role, ?Scope $scope = null): array; /** - * @param User $user - * @param string $role * @param Center|Center[]|array $center * @return array */ - public function getReachableScopes(User $user, string $role, $center): array; + public function getReachableScopes(UserInterface $user, string $role, $center): array; } diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index d08f39b1e..15f33abe7 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -1044,9 +1044,9 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface { if (count($this->getPersons()) === 0){ return null; - } else { - return $this->getPersons()->first()->getCenter(); } + + return $this->getPersons()->first()->getCenter(); } /** @@ -1116,7 +1116,9 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface { if ($this->getPersonLocation() instanceof Person) { return 'person'; - } elseif ($this->getAddressLocation() instanceof Address) { + } + + if ($this->getAddressLocation() instanceof Address) { return 'address'; } else { return 'none'; @@ -1137,11 +1139,11 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface public function getGroupSequence() { - if ($this->getStep() == self::STEP_DRAFT) - { + if ($this->getStep() == self::STEP_DRAFT) { return [[self::STEP_DRAFT]]; - } elseif ($this->getStep() == self::STEP_CONFIRMED) - { + } + + if ($this->getStep() == self::STEP_CONFIRMED) { return [[self::STEP_DRAFT, self::STEP_CONFIRMED]]; } diff --git a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php index 872feebbe..c1eea373e 100644 --- a/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php +++ b/src/Bundle/ChillPersonBundle/Repository/AccompanyingPeriod/AccompanyingPeriodWorkRepository.php @@ -1,5 +1,7 @@ findOneBy($criteria); + return $this->repository->findOneBy($criteria); } public function getClassName() diff --git a/src/Bundle/ChillPersonBundle/Search/PersonSearch.php b/src/Bundle/ChillPersonBundle/Search/PersonSearch.php index 7fff34d7d..d83749147 100644 --- a/src/Bundle/ChillPersonBundle/Search/PersonSearch.php +++ b/src/Bundle/ChillPersonBundle/Search/PersonSearch.php @@ -1,22 +1,7 @@ - * - * 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 . - */ +declare(strict_types=1); + namespace Chill\PersonBundle\Search; use Chill\MainBundle\Search\AbstractSearch; @@ -38,7 +23,7 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf protected PaginatorFactory $paginatorFactory; protected PersonACLAwareRepositoryInterface $personACLAwareRepository; - const NAME = "person_regular"; + public const NAME = "person_regular"; private const POSSIBLE_KEYS = [ '_default', 'firstname', 'lastname', 'birthdate', 'birthdate-before', @@ -102,7 +87,9 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf 'preview' => $options[SearchInterface::SEARCH_PREVIEW_OPTION], 'paginator' => $paginator )); - } elseif ($format === 'json') { + } + + if ($format === 'json') { return [ 'results' => $this->search($terms, $start, $limit, \array_merge($options, [ 'simplify' => true ])), 'pagination' => [ @@ -113,14 +100,9 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf } /** - * - * @param string $pattern - * @param int $start - * @param int $limit - * @param array $options * @return Person[] */ - protected function search(array $terms, $start, $limit, array $options = array()) + protected function search(array $terms, int $start, int $limit, array $options = []) { [ '_default' => $default, @@ -131,7 +113,6 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf 'birthdate-after' => $birthdateAfter, 'gender' => $gender, 'nationality' => $countryCode, - ] = $terms + \array_fill_keys(self::POSSIBLE_KEYS, null); foreach (['birthdateBefore', 'birthdateAfter', 'birthdate'] as $v) { diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/MembersEditorNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/MembersEditorNormalizer.php index b2c21c048..f3bcd74af 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/MembersEditorNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/MembersEditorNormalizer.php @@ -1,5 +1,7 @@ denormalizeLeave($data, $type, $format, $context); - } else { - return $this->denormalizeMove($data, $type, $format, $context); } + + return $this->denormalizeMove($data, $type, $format, $context); } private function performChecks($data): void { - if (NULL == $data['concerned'] ?? NULL + if (NULL == $data['concerned'] ?? NULL && FALSE === ·\is_array('concerned')) { throw new Exception\UnexpectedValueException("The schema does not have any key 'concerned'"); } @@ -55,8 +57,8 @@ class MembersEditorNormalizer implements DenormalizerInterface, DenormalizerAwar $editor = $this->factory->createEditor(null); foreach ($data['concerned'] as $key => $concerned) { - $person = $this->denormalizer->denormalize($concerned['person'] ?? null, Person::class, - $format, $context); + $person = $this->denormalizer->denormalize($concerned['person'] ?? null, Person::class, + $format, $context); $startDate = $this->denormalizer->denormalize($concerned['start_date'] ?? null, \DateTimeImmutable::class, $format, $context); @@ -80,18 +82,18 @@ class MembersEditorNormalizer implements DenormalizerInterface, DenormalizerAwar $householdContext = $context; $householdContext['groups'][] = 'create'; - $household = $this->denormalizer->denormalize($data['destination'], Household::class, + $household = $this->denormalizer->denormalize($data['destination'], Household::class, $format, $householdContext); if (NULL === $household) { - throw new Exception\InvalidArgumentException("household could not be denormalized. Impossible to process"); + throw new Exception\InvalidArgumentException("household could not be denormalized. Impossible to process"); } $editor = $this->factory->createEditor($household); foreach ($data['concerned'] as $key => $concerned) { - $person = $this->denormalizer->denormalize($concerned['person'] ?? null, Person::class, - $format, $context); + $person = $this->denormalizer->denormalize($concerned['person'] ?? null, Person::class, + $format, $context); $position = $this->denormalizer->denormalize($concerned['position'] ?? null, Position::class, $format, $context); $startDate = $this->denormalizer->denormalize($concerned['start_date'] ?? null, \DateTimeImmutable::class, @@ -110,10 +112,10 @@ class MembersEditorNormalizer implements DenormalizerInterface, DenormalizerAwar "person, position or start_date."); } - $editor->addMovement($startDate, $person, $position, $holder, + $editor->addMovement($startDate, $person, $position, $holder, $comment); } - + return $editor; } diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonNormalizer.php index 019f3989e..b7e0069ee 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonNormalizer.php @@ -67,7 +67,7 @@ class PersonNormalizer implements $this->centerResolverDispatcher = $centerResolverDispatcher; } - public function normalize($person, string $format = null, array $context = array()) + public function normalize($person, string $format = null, array $context = []) { /** @var Household $household */ $household = $person->getCurrentHousehold(); @@ -128,22 +128,44 @@ class PersonNormalizer implements $person = new Person(); } - foreach (['firstName', 'lastName', 'phonenumber', 'mobilenumber', 'gender'] - as $item) { - if (\array_key_exists($item, $data)) { - $person->{'set'.\ucfirst($item)}($data[$item]); + $properties = ['firstName', 'lastName', 'phonenumber', 'mobilenumber', 'gender']; + + $properties = array_filter( + $properties, + static fn (string $property): bool => array_key_exists($property, $data) + ); + + foreach ($properties as $item) { + $callable = [$person, sprintf('set%s', ucfirst($item))]; + + if (is_callable($callable)) { + $closure = \Closure::fromCallable($callable); + + $closure($data[$item]); } } - foreach ([ + $propertyToClassMapping = [ 'birthdate' => \DateTime::class, 'deathdate' => \DateTime::class, - 'center' => Center::class - ] as $item => $class) { - if (\array_key_exists($item, $data)) { - $object = $this->denormalizer->denormalize($data[$item], $class, $format, $context); - if ($object instanceof $class) { - $person->{'set'.\ucfirst($item)}($object); + 'center' => Center::class, + ]; + + $propertyToClassMapping = array_filter( + $propertyToClassMapping, + static fn (string $item): bool => array_key_exists($item, $data) + ); + + foreach ($propertyToClassMapping as $item => $class) { + $object = $this->denormalizer->denormalize($data[$item], $class, $format, $context); + + if ($object instanceof $class) { + $callable = [$object, sprintf('set%s', ucfirst($item))]; + + if (is_callable($callable)) { + $closure = \Closure::fromCallable($callable); + + $closure($object); } } } diff --git a/src/Bundle/ChillPersonBundle/Widget/PersonListWidget.php b/src/Bundle/ChillPersonBundle/Widget/PersonListWidget.php index d8e61f499..f1a631882 100644 --- a/src/Bundle/ChillPersonBundle/Widget/PersonListWidget.php +++ b/src/Bundle/ChillPersonBundle/Widget/PersonListWidget.php @@ -1,35 +1,22 @@ - * - * 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 . - */ +declare(strict_types=1); namespace Chill\PersonBundle\Widget; +use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface; use Chill\MainBundle\Templating\Widget\WidgetInterface; -use Doctrine\ORM\EntityRepository; +use Chill\PersonBundle\Repository\PersonRepository; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Query\Expr; use Doctrine\DBAL\Types\Types; use Chill\MainBundle\Security\Authorization\AuthorizationHelper; +use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage; use Chill\PersonBundle\Security\Authorization\PersonVoter; use Symfony\Component\Security\Core\Role\Role; use Doctrine\ORM\EntityManager; -use Chill\CustomFieldsBundle\Entity\CustomField; use Twig\Environment; /** @@ -42,45 +29,22 @@ use Twig\Environment; */ class PersonListWidget implements WidgetInterface { - /** - * Repository for persons - * - * @var PersonRepository - */ - protected $personRepository; + protected PersonRepository $personRepository; - /** - * The entity manager - * - * @var EntityManager - */ - protected $entityManager; + protected EntityManagerInterface $entityManager; - /** - * the authorization helper - * - * @var AuthorizationHelper; - */ - protected $authorizationHelper; + protected AuthorizationHelperInterface $authorizationHelper; - /** - * - * @var TokenStorage - */ - protected $tokenStorage; + protected TokenStorageInterface $tokenStorage; - /** - * - * @var UserInterface - */ - protected $user; + protected UserInterface $user; public function __construct( PersonRepository $personRepostory, - EntityManager $em, - AuthorizationHelper $authorizationHelper, - TokenStorage $tokenStorage - ) { + EntityManagerInterface $em, + AuthorizationHelperInterface $authorizationHelper, + TokenStorageInterface $tokenStorage + ) { $this->personRepository = $personRepostory; $this->authorizationHelper = $authorizationHelper; $this->tokenStorage = $tokenStorage; @@ -88,11 +52,8 @@ class PersonListWidget implements WidgetInterface } /** - * - * @param type $place * @param array $context * @param array $config - * @return string */ public function render(Environment $env, $place, array $context, array $config) { @@ -134,8 +95,10 @@ class PersonListWidget implements WidgetInterface . "implements %s", $config['filtering_class'], PersonListWidget\PersonFilteringInterface::class)); } - $ids = $filteringClass->getPersonIds($this->entityManager, - $this->getUser()); + $ids = $filteringClass->getPersonIds( + $this->entityManager, + $this->getUser() + ); $in = (new Expr())->in('person.id', ':ids'); $and->add($in); $qb->setParameter('ids', $ids); @@ -178,12 +141,7 @@ class PersonListWidget implements WidgetInterface ); } - /** - * - * @return UserInterface - * @throws \RuntimeException - */ - private function getUser() + private function getUser(): UserInterface { $token = $this->tokenStorage->getToken(); @@ -193,9 +151,10 @@ class PersonListWidget implements WidgetInterface $user = $token->getUser(); - if (!$user instanceof UserInterface || $user == null) { - throw new \RuntimeException("the user should implement UserInterface. " - . "Are you logged in ?"); + if ($user === null) { + throw new \RuntimeException( + 'The user should implement UserInterface. Are you logged in ?' + ); } return $user; diff --git a/src/Bundle/ChillPersonBundle/Widget/PersonListWidget/PersonFilteringInterface.php b/src/Bundle/ChillPersonBundle/Widget/PersonListWidget/PersonFilteringInterface.php index d1de741ab..b21151b83 100644 --- a/src/Bundle/ChillPersonBundle/Widget/PersonListWidget/PersonFilteringInterface.php +++ b/src/Bundle/ChillPersonBundle/Widget/PersonListWidget/PersonFilteringInterface.php @@ -22,6 +22,8 @@ namespace Chill\PersonBundle\Widget\PersonListWidget; use Doctrine\ORM\EntityManager; use Chill\MainBundle\Entity\User; +use Doctrine\ORM\EntityManagerInterface; +use Symfony\Component\Security\Core\User\UserInterface; /** @@ -78,8 +80,7 @@ interface PersonFilteringInterface } * ``` * - * @param EntityManager $em * @return int[] an array of persons id to show */ - public function getPersonIds(EntityManager $em, User $user); + public function getPersonIds(EntityManagerInterface $em, UserInterface $user); }