| Conditions | 13 |
| Paths | 162 |
| Total Lines | 76 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 2 | 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 |
||
| 17 | $entity = $app->getEntity($request->getAttribute('entity')); |
||
| 18 | |||
| 19 | if ($entity !== null && method_exists($this, $format)) { |
||
| 20 | return $this->$format($request, $response, $app, $entity); |
||
| 21 | } |
||
| 22 | |||
| 23 | return $response->withStatus(404); |
||
| 24 | } |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Helper to build the entity form. |
||
| 28 | * |
||
| 29 | * @param EntityInterface $entity |
||
| 30 | * @param Admin $app |
||
| 31 | * @param mixed|null $id |
||
| 32 | * |
||
| 33 | * return \Folk\Formats\Form |
||
| 34 | */ |
||
| 35 | protected static function createForm(EntityInterface $entity, Admin $app, $id = null) |
||
| 36 | { |
||
| 37 | $form = F::form() |
||
| 38 | ->method('post') |
||
| 39 | ->enctype('multipart/form-data') |
||
| 40 | ->add([ |
||
| 41 | 'entity' => F::hidden()->val($entity->getName())->class('field-data-entity'), |
||
| 42 | 'data' => $entity->getScheme($app['builder']), |
||
| 43 | ]); |
||
| 44 | |||
| 45 | if ($id !== null) { |
||
| 46 | $form['id'] = F::hidden()->val($id)->class('field-data-id'); |
||
| 47 | } |
||
| 48 | |||
| 49 | return $form; |
||
| 50 | } |
||
| 51 | } |
||
| 52 |