WatchController::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace XHGui\Controller;
4
5
use Slim\Http\Request;
6
use Slim\Slim as App;
7
use XHGui\AbstractController;
8
use XHGui\Searcher\SearcherInterface;
9
10
class WatchController extends AbstractController
11
{
12
    /**
13
     * @var SearcherInterface
14
     */
15
    protected $searcher;
16
17
    public function __construct(App $app, SearcherInterface $searcher)
18
    {
19
        parent::__construct($app);
20
        $this->searcher = $searcher;
21
    }
22
23
    public function get(): void
24
    {
25
        $watched = $this->searcher->getAllWatches();
26
27
        $this->render('watch/list.twig', ['watched' => $watched]);
28
    }
29
30
    public function post(Request $request): void
31
    {
32
        $saved = false;
33
        foreach ((array)$request->post('watch') as $data) {
34
            $saved = true;
35
            $this->searcher->saveWatch($data);
36
        }
37
        if ($saved) {
38
            $this->app->flash('success', 'Watch functions updated.');
39
        }
40
        $this->app->redirect($this->app->urlFor('watch.list'));
41
    }
42
}
43