Completed
Push — master ( 5488c0...facaaa )
by Oscar
03:24
created

UpdateEntityField   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 5
dl 0
loc 21
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A html() 0 18 2
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 Zend\Diactoros\Response\RedirectResponse;
9
10
class UpdateEntityField extends Entity
11
{
12
    public function html(Request $request, Response $response, Admin $app, $entityName)
13
    {
14
        $id = $request->getAttribute('id');
15
        $field = $request->getAttribute('field');
16
        $data = $request->getParsedBody();
17
18
        $form = static::createForm($app, $entityName, $id);
19
        $form['data']->val($app->getEntity($entityName)->read($id));
20
        $form['data'][$field]->val($data['value']);
21
22
        if ($form->validate()) {
23
            $app->getEntity($entityName)->update($id, $form['data']->val());
24
            
25
            return $data['value'];
26
        }
27
28
        return $response->withStatus(400);
29
    }
30
}
31