Issues (294)

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

Severity
1
<?php
2
/**
3
 * View cities page controller class file
4
 *
5
 * @package    EBloodBank
6
 * @subpackage Controllers
7
 * @since      1.0
8
 */
9
namespace EBloodBank\Controllers;
10
11
use EBloodBank as EBB;
12
use EBloodBank\Options;
13
14
/**
15
 * View cities page controller class
16
 *
17
 * @since 1.0
18
 */
19
class ViewCities extends Controller
20
{
21
    /**
22
     * @return void
23
     * @since 1.0
24
     */
25
    public function __invoke()
26
    {
27
        $isSitePublic = ('on' === EBB\Options::getOption('site_publication'));
28
        if (! $isSitePublic && (! $this->hasAuthenticatedUser() || ! $this->getAcl()->isUserAllowed($this->getAuthenticatedUser(), 'City', 'read'))) {
29
            $this->viewFactory->displayView('error-403');
30
        } else {
31
            $this->viewFactory->displayView('view-cities', [
32
                'cities'             => $this->getQueriedCities(),
33
                'pagination.total'   => $this->getPagesTotal(),
34
                'pagination.current' => $this->getCurrentPage(),
35
            ]);
36
        }
37
    }
38
39
    /**
40
     * @return int
41
     * @since 1.0
42
     */
43
    public function getPagesTotal()
44
    {
45
        $total = 1;
46
        $limit = (int) Options::getOption('entities_per_page');
47
        if ($limit >= 1) {
48
            $total = (int) ceil($this->countAllCities() / $limit);
49
        }
50
        return $total;
51
    }
52
53
    /**
54
     * @return int
55
     * @since 1.0
56
     */
57
    public function getCurrentPage()
58
    {
59
        return max((int) filter_input(INPUT_GET, 'page'), 1);
60
    }
61
62
    /**
63
     * @return \EBloodBank\Models\City[]
64
     * @since 1.0
65
     */
66
    public function getAllCities()
67
    {
68
        return $this->getCityRepository()->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

68
        return $this->getCityRepository()->/** @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...
69
    }
70
71
    /**
72
     * @return int
73
     * @since 1.0
74
     */
75
    public function countAllCities()
76
    {
77
        return $this->getCityRepository()->countAll();
78
    }
79
80
    /**
81
     * @return \EBloodBank\Models\City[]
82
     * @since 1.0
83
     */
84
    public function getQueriedCities()
85
    {
86
        $limit = (int) Options::getOption('entities_per_page');
87
        $offset = ($this->getCurrentPage() - 1) * $limit;
88
89
        return $this->getCityRepository()->findBy([], ['created_at' => 'DESC'], $limit, $offset);
90
    }
91
92
    /**
93
     * @return int
94
     * @since 1.0
95
     */
96
    public function countQueriedCities()
97
    {
98
        return count($this->getQueriedCities());
99
    }
100
}
101