Conditions | 11 |
Paths | 24 |
Total Lines | 46 |
Code Lines | 30 |
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 declare(strict_types = 1); |
||
27 | public function __construct(\stdClass $definition, string $path, string $method, array $pathParameters = []) |
||
28 | { |
||
29 | $this->path = $path; |
||
30 | $this->method = $method; |
||
31 | $this->parameters = $pathParameters; |
||
32 | |||
33 | if (isset($definition->parameters)) { |
||
34 | foreach ($definition->parameters as $parameterDefinition) { |
||
35 | $this->parameters[] = new OpenApiParameter($parameterDefinition); |
||
36 | } |
||
37 | } |
||
38 | |||
39 | if (isset($definition->responses)) { |
||
40 | $hasOkResponse = false; |
||
41 | foreach ($definition->responses as $code => $responseDefinition) { |
||
42 | $code = (string)$code; |
||
43 | if ($code === 'default' || substr((string)$code, 1) === '1') { |
||
44 | $hasOkResponse = true; |
||
45 | } |
||
46 | $code = (int)$code; |
||
47 | $this->responses[$code] = new OpenApiResponse($code, $responseDefinition); |
||
48 | } |
||
49 | if (!$hasOkResponse) { |
||
50 | $this->responses[200] = new OpenApiResponse(200, (object)[]); |
||
51 | } |
||
52 | } |
||
53 | |||
54 | $schemaDefinition = (object)[]; |
||
55 | if (!isset($definition->parameters)) { |
||
56 | $schemaDefinition->type = 'null'; |
||
57 | $this->requestSchema = Schema::get($schemaDefinition); |
||
58 | } else { |
||
59 | $schemaDefinition->type = 'object'; |
||
60 | $schemaDefinition->required = []; |
||
61 | $schemaDefinition->properties = (object)[]; |
||
62 | |||
63 | foreach ($this->parameters as $parameter) { |
||
64 | if ($parameter->isRequired()) { |
||
65 | $schemaDefinition->required[] = $parameter->getName(); |
||
66 | } |
||
67 | $schemaDefinition->properties->{$parameter->getName()} = $parameter->getSchema()->getDefinition(); |
||
68 | } |
||
69 | |||
70 | $this->requestSchema = Schema::get($schemaDefinition); |
||
71 | } |
||
72 | } |
||
73 | } |
||
74 |