Failed Conditions
Push — master ( 674f38...37557b )
by Adrien
03:06
created

CreatePaginator::createPaginator()   A

Complexity

Conditions 5
Paths 12

Size

Total Lines 34
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 6.0718

Importance

Changes 0
Metric Value
eloc 20
c 0
b 0
f 0
dl 0
loc 34
ccs 13
cts 20
cp 0.65
rs 9.2888
cc 5
nc 12
nop 1
crap 6.0718
1
<?php
2
3
namespace mQueue\Controller\ActionHelper;
4
5
use Zend_Controller_Action_Helper_Abstract;
6
use Zend_Paginator;
7
use Zend_Session_Namespace;
8
9
class CreatePaginator extends Zend_Controller_Action_Helper_Abstract
10
{
11
    /**
12
     * Create a new Zend_Paginator and configure it with GET or session variables
13
     *
14
     * @param mixed $data
15
     *
16
     * @return Zend_Paginator
17
     */
18 4
    public function createPaginator($data)
19
    {
20
        // Read perPage from session, or GET
21 4
        $perPage = 25;
22 4
        $session = new Zend_Session_Namespace();
23 4
        if (isset($session->perPage)) {
24
            $perPage = $session->perPage;
25
        }
26
27 4
        $userPerPage = $this->getRequest()->getParam('perPage');
28 4
        if ($userPerPage) {
29
            $perPage = $userPerPage;
30
            $session->perPage = $perPage;
31
        }
32
33
        // If we export to csv or rss, override perPage parameter
34 4
        $currentContext = $this->getActionController()->getHelper('contextSwitch')->getCurrentContext();
0 ignored issues
show
Bug introduced by
The method getCurrentContext() does not exist on Zend_Controller_Action_Helper_Abstract. It seems like you code against a sub-type of Zend_Controller_Action_Helper_Abstract such as Zend_Controller_Action_Helper_Cache or Zend_Controller_Action_Helper_ContextSwitch or Zend_Controller_Action_Helper_Redirector or Zend_Layout_Controller_Action_Helper_Layout. ( Ignorable by Annotation )

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

34
        $currentContext = $this->getActionController()->getHelper('contextSwitch')->/** @scrutinizer ignore-call */ getCurrentContext();
Loading history...
35
        switch ($currentContext) {
36 4
            case 'csv':
37
                $perPage = -1;
38
39
                break;
40 4
            case 'rss':
41
                $perPage = 200;
42
43
                break;
44
        }
45
46
        // Defines the paginator
47 4
        $paginator = Zend_Paginator::factory($data);
48 4
        $paginator->setCurrentPageNumber($this->getRequest()->getParam('page'));
49 4
        $paginator->setItemCountPerPage($perPage);
50
51 4
        return $paginator;
52
    }
53
54
    /**
55
     * Strategy pattern: call helper as broker method
56
     *
57
     * @param mixed $data
58
     *
59
     * @return Zend_Paginator
60
     */
61 4
    public function direct($data)
62
    {
63 4
        return $this->createPaginator($data);
64
    }
65
}
66