Passed
Push — master ( c57047...e9f946 )
by Mihail
06:06
created

ActionImportantChange   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 22
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A important() 0 14 3
1
<?php
2
3
namespace Apps\Controller\Admin\Content;
4
5
use Ffcms\Core\Arch\View;
6
use Ffcms\Core\Exception\NotFoundException;
7
use Ffcms\Core\Network\Request;
8
use Ffcms\Core\Network\Response;
9
10
/**
11
 * Trait ActionImportantChange
12
 * @package Apps\Controller\Admin\Content
13
 * @property Request $request
14
 * @property Response $response
15
 * @property View $view
16
 */
17
trait ActionImportantChange
18
{
19
20
    /**
21
     * Change content important status from user request
22
     * @param string $id
23
     * @throws NotFoundException
24
     */
25
    public function important(string $id): void
26
    {
27
        $status = (bool)$this->request->query->get('status', 0);
28
        $content = \Apps\ActiveRecord\Content::find($id);
29
        if (!$content) {
30
            throw new NotFoundException(__('Content {%id%} are not exist', ['id' => $id]));
31
        }
32
33
        if ((bool)$content->important !== $status) {
34
            $content->important = $status;
35
            $content->save();
36
        }
37
38
        $this->response->redirect('content/index');
39
    }
40
}