| Conditions | 13 |
| Paths | 671 |
| Total Lines | 152 |
| Code Lines | 90 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 37 | public function __invoke(): JsonResponse |
||
| 38 | { |
||
| 39 | try { |
||
| 40 | |||
| 41 | $myCompanies = []; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var \ControleOnline\Entity\User |
||
| 45 | */ |
||
| 46 | $currentUser = $this->security->getUser(); |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var \ControleOnline\Entity\People |
||
| 50 | */ |
||
| 51 | $userPeople = $currentUser->getPeople(); |
||
| 52 | $permissions = []; |
||
| 53 | |||
| 54 | |||
| 55 | $getPeopleCompanies = $userPeople->getLink(); |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @var \ControleOnline\Entity\PeopleLink $peopleCompany |
||
| 59 | */ |
||
| 60 | foreach ($getPeopleCompanies as $peopleCompany) { |
||
| 61 | |||
| 62 | $allConfigs = []; |
||
| 63 | $configs = []; |
||
| 64 | $people = $peopleCompany->getCompany(); |
||
| 65 | |||
| 66 | //if ($peopleCompany->getEnabled() && $people->getEnabled()) { |
||
| 67 | |||
| 68 | $domains = $this->getPeopleDomains($people); |
||
| 69 | $packages = $this->getPeoplePackages($people); |
||
| 70 | |||
| 71 | |||
| 72 | $permissions[$people->getId()] = $this->roles->getAllRoles($userPeople); |
||
| 73 | |||
| 74 | $allConfigs = $this->em->getRepository(Config::class)->findBy([ |
||
| 75 | 'people' => $people->getId(), |
||
| 76 | 'visibility' => 'public' |
||
| 77 | ]); |
||
| 78 | foreach ($allConfigs as $config) { |
||
| 79 | $configs[$config->getConfigKey()] = $config->getConfigValue(); |
||
| 80 | } |
||
| 81 | |||
| 82 | $myCompanies[$people->getId()] = [ |
||
| 83 | 'id' => $people->getId(), |
||
| 84 | 'enabled' => $people->getEnabled(), |
||
| 85 | 'alias' => $people->getAlias(), |
||
| 86 | 'logo' => $this->getLogo($people), |
||
| 87 | 'document' => $this->getDocument($people), |
||
| 88 | 'domains' => $domains, |
||
| 89 | 'configs' => $configs, |
||
| 90 | 'packages' => $packages, |
||
| 91 | 'user' => [ |
||
| 92 | 'id' => $userPeople->getId(), |
||
| 93 | 'name' => $userPeople->getName(), |
||
| 94 | 'alias' => $userPeople->getAlias(), |
||
| 95 | 'enabled' => $userPeople->getEnabled(), |
||
| 96 | 'employee_enabled' => $peopleCompany->getEnabled(), |
||
| 97 | 'salesman_enabled' => false |
||
| 98 | ] |
||
| 99 | ]; |
||
| 100 | //} |
||
| 101 | } |
||
| 102 | |||
| 103 | $peopleSalesman = $this->em->getRepository(People::class)->getPeopleLinks($userPeople, 'salesman'); |
||
| 104 | |||
| 105 | foreach ($peopleSalesman as $com) { |
||
| 106 | $company = $this->em->getRepository(People::class)->find($com['people_id']); |
||
| 107 | $allConfigs = []; |
||
| 108 | $configs = []; |
||
| 109 | $allConfigs = $this->em->getRepository(Config::class)->findBy([ |
||
| 110 | 'people' => $company->getId(), |
||
| 111 | 'visibility' => 'public' |
||
| 112 | ]); |
||
| 113 | foreach ($allConfigs as $config) { |
||
| 114 | $configs[$config->getConfigKey()] = $config->getConfigValue(); |
||
| 115 | } |
||
| 116 | |||
| 117 | if ($company) { |
||
| 118 | $people_domains = $this->em->getRepository(PeopleDomain::class)->findBy(['people' => $com['people_id']]); |
||
| 119 | |||
| 120 | $domains = []; |
||
| 121 | |||
| 122 | if (!empty($people_domains)) { |
||
| 123 | |||
| 124 | /** |
||
| 125 | * @var PeopleDomain $company |
||
| 126 | */ |
||
| 127 | foreach ($people_domains as $domain) { |
||
| 128 | |||
| 129 | $domains[] = [ |
||
| 130 | 'id' => $domain->getId(), |
||
| 131 | 'domainType' => $domain->getDomainType(), |
||
| 132 | 'domain' => $domain->getDomain() |
||
| 133 | ]; |
||
| 134 | } |
||
| 135 | } |
||
| 136 | |||
| 137 | $peopleemployee = $this->em->getRepository(PeopleLink::class)->findOneBy(['company' => $company, 'employee' => $userPeople]); |
||
| 138 | |||
| 139 | $permissions[$company->getId()][] = 'salesman'; |
||
| 140 | $myCompanies[$company->getId()] = [ |
||
| 141 | 'id' => $company->getId(), |
||
| 142 | 'enabled' => $company->getEnabled(), |
||
| 143 | 'alias' => $company->getAlias(), |
||
| 144 | 'logo' => $this->getLogo($company), |
||
| 145 | 'document' => $this->getDocument($company), |
||
| 146 | 'commission' => $com['commission'], |
||
| 147 | 'domains' => $domains, |
||
| 148 | 'configs' => $configs, |
||
| 149 | 'user' => [ |
||
| 150 | 'id' => $userPeople->getId(), |
||
| 151 | 'name' => $userPeople->getName(), |
||
| 152 | 'alias' => $userPeople->getAlias(), |
||
| 153 | 'enabled' => $userPeople->getEnabled(), |
||
| 154 | 'employee_enabled' => $peopleemployee ? $peopleemployee->getEnabled() : $com['enable'], |
||
| 155 | 'salesman_enabled' => $com['enable'] |
||
| 156 | ] |
||
| 157 | ]; |
||
| 158 | } |
||
| 159 | } |
||
| 160 | |||
| 161 | foreach ($permissions as $key => $permission) { |
||
| 162 | $myCompanies[$key]['permission'] = array_values($permission); |
||
| 163 | } |
||
| 164 | |||
| 165 | usort($myCompanies, function ($a, $b) { |
||
| 166 | |||
| 167 | if ($a['alias'] == $b['alias']) { |
||
| 168 | return 0; |
||
| 169 | } |
||
| 170 | return ($a['alias'] < $b['alias']) ? -1 : 1; |
||
| 171 | }); |
||
| 172 | |||
| 173 | return new JsonResponse([ |
||
| 174 | 'response' => [ |
||
| 175 | 'data' => $myCompanies, |
||
| 176 | 'count' => count($myCompanies), |
||
| 177 | 'error' => '', |
||
| 178 | 'success' => true, |
||
| 179 | ], |
||
| 180 | ]); |
||
| 181 | } catch (\Exception $e) { |
||
| 182 | |||
| 183 | return new JsonResponse([ |
||
| 184 | 'response' => [ |
||
| 185 | 'data' => [], |
||
| 186 | 'count' => 0, |
||
| 187 | 'error' => $e->getMessage(), |
||
| 188 | 'success' => false, |
||
| 189 | ], |
||
| 269 |
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