Test Failed
Push — master ( e3c39f...fe570d )
by Mihail
07:20
created

Apps/Controller/Admin/Feedback/ActionTurn.php (2 issues)

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;
0 ignored issues
show
Documentation Bug introduced by
The property $closed was declared of type boolean, but 0 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
42
                $record->save();
43
                break;
44
            case 'close':
45
                $record->closed = 1;
46
                $record->save();
47
                break;
48
            case 'read':
49
                $record->readed = 1;
0 ignored issues
show
Documentation Bug introduced by
The property $readed was declared of type boolean, but 1 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
50
                $record->save();
51
                break;
52
            default:
53
                throw new NotFoundException(__('Hack attention'));
54
                break;
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