Conditions | 11 |
Paths | 29 |
Total Lines | 46 |
Code Lines | 24 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 declare(strict_types = 1); |
||
52 | public function process(ServerRequestInterface $request, DelegateInterface $delegate) |
||
53 | { |
||
54 | $uriPath = $request->getUri()->getPath(); |
||
55 | |||
56 | /** @var Description $description */ |
||
57 | foreach ($this->repository as $description) { |
||
58 | |||
59 | $basePath = $description->getBasePath() ? "{$description->getBasePath()}/" : ""; |
||
60 | |||
61 | foreach ($description->getPaths() as $path) { |
||
62 | $pathPattern = "$basePath{$path->getPath()}"; |
||
63 | |||
64 | $parameterNames = []; |
||
65 | foreach ($path->getOperations() as $operation) { |
||
66 | foreach ($operation->getParameters() as $parameter) { |
||
67 | if ($parameter->getIn() === Parameter::IN_PATH |
||
68 | && ($schema = $parameter->getSchema()) instanceof ScalarSchema |
||
69 | ) { |
||
70 | $parameterName = $parameter->getName(); |
||
71 | $parameterNames[] = $parameterName; |
||
72 | $typePattern = $this->typePatternResolver->resolve($schema); |
||
73 | $parameterPattern = "(?P<$parameterName>$typePattern)(?=(/|$))"; |
||
74 | $pathPattern = str_replace('{'.$parameterName.'}', $parameterPattern, $pathPattern); |
||
75 | } |
||
76 | } |
||
77 | |||
78 | if (preg_match("#^$pathPattern$#", $uriPath, $matches) > 0) { |
||
79 | if (strtolower($request->getMethod()) !== $operation->getMethod()) { |
||
80 | return Factory::createResponse(405); |
||
81 | } |
||
82 | |||
83 | $request = Meta::requestWith($request, $description, $operation, $path); |
||
84 | |||
85 | foreach ($parameterNames as $parameterName) { |
||
86 | $request = $request->withAttribute($parameterName, $matches[$parameterName]); |
||
87 | } |
||
88 | |||
89 | return $delegate->process($request); |
||
90 | } |
||
91 | } |
||
92 | |||
93 | } |
||
94 | } |
||
95 | |||
96 | return Factory::createResponse(404); |
||
97 | } |
||
98 | } |