Passed
Push — master ( 81f334...c86e8c )
by Mihail
03:35
created

ActionTurn   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 7

1 Method

Rating   Name   Duplication   Size   Complexity  
C turn() 0 36 7
1
<?php
2
3
namespace Apps\Controller\Admin\Feedback;
4
5
use Apps\ActiveRecord\FeedbackPost;
6
use Ffcms\Core\App;
7
use Ffcms\Core\Exception\NotFoundException;
8
use Ffcms\Core\Helper\Type\Any;
9
use Ffcms\Core\Network\Request;
10
use Ffcms\Core\Network\Response;
11
12
/**
13
 * Trait ActionTurn
14
 * @package Apps\Controller\Admin\Feedback
15
 * @property Request $request
16
 * @property Response $response
17
 */
18
trait ActionTurn
19
{
20
    /**
21
     * Turn feedback request post - close, open, readed
22
     * @param string $direction
23
     * @param string $id
24
     * @return void
25
     * @throws NotFoundException
26
     */
27
    public function turn(string $direction, string $id): void
28
    {
29
        if (!Any::isInt($id) || $id < 1) {
30
            throw new NotFoundException('Bad is format');
31
        }
32
        // try to find record
33
        $record = FeedbackPost::find($id);
34
        if (!$record) {
35
            throw new NotFoundException(__('Feedback request with id %id% is not found', ['id' => $id]));
36
        }
37
38
        // switch operation direction to what we must change
39
        switch ($direction) {
40
            case 'open':
41
                $record->closed = 0;
42
                $record->save();
43
                break;
44
            case 'close':
45
                $record->closed = 1;
46
                $record->save();
47
                break;
48
            case 'read':
49
                $record->readed = 1;
50
                $record->save();
51
                break;
52
            default:
53
                throw new NotFoundException(__('Hack attention'));
54
                break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
55
        }
56
57
        // add notification of successful changes
58
        App::$Session->getFlashBag()->add('success', __('Feedback request is changed!'));
59
60
        // redirect to feedback post read
61
        $this->response->redirect('feedback/read/' . $id);
62
    }
63
}
64