Conditions | 8 |
Paths | 36 |
Total Lines | 98 |
Code Lines | 58 |
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 |
||
58 | #[Override] |
||
59 | public function getRoutes(string ...$classes): array |
||
60 | { |
||
61 | $routes = []; |
||
62 | $attributes = []; |
||
63 | |||
64 | foreach ($classes as $class) { |
||
65 | /** @var Route[] $memberAttributes */ |
||
66 | $memberAttributes = $this->attributes->forClassMembers($class, Route::class); |
||
67 | |||
68 | // Iterate through all the members' attributes |
||
69 | foreach ($memberAttributes as $routeAttribute) { |
||
70 | $routeDispatch = $routeAttribute->getDispatch(); |
||
71 | |||
72 | $method = $routeDispatch->getMethod(); |
||
73 | $routeParameters = $this->attributes->forMethod($class, $method, Parameter::class); |
||
74 | $routeMiddleware = $this->attributes->forMethod($class, $method, Middleware::class); |
||
75 | $routeRequestStruct = $this->attributes->forMethod($class, $method, RequestStruct::class); |
||
76 | $routeResponseStruct = $this->attributes->forMethod($class, $method, ResponseStruct::class); |
||
77 | $requestMethods = $this->attributes->forMethod($class, $method, RequestMethod::class); |
||
78 | |||
79 | /** @var class-string[] $middlewareClasses */ |
||
80 | $middlewareClasses = array_column( |
||
81 | $routeMiddleware, |
||
82 | 'name' |
||
83 | ); |
||
84 | |||
85 | foreach ($middlewareClasses as $middlewareClass) { |
||
86 | $routeAttribute = match (true) { |
||
87 | is_a($middlewareClass, RouteMatchedMiddleware::class, true) => $routeAttribute->withAddedRouteMatchedMiddleware( |
||
88 | $middlewareClass |
||
89 | ), |
||
90 | is_a($middlewareClass, RouteDispatchedMiddleware::class, true) => $routeAttribute->withAddedRouteDispatchedMiddleware( |
||
91 | $middlewareClass |
||
92 | ), |
||
93 | is_a($middlewareClass, ThrowableCaughtMiddleware::class, true) => $routeAttribute->withAddedThrowableCaughtMiddleware( |
||
94 | $middlewareClass |
||
95 | ), |
||
96 | is_a($middlewareClass, SendingResponseMiddleware::class, true) => $routeAttribute->withAddedSendingResponseMiddleware( |
||
97 | $middlewareClass |
||
98 | ), |
||
99 | is_a($middlewareClass, TerminatedMiddleware::class, true) => $routeAttribute->withAddedTerminatedMiddleware( |
||
100 | $middlewareClass |
||
101 | ), |
||
102 | default => $routeAttribute, |
||
103 | }; |
||
104 | } |
||
105 | |||
106 | foreach ($requestMethods as $requestMethod) { |
||
107 | /** @psalm-suppress MixedArgument Unsure why Psalm doesn't realize that the requestMethods property is an array of RequestMethod enums */ |
||
108 | $routeAttribute = $routeAttribute->withAddedRequestMethods(...$requestMethod->requestMethods); |
||
109 | } |
||
110 | |||
111 | /** @var class-string<RequestStructContract>[] $requestStruct */ |
||
112 | $requestStruct = array_column($routeRequestStruct, 'name'); |
||
113 | |||
114 | if ($requestStruct !== []) { |
||
115 | $routeAttribute = $routeAttribute->withRequestStruct($requestStruct[0]); |
||
116 | } |
||
117 | |||
118 | /** @var class-string<ResponseStructContract>[] $responseStruct */ |
||
119 | $responseStruct = array_column($routeResponseStruct, 'name'); |
||
120 | |||
121 | if ($responseStruct !== []) { |
||
122 | $routeAttribute = $routeAttribute->withResponseStruct($responseStruct[0]); |
||
123 | } |
||
124 | |||
125 | $routeAttribute = $routeAttribute->withParameters( |
||
126 | ...$this->attributes->forMethodParameters($class, $method, Parameter::class), |
||
127 | ...$routeParameters |
||
128 | ); |
||
129 | |||
130 | // And set a new route with the controller defined annotation additions |
||
131 | $attributes[] = $routeAttribute; |
||
132 | } |
||
133 | } |
||
134 | |||
135 | foreach ($attributes as $attribute) { |
||
136 | $attribute = $this->setRouteProperties($attribute); |
||
137 | |||
138 | $routes[] = new \Valkyrja\Http\Routing\Data\Route( |
||
139 | path: $attribute->getPath(), |
||
140 | name: $attribute->getName(), |
||
141 | dispatch: $attribute->getDispatch(), |
||
142 | requestMethods: $attribute->getRequestMethods(), |
||
143 | regex: $attribute->getRegex(), |
||
144 | parameters: $attribute->getParameters(), |
||
145 | routeMatchedMiddleware: $attribute->getRouteMatchedMiddleware(), |
||
146 | routeDispatchedMiddleware: $attribute->getRouteDispatchedMiddleware(), |
||
147 | throwableCaughtMiddleware: $attribute->getThrowableCaughtMiddleware(), |
||
148 | sendingResponseMiddleware: $attribute->getSendingResponseMiddleware(), |
||
149 | terminatedMiddleware: $attribute->getTerminatedMiddleware(), |
||
150 | requestStruct: $attribute->getRequestStruct(), |
||
151 | responseStruct: $attribute->getResponseStruct() |
||
152 | ); |
||
153 | } |
||
154 | |||
155 | return $routes; |
||
156 | } |
||
180 |
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