Completed
Pull Request — master (#333)
by Elan
01:50 queued 35s
created

WatchController::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace XHGui\Controller;
4
5
use Slim\App;
6
use Slim\Http\Request;
7
use Slim\Slim as App;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Cannot use Slim\Slim as App because the name is already in use
Loading history...
8
use XHGui\AbstractController;
9
use XHGui\Searcher\SearcherInterface;
10
11
class WatchController extends AbstractController
12
{
13
    /**
14
     * @var SearcherInterface
15
     */
16
    protected $searcher;
17
18
    public function __construct(App $app, SearcherInterface $searcher)
19
    {
20
        parent::__construct($app);
21
        $this->searcher = $searcher;
22
    }
23
24
    public function get()
25
    {
26
        $watched = $this->searcher->getAllWatches();
27
28
        $this->_template = 'watch/list.twig';
29
        $this->set(['watched' => $watched]);
30
    }
31
32
    public function post(Request $request)
33
    {
34
        $saved = false;
35
        foreach ((array)$request->post('watch') as $data) {
36
            $saved = true;
37
            $this->searcher->saveWatch($data);
38
        }
39
        if ($saved) {
40
            $this->app->flash('success', 'Watch functions updated.');
41
        }
42
        $this->app->redirect($this->app->urlFor('watch.list'));
43
    }
44
}
45