ActivityController::init()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 11
rs 10
ccs 5
cts 5
cp 1
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
use mQueue\Model\MovieMapper;
4
use mQueue\Model\StatusMapper;
5
use mQueue\Model\UserMapper;
6
7
class ActivityController extends Zend_Controller_Action
8
{
9 3
    public function init(): void
10
    {
11
        // Init the Context Switch Action helper
12 3
        $contextSwitch = $this->_helper->contextSwitch();
13
14
        // Add the new context
15 3
        $contextSwitch->setContexts([
16 3
            'rss' => ['suffix' => 'rss'],
17
        ]);
18
19 3
        $contextSwitch->addActionContext('index', 'rss')->initContext();
20 3
    }
21
22 3
    public function indexAction(): void
23
    {
24
        // By default we show overall activity
25 3
        $item = null;
26 3
        $this->view->title = $this->view->translate('Overall activity');
27
28
        // Try to show user's activity
29 3
        if ($this->getRequest()->getParam('user')) {
30 1
            $item = UserMapper::find($this->getRequest()->getParam('user'));
31 1
            if ($item) {
0 ignored issues
show
introduced by
$item is of type mQueue\Model\User, thus it always evaluated to true.
Loading history...
32 1
                $this->view->title = $this->view->translate('Activity for %s', [$item->nickname]);
0 ignored issues
show
Bug Best Practice introduced by
The property nickname does not exist on mQueue\Model\User. Since you implemented __get, consider adding a @property annotation.
Loading history...
33
            }
34
        }
35
36
        // Try to show movie's activity
37 3
        if ($this->getRequest()->getParam('movie')) {
38 1
            $item = MovieMapper::find($this->getRequest()->getParam('movie'));
39 1
            if ($item) {
0 ignored issues
show
introduced by
$item is of type mQueue\Model\Movie, thus it always evaluated to true.
Loading history...
40 1
                $this->view->title = $this->view->translate('Activity for %s', [$item->getTitle()]);
41
            }
42
        }
43
44 3
        $this->view->activity = $this->_helper->createPaginator(StatusMapper::getActivityQuery($item));
45 3
    }
46
}
47