Completed
Push — master ( cc3347...ae7860 )
by Adrien
01:57
created

UserController   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 90
Duplicated Lines 15.56 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 71.43%

Importance

Changes 0
Metric Value
dl 14
loc 90
ccs 35
cts 49
cp 0.7143
rs 10
c 0
b 0
f 0
wmc 16
lcom 1
cbo 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A indexAction() 0 4 1
A newAction() 0 20 3
B loginAction() 0 36 7
A logoutAction() 0 4 1
A viewAction() 14 14 3

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 UserController extends Zend_Controller_Action
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5 3
    public function init(): void
6
    {
7
        // Initialize action controller here
8 3
    }
9
10 1
    public function indexAction(): void
11
    {
12 1
        $this->view->users = \mQueue\Model\UserMapper::fetchAll();
13 1
    }
14
15 2
    public function newAction()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
16
    {
17 2
        $request = $this->getRequest();
18 2
        $form = new \mQueue\Form\User();
19
20 2
        if ($this->getRequest()->isPost()) {
21 2
            if ($form->isValid($request->getPost())) {
22 2
                $values = $form->getValues();
23 2
                $user = \mQueue\Model\UserMapper::insertUser($values);
24
25 2
                \mQueue\Model\User::setCurrent($user);
26
27 2
                $this->_helper->FlashMessenger('Subscription complete.');
28
29 2
                return $this->_helper->redirector('index', 'movie');
30
            }
31
        }
32
33 2
        $this->view->form = $form;
34 2
    }
35
36 1
    public function loginAction()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
37
    {
38 1
        $request = $this->getRequest();
39 1
        $form = new \mQueue\Form\Login();
40
41 1
        if ($this->getRequest()->isPost()) {
42 1
            if ($form->isValid($request->getPost())) {
43 1
                $values = $form->getValues();
44
45 1
                $user = \mQueue\Model\UserMapper::findEmailPassword($values['email'], $values['password']);
46 1
                if ($user) {
47 1
                    \mQueue\Model\User::setCurrent($user);
48
49 1
                    $this->_helper->FlashMessenger('Logged in.');
50
51 1
                    $referrer = $values['referrer'];
52
53
                    // If we have a valid referer to one page of ourselve (except login or logout), redirect to it
54 1
                    if (mb_strpos($referrer, $this->view->serverUrl() . $this->view->baseUrl()) === 0
55 1
                            && mb_strpos($referrer, $this->view->serverUrl() . $this->view->url(['controller' => 'user', 'action' => 'login'])) !== 0
56 1
                            && mb_strpos($referrer, $this->view->serverUrl() . $this->view->url(['controller' => 'user', 'action' => 'logout'])) !== 0) {
57
                        return $this->_redirect($values['referrer']);
0 ignored issues
show
Deprecated Code introduced by
The method Zend_Controller_Action::_redirect() has been deprecated with message: Deprecated as of Zend Framework 1.7. Use redirect() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
58
                    }
59
60 1
                    return $this->_helper->redirector('index', 'movie');
61
                }
62
                $this->_helper->FlashMessenger(['error' => 'Login failed.']);
63
            }
64
        } else {
65
            $form->setDefaults([
66
                'referrer' => $this->getRequest()->getServer('HTTP_REFERER'),
67
            ]);
68
        }
69
70
        $this->view->form = $form;
71
    }
72
73 1
    public function logoutAction(): void
74
    {
75 1
        \mQueue\Model\User::setCurrent(null);
76 1
    }
77
78 View Code Duplication
    public function viewAction(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
79
    {
80
        if ($this->getRequest()->getParam('id')) {
81
            $this->view->user = \mQueue\Model\UserMapper::find($this->getRequest()->getParam('id'));
82
        } else {
83
            $this->view->user = \mQueue\Model\User::getCurrent();
84
        }
85
86
        if (!$this->view->user) {
87
            throw new Exception($this->view->translate('User not found'));
88
        }
89
90
        $this->view->userActivity = $this->_helper->createPaginator(\mQueue\Model\StatusMapper::getActivityQuery($this->view->user));
91
    }
92
}
93