| Conditions | 11 |
| Paths | 66 |
| Total Lines | 36 |
| Code Lines | 23 |
| 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 |
||
| 29 | public function getEncoder(string $name = 'default') |
||
| 30 | { |
||
| 31 | if (!isset($this->encoders[$name])) { |
||
| 32 | if ($name === 'default') { |
||
| 33 | $config = $this->config; |
||
| 34 | } elseif(isset($this->config['encoders'][$name])) { |
||
| 35 | $config = $this->config['encoders'][$name]; |
||
| 36 | } else { |
||
| 37 | throw new \Exception(sprintf('No configuration found for %s "%s"', Encoder::class, $name)); |
||
| 38 | } |
||
| 39 | |||
| 40 | $encoder_options = isset($config['encoder-options']) && is_array($config['encoder-options']) ? |
||
| 41 | $config['encoder-options'] : |
||
| 42 | []; |
||
| 43 | $options = $this->getEncoderOptions($encoder_options); |
||
| 44 | |||
| 45 | $encoder = Encoder::instance( |
||
| 46 | $this->config['schemas'], |
||
| 47 | $options |
||
| 48 | ); |
||
| 49 | |||
| 50 | if (isset($config['jsonapi'])) { |
||
| 51 | if (is_array($config['jsonapi'])) { |
||
| 52 | $encoder->withJsonApiVersion($config['jsonapi']); |
||
| 53 | } elseif ($config['jsonapi'] === true) { |
||
| 54 | $encoder->withJsonApiVersion(); |
||
| 55 | } |
||
| 56 | } |
||
| 57 | if (isset($config['meta']) && is_array($config['meta'])) { |
||
| 58 | $encoder->withMeta($config['meta']); |
||
| 59 | } |
||
| 60 | |||
| 61 | $this->encoders[$name] = $encoder; |
||
| 62 | } |
||
| 63 | return $this->encoders[$name]; |
||
| 64 | } |
||
| 65 | |||
| 80 |