| Conditions | 11 |
| Paths | 24 |
| Total Lines | 46 |
| Code Lines | 30 |
| 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); |
||
| 53 | /** |
||
| 54 | * @return string |
||
| 55 | */ |
||
| 56 | public function getId(): string |
||
| 57 | { |
||
| 58 | return "$this->path::$this->method"; |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @return int[] |
||
| 63 | */ |
||
| 64 | public function getStatusCodes(): array |
||
| 65 | { |
||
| 66 | return array_keys($this->responses); |
||
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @param int $code |
||
| 71 | * |
||
| 72 | * @return Response |
||
| 73 | */ |
||
| 74 | public function getResponse(int $code): Response |
||
| 75 | { |
||
| 76 | if (!isset($this->responses[$code])) { |
||
| 77 | if (isset($this->responses[0])) { |
||
| 78 | // Return default response |
||
| 79 | return $this->responses[0]; |
||
| 80 | } |
||
| 81 | throw new \InvalidArgumentException( |
||
| 82 | "Operation '{$this->getId()}' does not have a definition for status '$code'" . |
||
| 83 | " (has " . implode(', ', array_keys($this->responses)) . ')' |
||
| 84 | ); |
||
| 85 | } |
||
| 86 | |||
| 87 | return $this->responses[$code]; |
||
| 88 | } |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @return Response[] |
||
| 92 | */ |
||
| 93 | public function getResponses() |
||
| 94 | { |
||
| 95 | return array_values($this->responses); |
||
| 96 | } |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @return Schema |
||
| 145 |