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

UpdateEntity::html()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 13

Duplication

Lines 8
Ratio 34.78 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 8
loc 23
rs 9.0856
cc 2
eloc 13
nc 2
nop 4
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 UpdateEntity 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
        $id = $request->getAttribute('id');
16
17
        $form = static::createForm($entity, $app, $id);
18
        $form->loadFromPsr7($request);
19
20 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...
21
            $entity->update($id, $form['data']->val());
22
23
            return new RedirectResponse($app->getRoute('read', [
24
                'entity' => $entity->getName(),
25
                'id' => $id,
26
            ]));
27
        }
28
29
        //Render template
30
        return $app['templates']->render('pages/edit', [
31
            'entity' => $entity,
32
            'form' => $form,
33
            'id' => $id,
34
        ]);
35
    }
36
}
37