Issues (98)

application/controllers/UserController.php (6 issues)

1
<?php
2
3
use mQueue\Form\Login;
4
use mQueue\Model\StatusMapper;
5
use mQueue\Model\User;
6
use mQueue\Model\UserMapper;
7
8
class UserController extends Zend_Controller_Action
9
{
10 3
    public function init(): void
11
    {
12
        // Initialize action controller here
13 3
    }
14
15 1
    public function indexAction(): void
16
    {
17 1
        $this->view->users = UserMapper::fetchAll();
18 1
    }
19
20 2
    public function newAction()
21
    {
22 2
        $request = $this->getRequest();
23 2
        $form = new \mQueue\Form\User();
24
25 2
        if ($this->getRequest()->isPost()) {
0 ignored issues
show
The method isPost() does not exist on Zend_Controller_Request_Abstract. It seems like you code against a sub-type of Zend_Controller_Request_Abstract such as Zend_Controller_Request_Http. ( Ignorable by Annotation )

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

25
        if ($this->getRequest()->/** @scrutinizer ignore-call */ isPost()) {
Loading history...
26 2
            if ($form->isValid($request->getPost())) {
0 ignored issues
show
The method getPost() does not exist on Zend_Controller_Request_Abstract. It seems like you code against a sub-type of Zend_Controller_Request_Abstract such as Zend_Controller_Request_Http. ( Ignorable by Annotation )

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

26
            if ($form->isValid($request->/** @scrutinizer ignore-call */ getPost())) {
Loading history...
27 2
                $values = $form->getValues();
28 2
                $user = UserMapper::insertUser($values);
29
30 2
                User::setCurrent($user);
31
32 2
                $this->_helper->FlashMessenger('Subscription complete.');
33
34 2
                return $this->_helper->redirector('index', 'movie');
35
            }
36
        }
37
38 2
        $this->view->form = $form;
39 2
    }
40
41 1
    public function loginAction()
42
    {
43 1
        $request = $this->getRequest();
44 1
        $form = new Login();
45
46 1
        if ($this->getRequest()->isPost()) {
47 1
            if ($form->isValid($request->getPost())) {
48 1
                $values = $form->getValues();
49
50 1
                $user = UserMapper::findEmailPassword($values['email'], $values['password']);
51 1
                if ($user) {
0 ignored issues
show
$user is of type mQueue\Model\User, thus it always evaluated to true.
Loading history...
52 1
                    User::setCurrent($user);
53
54 1
                    $this->_helper->FlashMessenger('Logged in.');
55
56 1
                    $referrer = $values['referrer'];
57
58
                    // If we have a valid referer to one page of ours (except login or logout), redirect to it
59 1
                    if (mb_strpos($referrer, $this->view->serverUrl() . $this->view->baseUrl()) === 0
60 1
                        && mb_strpos($referrer, $this->view->serverUrl() . $this->view->url(['controller' => 'user', 'action' => 'login'])) !== 0
61 1
                        && mb_strpos($referrer, $this->view->serverUrl() . $this->view->url(['controller' => 'user', 'action' => 'logout'])) !== 0) {
62
                        return $this->redirect($values['referrer']);
0 ignored issues
show
Are you sure the usage of $this->redirect($values['referrer']) targeting Zend_Controller_Action::redirect() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
63
                    }
64
65 1
                    return $this->_helper->redirector('index', 'movie');
66
                }
67
                $this->_helper->FlashMessenger(['error' => 'Login failed.']);
68
            }
69
        } else {
70
            $form->setDefaults([
71
                'referrer' => $this->getRequest()->getServer('HTTP_REFERER'),
0 ignored issues
show
The method getServer() does not exist on Zend_Controller_Request_Abstract. It seems like you code against a sub-type of Zend_Controller_Request_Abstract such as Zend_Controller_Request_Http. ( Ignorable by Annotation )

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

71
                'referrer' => $this->getRequest()->/** @scrutinizer ignore-call */ getServer('HTTP_REFERER'),
Loading history...
72
            ]);
73
        }
74
75
        $this->view->form = $form;
76
    }
77
78 1
    public function logoutAction(): void
79
    {
80 1
        User::setCurrent(null);
81 1
    }
82
83
    public function viewAction(): void
84
    {
85
        if ($this->getRequest()->getParam('id')) {
86
            $this->view->user = UserMapper::find($this->getRequest()->getParam('id'));
87
        } else {
88
            $this->view->user = User::getCurrent();
89
        }
90
91
        if (!$this->view->user) {
0 ignored issues
show
Accessing user on the interface Zend_View_Interface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
92
            throw new Exception($this->view->translate('User not found'));
93
        }
94
95
        $this->view->userActivity = $this->_helper->createPaginator(StatusMapper::getActivityQuery($this->view->user));
96
    }
97
}
98