Xhgui_Controller_Watch   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A get() 0 7 1
A post() 0 13 3
1
<?php
2
3
use Slim\Slim;
4
5
class Xhgui_Controller_Watch extends Xhgui_Controller
6
{
7
    /**
8
     * @var Xhgui_Searcher_Interface
9
     */
10
    protected $searcher;
11
12
    public function __construct(Slim $app, Xhgui_Searcher_Interface $searcher)
13
    {
14
        parent::__construct($app);
15
        $this->searcher = $searcher;
16
    }
17
18
    public function get()
19
    {
20
        $watched = $this->searcher->getAllWatches();
21
22
        $this->_template = 'watch/list.twig';
23
        $this->set(array('watched' => $watched));
24
    }
25
26
    public function post()
27
    {
28
        $saved = false;
29
        $request = $this->app->request();
30
        foreach ((array)$request->post('watch') as $data) {
31
            $saved = true;
32
            $this->searcher->saveWatch($data);
33
        }
34
        if ($saved) {
35
            $this->app->flash('success', 'Watch functions updated.');
36
        }
37
        $this->app->redirect($this->app->urlFor('watch.list'));
38
    }
39
}
40