Failed Conditions
Push — master ( 1a6d63...dcbc0d )
by Adrien
05:26
created

ActivityController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 30 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 12
loc 40
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A indexAction() 0 23 5
A init() 0 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
class ActivityController extends Zend_Controller_Action
4
{
5 3
    public function init(): void
6
    {
7
        // Init the Context Switch Action helper
8 3
        $contextSwitch = $this->_helper->contextSwitch();
9
10
        // Add the new context
11 3
        $contextSwitch->setContexts([
12 3
            'rss' => ['suffix' => 'rss'],
13
        ]);
14
15 3
        $contextSwitch->addActionContext('index', 'rss')->initContext();
16 3
    }
17
18 3
    public function indexAction(): void
19
    {
20
        // By default we show overall activity
21 3
        $item = null;
22 3
        $this->view->title = $this->view->translate('Overall activity');
23
24
        // Try to show user's actitvity
25 3
        if ($this->getRequest()->getParam('user')) {
26 1
            $item = \mQueue\Model\UserMapper::find($this->getRequest()->getParam('user'));
27 1
            if ($item) {
28 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...
29
            }
30
        }
31
32
        // Try to show movie's actitvity
33 3
        if ($this->getRequest()->getParam('movie')) {
34 1
            $item = \mQueue\Model\MovieMapper::find($this->getRequest()->getParam('movie'));
35 1
            if ($item) {
36 1
                $this->view->title = $this->view->translate('Activity for %s', [$item->getTitle()]);
37
            }
38
        }
39
40 3
        $this->view->activity = $this->_helper->createPaginator(\mQueue\Model\StatusMapper::getActivityQuery($item));
41 3
    }
42
}
43