| Conditions | 13 |
| Paths | 671 |
| Total Lines | 152 |
| Code Lines | 90 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 35 | public function __invoke(Request $request): JsonResponse |
||
| 36 | { |
||
| 37 | try { |
||
| 38 | $myCompanies = []; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var \ControleOnline\Entity\User |
||
| 42 | */ |
||
| 43 | $currentUser = $this->security->getToken()->getUser(); |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @var \ControleOnline\Entity\People |
||
| 47 | */ |
||
| 48 | $userPeople = $currentUser->getPeople(); |
||
| 49 | $permissions = []; |
||
| 50 | |||
| 51 | |||
| 52 | $getPeopleCompanies = $userPeople->getLink(); |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var \ControleOnline\Entity\PeopleLink $peopleCompany |
||
| 56 | */ |
||
| 57 | foreach ($getPeopleCompanies as $peopleCompany) { |
||
| 58 | |||
| 59 | $allConfigs = []; |
||
| 60 | $configs = []; |
||
| 61 | $people = $peopleCompany->getCompany(); |
||
| 62 | |||
| 63 | //if ($peopleCompany->getEnabled() && $people->getEnabled()) { |
||
| 64 | |||
| 65 | $domains = $this->getPeopleDomains($people); |
||
| 66 | $packages = $this->getPeoplePackages($people); |
||
| 67 | |||
| 68 | |||
| 69 | $permissions[$people->getId()] = $this->roles->getAllRoles($people); |
||
| 70 | |||
| 71 | $allConfigs = $this->em->getRepository(Config::class)->findBy([ |
||
| 72 | 'people' => $people->getId(), |
||
| 73 | 'visibility' => 'public' |
||
| 74 | ]); |
||
| 75 | foreach ($allConfigs as $config) { |
||
| 76 | $configs[$config->getConfigKey()] = $config->getConfigValue(); |
||
| 77 | } |
||
| 78 | |||
| 79 | |||
| 80 | $myCompanies[$people->getId()] = [ |
||
| 81 | 'id' => $people->getId(), |
||
| 82 | 'enabled' => $people->getEnabled(), |
||
| 83 | 'alias' => $people->getAlias(), |
||
| 84 | 'logo' => $this->fileService->getFileUrl($people), |
||
| 85 | 'document' => $this->getDocument($people), |
||
| 86 | 'domains' => $domains, |
||
| 87 | 'configs' => $configs, |
||
| 88 | 'packages' => $packages, |
||
| 89 | 'user' => [ |
||
| 90 | 'id' => $userPeople->getId(), |
||
| 91 | 'name' => $userPeople->getName(), |
||
| 92 | 'alias' => $userPeople->getAlias(), |
||
| 93 | 'enabled' => $userPeople->getEnabled(), |
||
| 94 | 'employee_enabled' => $peopleCompany->getEnabled(), |
||
| 95 | 'salesman_enabled' => false |
||
| 96 | ] |
||
| 97 | ]; |
||
| 98 | //} |
||
| 99 | } |
||
| 100 | |||
| 101 | $peopleSalesman = $this->em->getRepository(People::class)->getPeopleLinks($userPeople, 'salesman'); |
||
| 102 | |||
| 103 | foreach ($peopleSalesman as $com) { |
||
| 104 | $company = $this->em->getRepository(People::class)->find($com['people_id']); |
||
| 105 | $allConfigs = []; |
||
| 106 | $configs = []; |
||
| 107 | $allConfigs = $this->em->getRepository(Config::class)->findBy([ |
||
| 108 | 'people' => $company->getId(), |
||
| 109 | 'visibility' => 'public' |
||
| 110 | ]); |
||
| 111 | foreach ($allConfigs as $config) { |
||
| 112 | $configs[$config->getConfigKey()] = $config->getConfigValue(); |
||
| 113 | } |
||
| 114 | |||
| 115 | if ($company) { |
||
| 116 | $people_domains = $this->em->getRepository(PeopleDomain::class)->findBy(['people' => $com['people_id']]); |
||
| 117 | |||
| 118 | $domains = []; |
||
| 119 | |||
| 120 | if (!empty($people_domains)) { |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @var PeopleDomain $company |
||
| 124 | */ |
||
| 125 | foreach ($people_domains as $domain) { |
||
| 126 | |||
| 127 | $domains[] = [ |
||
| 128 | 'id' => $domain->getId(), |
||
| 129 | 'domainType' => $domain->getDomainType(), |
||
| 130 | 'domain' => $domain->getDomain() |
||
| 131 | ]; |
||
| 132 | } |
||
| 133 | } |
||
| 134 | |||
| 135 | $peopleemployee = $this->em->getRepository(PeopleLink::class)->findOneBy(['company' => $company, 'employee' => $userPeople]); |
||
| 136 | |||
| 137 | $permissions[$company->getId()][] = 'salesman'; |
||
| 138 | $myCompanies[$company->getId()] = [ |
||
| 139 | 'id' => $company->getId(), |
||
| 140 | 'enabled' => $company->getEnabled(), |
||
| 141 | 'alias' => $company->getAlias(), |
||
| 142 | 'logo' => $this->fileService->getFileUrl($company), |
||
| 143 | 'document' => $this->getDocument($company), |
||
| 144 | 'commission' => $com['commission'], |
||
| 145 | 'domains' => $domains, |
||
| 146 | 'configs' => $configs, |
||
| 147 | 'user' => [ |
||
| 148 | 'id' => $userPeople->getId(), |
||
| 149 | 'name' => $userPeople->getName(), |
||
| 150 | 'alias' => $userPeople->getAlias(), |
||
| 151 | 'enabled' => $userPeople->getEnabled(), |
||
| 152 | 'employee_enabled' => $peopleemployee ? $peopleemployee->getEnabled() : $com['enable'], |
||
| 153 | 'salesman_enabled' => $com['enable'] |
||
| 154 | ] |
||
| 155 | ]; |
||
| 156 | } |
||
| 157 | } |
||
| 158 | |||
| 159 | foreach ($permissions as $key => $permission) { |
||
| 160 | $myCompanies[$key]['permission'] = array_values($permission); |
||
| 161 | } |
||
| 162 | |||
| 163 | usort($myCompanies, function ($a, $b) { |
||
| 164 | |||
| 165 | if ($a['alias'] == $b['alias']) { |
||
| 166 | return 0; |
||
| 167 | } |
||
| 168 | return ($a['alias'] < $b['alias']) ? -1 : 1; |
||
| 169 | }); |
||
| 170 | |||
| 171 | return new JsonResponse([ |
||
| 172 | 'response' => [ |
||
| 173 | 'data' => $myCompanies, |
||
| 174 | 'count' => count($myCompanies), |
||
| 175 | 'error' => '', |
||
| 176 | 'success' => true, |
||
| 177 | ], |
||
| 178 | ]); |
||
| 179 | } catch (\Exception $e) { |
||
| 180 | |||
| 181 | return new JsonResponse([ |
||
| 182 | 'response' => [ |
||
| 183 | 'data' => [], |
||
| 184 | 'count' => 0, |
||
| 185 | 'error' => $e->getMessage(), |
||
| 186 | 'success' => false, |
||
| 187 | ], |
||
| 255 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths