Passed
Push — master ( fa3542...0a3787 )
by Mihail
05:11
created

ActionDisplay::display()   A

Complexity

Conditions 5
Paths 9

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 15
nc 9
nop 2
dl 0
loc 25
rs 9.4555
c 0
b 0
f 0
1
<?php
2
3
namespace Apps\Controller\Admin\Comments;
4
5
6
use Apps\ActiveRecord\CommentAnswer;
7
use Apps\ActiveRecord\CommentPost;
8
use Ffcms\Core\Arch\View;
9
use Ffcms\Core\Exception\NotFoundException;
10
use Ffcms\Core\Network\Request;
11
use Ffcms\Core\Network\Response;
12
13
/**
14
 * Trait ActionDisplay
15
 * @package Apps\Controller\Admin\Comments
16
 * @property Request $request
17
 * @property Response $response
18
 * @property View $view
19
 */
20
trait ActionDisplay
21
{
22
23
    /**
24
     * Change moderate status in comment/answer and redirect back
25
     * @param string $type
26
     * @param int $id
27
     * @throws NotFoundException
28
     */
29
    public function display($type, $id)
30
    {
31
        /** @var CommentPost|CommentAnswer|null $record */
32
        $record = null;
33
        switch ($type) {
34
            case self::TYPE_COMMENT:
0 ignored issues
show
Bug introduced by zenn
The constant Apps\Controller\Admin\Co...onDisplay::TYPE_COMMENT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
35
                $record = CommentPost::find($id);
36
                break;
37
            case self::TYPE_ANSWER:
0 ignored issues
show
Bug introduced by zenn
The constant Apps\Controller\Admin\Co...ionDisplay::TYPE_ANSWER was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
38
                $record = CommentAnswer::find($id);
39
                break;
40
        }
41
42
        if (!$record) {
43
            throw new NotFoundException('No comments found');
44
        }
45
46
        $record->moderate = !$record->moderate;
47
        $record->save();
48
49
        if ($type === self::TYPE_ANSWER) {
50
            $this->response->redirect('comments/answerlist');
51
        }
52
53
        $this->response->redirect('comments/index');
54
    }
55
}