Issues (294)

src/EBloodBank/Controllers/ViewUsers.php (1 issue)

Severity
1
<?php
2
/**
3
 * View users page controller class file
4
 *
5
 * @package    EBloodBank
6
 * @subpackage Controllers
7
 * @since      1.0
8
 */
9
namespace EBloodBank\Controllers;
10
11
use EBloodBank\Options;
12
13
/**
14
 * View users page controller class
15
 *
16
 * @since 1.0
17
 */
18
class ViewUsers extends Controller
19
{
20
    /**
21
     * @return void
22
     * @since 1.0
23
     */
24
    public function __invoke()
25
    {
26
        if (! $this->hasAuthenticatedUser() || ! $this->getAcl()->isUserAllowed($this->getAuthenticatedUser(), 'User', 'read')) {
27
            $this->viewFactory->displayView('error-403');
28
        } else {
29
            $this->viewFactory->displayView('view-users', [
30
                'users'              => $this->getQueriedUsers(),
31
                'pagination.total'   => $this->getPagesTotal(),
32
                'pagination.current' => $this->getCurrentPage(),
33
            ]);
34
        }
35
    }
36
37
    /**
38
     * @return int
39
     * @since 1.0
40
     */
41
    public function getPagesTotal()
42
    {
43
        $total = 1;
44
        $limit = (int) Options::getOption('entities_per_page');
45
        if ($limit >= 1) {
46
            $total = (int) ceil($this->countAllUsers() / $limit);
47
        }
48
        return $total;
49
    }
50
51
    /**
52
     * @return int
53
     * @since 1.0
54
     */
55
    public function getCurrentPage()
56
    {
57
        return max((int) filter_input(INPUT_GET, 'page'), 1);
58
    }
59
60
    /**
61
     * @return \EBloodBank\Models\User[]
62
     * @since 1.0
63
     */
64
    public function getAllUsers()
65
    {
66
        return $this->getUserRepository()->findAll([], ['created_at' => 'DESC']);
0 ignored issues
show
The call to Doctrine\ORM\EntityRepository::findAll() has too many arguments starting with array(). ( Ignorable by Annotation )

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

66
        return $this->getUserRepository()->/** @scrutinizer ignore-call */ findAll([], ['created_at' => 'DESC']);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
67
    }
68
69
    /**
70
     * @return int
71
     * @since 1.0
72
     */
73
    public function countAllUsers()
74
    {
75
        return $this->getUserRepository()->countAll();
76
    }
77
78
    /**
79
     * @return \EBloodBank\Models\User[]
80
     * @since 1.0
81
     */
82
    public function getQueriedUsers()
83
    {
84
        $limit = (int) Options::getOption('entities_per_page');
85
        $offset = ($this->getCurrentPage() - 1) * $limit;
86
87
        $criteria = [];
88
        if (! $this->hasAuthenticatedUser() || ! $this->getAcl()->isUserAllowed($this->getAuthenticatedUser(), 'Donor', 'approve')) {
89
            $criteria['status'] = 'activated';
90
        }
91
92
        return $this->getUserRepository()->findBy($criteria, ['created_at' => 'DESC'], $limit, $offset);
93
    }
94
95
    /**
96
     * @return int
97
     * @since 1.0
98
     */
99
    public function countQueriedUsers()
100
    {
101
        return count($this->getQueriedUsers());
102
    }
103
}
104