StatusController::listAction()   A
last analyzed

Complexity

Conditions 5
Paths 12

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 15
c 2
b 0
f 0
dl 0
loc 25
rs 9.4555
ccs 0
cts 16
cp 0
cc 5
nc 12
nop 0
crap 30
1
<?php
2
3
use mQueue\Model\Movie;
4
use mQueue\Model\MovieMapper;
5
use mQueue\Model\StatusMapper;
6
use mQueue\Model\User;
7
use mQueue\Model\UserMapper;
8
9
class StatusController extends Zend_Controller_Action
10
{
11 1
    public function init(): void
12
    {
13 1
        $contextSwitch = $this->_helper->getHelper('contextSwitch');
14 1
        $contextSwitch->addActionContext('list', 'json')
0 ignored issues
show
Bug introduced by
The method addActionContext() does not exist on Zend_Controller_Action_Helper_Abstract. It seems like you code against a sub-type of Zend_Controller_Action_Helper_Abstract such as Zend_Controller_Action_Helper_Cache or Zend_Controller_Action_Helper_ContextSwitch or Zend_Controller_Action_Helper_Redirector or Zend_Layout_Controller_Action_Helper_Layout. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

14
        $contextSwitch->/** @scrutinizer ignore-call */ 
15
                        addActionContext('list', 'json')
Loading history...
15 1
            ->addActionContext('index', 'json')
16 1
            ->initContext();
17 1
    }
18
19 1
    public function indexAction(): void
20
    {
21 1
        $jsonCallback = $this->_request->getParam('jsoncallback');
22 1
        if ($jsonCallback) {
23
            $this->_helper->layout->setLayout('jsonp');
0 ignored issues
show
Bug introduced by
The method setLayout() does not exist on Zend_Controller_Action_Helper_Abstract. It seems like you code against a sub-type of Zend_Controller_Action_Helper_Abstract such as Zend_Controller_Action_Helper_Cache or Zend_Controller_Action_Helper_Redirector or Zend_Layout_Controller_Action_Helper_Layout. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
            $this->_helper->layout->/** @scrutinizer ignore-call */ 
24
                                    setLayout('jsonp');
Loading history...
24
            $this->view->jsonCallback = $jsonCallback;
25
        }
26
27 1
        $idMovie = Movie::extractId($this->_request->getParam('movie'));
28
29 1
        if ($idMovie == null) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $idMovie of type null|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
30 1
            throw new Exception('no valid movie specified.');
31
        }
32
33
        // If new rating is specified and we are logged in, save it and create movie if needed
34 1
        $rating = $this->_request->getParam('rating');
35 1
        if (isset($rating) && User::getCurrent()) {
36
            $movie = MovieMapper::find($idMovie);
0 ignored issues
show
Bug introduced by
$idMovie of type string is incompatible with the type integer expected by parameter $id of mQueue\Model\MovieMapper::find(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

36
            $movie = MovieMapper::find(/** @scrutinizer ignore-type */ $idMovie);
Loading history...
37
38
            if ($movie == null) {
39
                $movie = MovieMapper::getDbTable()->createRow();
40
                $movie->setId($idMovie);
41
                $movie->save();
42
            }
43
            $status = $movie->setStatus(User::getCurrent(), $rating);
44
        } else {
45 1
            $status = StatusMapper::find($idMovie, User::getCurrent());
0 ignored issues
show
Bug introduced by
$idMovie of type string is incompatible with the type integer expected by parameter $idMovie of mQueue\Model\StatusMapper::find(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

45
            $status = StatusMapper::find(/** @scrutinizer ignore-type */ $idMovie, User::getCurrent());
Loading history...
46
        }
47
48 1
        if (!$jsonCallback) {
49 1
            $this->view->status = $status;
50
        } else {
51
            $html = $this->view->statusLinks($status);
52
            $this->view->status = $html;
53
            $this->view->id = $status->getUniqueId();
0 ignored issues
show
Bug introduced by
The method getUniqueId() does not exist on Zend_Db_Table_Rowset_Abstract. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
            /** @scrutinizer ignore-call */ 
54
            $this->view->id = $status->getUniqueId();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
54
        }
55 1
    }
56
57
    public function listAction(): void
58
    {
59
        $jsonCallback = $this->_request->getParam('jsoncallback');
60
        if ($jsonCallback) {
61
            $this->_helper->layout->setLayout('jsonp');
62
            $this->view->jsonCallback = $jsonCallback;
63
        }
64
65
        $idMovies = [];
66
        foreach (explode(',', trim($this->_request->getParam('movies'), ',')) as $idMovie) {
0 ignored issues
show
Bug introduced by
It seems like $this->_request->getParam('movies') can also be of type null; however, parameter $string of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

66
        foreach (explode(',', trim(/** @scrutinizer ignore-type */ $this->_request->getParam('movies'), ',')) as $idMovie) {
Loading history...
67
            $idMovie = Movie::extractId($idMovie);
68
            if ($idMovie) {
69
                $idMovies[] = $idMovie;
70
            }
71
        }
72
73
        $statuses = StatusMapper::findAll($idMovies, User::getCurrent());
74
75
        $json = [];
76
        foreach ($statuses as $s) {
77
            $html = $this->view->statusLinks($s);
78
            $json[$s->getUniqueId()] = $html;
79
        }
80
81
        $this->view->status = $json;
82
    }
83
84
    public function graphAction(): void
85
    {
86
        $percent = $this->_request->getParam('percent');
87
        $user = UserMapper::find($this->getParam('user'));
88
        $data = StatusMapper::getGraph($user, $percent);
89
        $chart = [
90
            'chart' => [
91
                'zoomType' => 'x',
92
            ],
93
            'title' => [
94
                'text' => '',
95
            ],
96
            'xAxis' => [
97
                'type' => 'datetime',
98
            ],
99
            'yAxis' => [
100
                'title' => [
101
                    'text' => 'Movies',
102
                ],
103
                'min' => 0,
104
            ],
105
            'series' => $data,
106
        ];
107
108
        if ($percent) {
109
            $chart['chart']['type'] = 'area';
110
            $chart['yAxis']['title']['text'] = $chart['yAxis']['title']['text'] . ' [%]';
111
            $chart['plotOptions'] = [
112
                'area' => [
113
                    'stacking' => 'percent',
114
                    'marker' => [
115
                        'enabled' => false,
116
                    ],
117
                ],
118
            ];
119
        }
120
121
        echo Zend_Json::encode($chart, Zend_Json::TYPE_ARRAY);
0 ignored issues
show
Bug introduced by
Zend_Json::TYPE_ARRAY of type integer is incompatible with the type boolean expected by parameter $cycleCheck of Zend_Json::encode(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

121
        echo Zend_Json::encode($chart, /** @scrutinizer ignore-type */ Zend_Json::TYPE_ARRAY);
Loading history...
122
        die();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
123
    }
124
}
125