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

ActionDisplay   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A display() 0 25 5
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
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
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
}