1 | <?php |
||||||
2 | |||||||
3 | namespace ControleOnline\Controller; |
||||||
4 | |||||||
5 | use ControleOnline\Entity\Menu; |
||||||
6 | use ControleOnline\Entity\People; |
||||||
0 ignored issues
–
show
|
|||||||
7 | use Symfony\Component\HttpFoundation\Request; |
||||||
0 ignored issues
–
show
The type
Symfony\Component\HttpFoundation\Request was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||||
8 | use Doctrine\ORM\EntityManagerInterface; |
||||||
0 ignored issues
–
show
The type
Doctrine\ORM\EntityManagerInterface was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||||
9 | use Exception; |
||||||
10 | use Symfony\Component\HttpFoundation\JsonResponse; |
||||||
0 ignored issues
–
show
The type
Symfony\Component\HttpFoundation\JsonResponse was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||||
11 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface |
||||||
0 ignored issues
–
show
The type
Symfony\Component\Securi...e\TokenStorageInterface was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||||
12 | as Security; |
||||||
13 | use ControleOnline\Repository\MenuRepository; |
||||||
14 | |||||||
15 | |||||||
16 | class GetMenuByPeopleAction |
||||||
17 | { |
||||||
18 | /** |
||||||
19 | * Entity Manager |
||||||
20 | * |
||||||
21 | * @var EntityManagerInterface |
||||||
22 | */ |
||||||
23 | private $manager = null; |
||||||
24 | |||||||
25 | /** |
||||||
26 | * Request |
||||||
27 | * |
||||||
28 | * @var Request |
||||||
29 | */ |
||||||
30 | private $request = null; |
||||||
0 ignored issues
–
show
|
|||||||
31 | |||||||
32 | /** |
||||||
33 | * Security |
||||||
34 | * |
||||||
35 | * @var Security |
||||||
36 | */ |
||||||
37 | private $security = null; |
||||||
38 | |||||||
39 | /** |
||||||
40 | * @var \ControleOnline\Repository\MenuRepository |
||||||
41 | */ |
||||||
42 | private $repository = null; |
||||||
43 | |||||||
44 | |||||||
45 | public function __construct(Security $security, EntityManagerInterface $entityManager) |
||||||
46 | { |
||||||
47 | $this->manager = $entityManager; |
||||||
48 | $this->security = $security; |
||||||
49 | $this->repository = $this->manager->getRepository(Menu::class); |
||||||
50 | } |
||||||
51 | |||||||
52 | public function __invoke(Request $request): JsonResponse |
||||||
53 | { |
||||||
54 | try { |
||||||
55 | |||||||
56 | $menu = []; |
||||||
0 ignored issues
–
show
|
|||||||
57 | |||||||
58 | $company = $request->query->get('myCompany', null); |
||||||
59 | |||||||
60 | if ($company === null) |
||||||
61 | throw new Exception("Company not found", 404); |
||||||
62 | |||||||
63 | |||||||
64 | $myCompany = $this->manager->getRepository(People::class) |
||||||
65 | ->find($company); |
||||||
66 | |||||||
67 | if ($myCompany === null) |
||||||
68 | throw new Exception("Company not found", 404); |
||||||
69 | |||||||
70 | |||||||
71 | |||||||
72 | $currentUser = $this->security->getToken()->getUser(); |
||||||
73 | /** |
||||||
74 | * @var People |
||||||
75 | */ |
||||||
76 | $userPeople = $currentUser->getPeople(); |
||||||
77 | |||||||
78 | $menu = $this->getMenuByPeople($userPeople, $myCompany); |
||||||
79 | |||||||
80 | |||||||
81 | return new JsonResponse([ |
||||||
82 | 'response' => [ |
||||||
83 | 'data' => $menu, |
||||||
84 | 'count' => 1, |
||||||
85 | 'error' => '', |
||||||
86 | 'success' => true, |
||||||
87 | ], |
||||||
88 | ]); |
||||||
89 | } catch (\Exception $e) { |
||||||
90 | |||||||
91 | return new JsonResponse([ |
||||||
92 | 'response' => [ |
||||||
93 | 'data' => [], |
||||||
94 | 'count' => 0, |
||||||
95 | 'error' => $e->getMessage(), |
||||||
96 | 'success' => false, |
||||||
97 | ], |
||||||
98 | ]); |
||||||
99 | } |
||||||
100 | } |
||||||
101 | |||||||
102 | private function getMenuByPeople(People $userPeople, People $myCompany) |
||||||
0 ignored issues
–
show
The parameter
$userPeople is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() The parameter
$myCompany is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||||
103 | { |
||||||
104 | |||||||
105 | $return = []; |
||||||
106 | $connection = $this->manager->getConnection(); |
||||||
107 | |||||||
108 | // build query |
||||||
109 | |||||||
110 | $sql = 'SELECT menu.*, |
||||||
111 | category.name AS category_label, |
||||||
112 | category.color AS category_color, |
||||||
113 | routes.route AS route, |
||||||
114 | routes.color AS color, |
||||||
115 | routes.icon AS icon, |
||||||
116 | routes.module_id AS module, |
||||||
117 | category.icon AS category_icon FROM menu |
||||||
118 | INNER JOIN category ON category.id = menu.category_id |
||||||
119 | INNER JOIN menu_role ON menu.id = menu_role.menu_id |
||||||
120 | INNER JOIN people_role ON people_role.role_id = menu_role.role_id |
||||||
121 | INNER JOIN routes ON routes.id = menu.route_id '; |
||||||
122 | //$sql .= 'WHERE people_role.company_id=:myCompany AND people_role.people_id=:userPeople '; |
||||||
123 | $sql .= 'GROUP BY menu.id'; |
||||||
124 | |||||||
125 | |||||||
126 | $params = []; |
||||||
127 | |||||||
128 | //$params['myCompany'] = $myCompany->getId(); |
||||||
129 | //$params['userPeople'] = $userPeople->getId(); |
||||||
130 | // execute query |
||||||
131 | |||||||
132 | $result = $connection->executeQuery($sql, $params)->fetchAllAssociative(); |
||||||
133 | |||||||
134 | foreach ($result as $menu) { |
||||||
135 | |||||||
136 | $return['modules'][$menu['category_id']]['id'] = $menu['category_id']; |
||||||
137 | $return['modules'][$menu['category_id']]['label'] = $menu['category_label']; |
||||||
138 | $return['modules'][$menu['category_id']]['color'] = $menu['category_color']; |
||||||
139 | $return['modules'][$menu['category_id']]['icon'] = $menu['category_icon']; |
||||||
140 | $return['modules'][$menu['category_id']]['menus'][] = [ |
||||||
141 | 'id' => $menu['id'], |
||||||
142 | 'label' => $menu['menu'], |
||||||
143 | 'icon' => $menu['icon'], |
||||||
144 | 'color' => $menu['color'], |
||||||
145 | 'route' => $menu['route'], |
||||||
146 | 'module' => '/modules/' . $menu['module'], |
||||||
147 | ]; |
||||||
148 | } |
||||||
149 | |||||||
150 | |||||||
151 | |||||||
152 | return $return; |
||||||
153 | } |
||||||
154 | } |
||||||
155 |
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