Completed
Push — master ( 7e75f8...53d3fb )
by Ryan
10:44 queued 05:05
created

FormController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 31 6
1
<?php namespace Anomaly\Streams\Platform\Http\Controller;
2
3
use Anomaly\Streams\Platform\Ui\Form\Command\GetFormCriteria;
4
use Anomaly\Streams\Platform\Ui\Form\FormBuilder;
5
use Anomaly\Streams\Platform\Ui\Form\FormCriteria;
6
use Illuminate\Cache\Repository;
7
use Illuminate\Routing\Redirector;
8
9
/**
10
 * Class FormController
11
 *
12
 * @link   http://pyrocms.com/
13
 * @author PyroCMS, Inc. <[email protected]>
14
 * @author Ryan Thompson <[email protected]>
15
 */
16
class FormController extends PublicController
17
{
18
19
    /**
20
     * Handle the form.
21
     *
22
     * @param  Repository                                 $cache
23
     * @param  Redirector                                 $redirect
24
     * @param                                             $key
25
     * @return \Symfony\Component\HttpFoundation\Response
26
     */
27
    public function handle(Repository $cache, Redirector $redirect, $key)
28
    {
29
        $parameters = $cache->get('form::' . $key);
30
31
        /* @var FormCriteria $criteria */
32
        $criteria = $this->dispatch(new GetFormCriteria($parameters));
33
34
        /* @var FormBuilder $builder */
35
        $builder = $criteria->build();
36
37
        $response = $builder
38
            ->build()
39
            ->post()
40
            ->getFormResponse();
41
42
        $builder->flash();
43
44
        if ($response && $response->getStatusCode() !== 200) {
45
            return $response;
46
        }
47
48
        if ($builder->isAjax()) {
49
            return $builder->getFormResponse();
50
        }
51
52
        if ($builder->hasFormErrors()) {
53
            return $redirect->back();
54
        }
55
56
        return $response ?: $redirect->back();
57
    }
58
}
59