Conditions | 6 |
Paths | 32 |
Total Lines | 67 |
Code Lines | 40 |
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 |
||
32 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
||
33 | { |
||
34 | $params = $request->getQueryParams(); |
||
35 | $page = isset($params['page']) ? (int) $params['page'] : 1; |
||
36 | $limit = isset($params['limit']) ? (int) $params['limit'] : 25; |
||
37 | $offset = ($page * $limit) - $limit; |
||
38 | $entityClass = $this->getEntityClass(); |
||
39 | $whereCriteria = $this->getWhereCriteria(); |
||
40 | $orderByCriteria = $this->getWhereCriteria(); |
||
41 | $requestAttributeName = $this->getRequestAttributeName(); |
||
42 | $entities = $this->entityManager->getRepository($entityClass)->findBy($whereCriteria, $orderByCriteria, $limit, $offset); |
||
43 | $totalRecords = $this->entityManager->getRepository($entityClass)->count($whereCriteria); |
||
44 | $totalPages = (int) ceil($totalRecords / $limit); |
||
45 | $uri = $request->getUri(); |
||
46 | |||
47 | $hal = [ |
||
48 | '_links' => [ |
||
49 | 'self' => [ |
||
50 | 'href' => $uri->getScheme() . '://' . $uri->getHost() . $uri->getPath(), |
||
51 | ], |
||
52 | 'first' => [ |
||
53 | 'href' => $uri->getScheme() . '://' . $uri->getHost() . $uri->getPath(), |
||
54 | ], |
||
55 | ], |
||
56 | ]; |
||
57 | |||
58 | if ($page !== 1) { |
||
59 | $hal['_links']['prev'] = [ |
||
60 | 'href' => $uri->getScheme() . '://' . $uri->getHost() . $uri->getPath() . '?page=' . ($page - 1), |
||
61 | ]; |
||
62 | } |
||
63 | |||
64 | if ($page !== $totalPages) { |
||
65 | $hal['_links']['next'] = [ |
||
66 | 'href' => $uri->getScheme() . '://' . $uri->getHost() . $uri->getPath() . '?page=' . ($page + 1), |
||
67 | ]; |
||
68 | } |
||
69 | |||
70 | $hal['_links']['last'] = [ |
||
71 | 'href' => $uri->getScheme() . '://' . $uri->getHost() . $uri->getPath() . '?page=' . $totalPages, |
||
72 | ]; |
||
73 | |||
74 | $hal['_embedded'] = []; |
||
75 | |||
76 | $encoders = [new JsonEncoder()]; |
||
77 | $normalizers = [new ObjectNormalizer()]; |
||
78 | $serializer = new Serializer($normalizers, $encoders); |
||
79 | |||
80 | // foreach ($entities as $entity) { |
||
81 | $hal['_embedded'][] = $serializer->serialize($entities, 'json'); //$entity->toArray(); |
||
82 | // } |
||
83 | |||
84 | $hal['totalPages'] = $totalPages; |
||
85 | $hal['totalRecords'] = $totalRecords; |
||
86 | /** @todo add _self links for entities in collection */ |
||
87 | foreach ($hal['_embedded'] as $key => $value) { |
||
88 | $hal['_embedded'][$key]['_links'] = [ |
||
89 | 'self' => [ |
||
90 | 'href' => $uri->getScheme() . '://' . $uri->getHost() . $uri->getPath() . '/' . $value['id'], |
||
91 | ], |
||
92 | ]; |
||
93 | } |
||
94 | |||
95 | $response = new JsonResponse($hal); |
||
96 | $response = $response->withHeader('Content-Type', 'application/hal+json'); |
||
97 | |||
98 | return $response; |
||
99 | } |
||
101 |
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