Completed
Push — master ( 5cd95a...6f73c5 )
by Oscar
03:28
created

CreateEntity   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 30 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 4
dl 6
loc 20
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A html() 6 17 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Folk\Controllers;
4
5
use Psr\Http\Message\ServerRequestInterface as Request;
6
use Psr\Http\Message\ResponseInterface as Response;
7
use Folk\Admin;
8
use Folk\Entities\EntityInterface;
9
use Zend\Diactoros\Response\RedirectResponse;
10
11
class CreateEntity extends Entity
12
{
13
    public function html(Request $request, Response $response, Admin $app, EntityInterface $entity)
0 ignored issues
show
Unused Code introduced by
The parameter $response is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
14
    {
15
        $form = static::createForm($entity, $app);
16
        $form->loadFromPsr7($request);
17
18 View Code Duplication
        if ($form->isValid()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
            return new RedirectResponse($app->getRoute('read', [
20
                'entity' => $entity->getName(),
21
                'id' => $entity->create($form['data']->val()),
22
            ]));
23
        }
24
25
        return $app['templates']->render('pages/create', [
26
            'entity' => $entity,
27
            'form' => $form,
28
        ]);
29
    }
30
}
31