AbstractProviderPagerFanta   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 49
rs 10
c 1
b 0
f 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getAdapter() 0 4 1
A getPagerfantaObject() 0 9 1
A getPagerFanta() 0 4 1
1
<?php
2
3
4
namespace Miliooo\Messaging\ThreadProvider\Folder;
5
6
use Doctrine\ORM\QueryBuilder;
7
use Pagerfanta\Adapter\DoctrineORMAdapter;
8
use Pagerfanta\Pagerfanta;
9
10
/**
11
 * Abstract provider class for pagerfanta folder pagination.
12
 *
13
 * @author Michiel Boeckaert <[email protected]>
14
 */
15
abstract class AbstractProviderPagerFanta
16
{
17
    /**
18
     * Gets an adapter with the querybuilder.
19
     *
20
     * Helper function to be able to somewhat test this.
21
     *
22
     * @param QueryBuilder $queryBuilder
23
     *
24
     * @return DoctrineORMAdapter
25
     */
26
    protected function getAdapter(QueryBuilder $queryBuilder)
27
    {
28
        return new DoctrineORMAdapter($queryBuilder);
29
    }
30
31
    /**
32
     * Gets the pagerfanta object with the current adapter.
33
     *
34
     * Helper function to be able to somewhat test this.
35
     *
36
     * @param DoctrineORMAdapter $adapter
37
     *
38
     * @return Pagerfanta
39
     */
40
    protected function getPagerFanta(DoctrineORMAdapter $adapter)
41
    {
42
        return new Pagerfanta($adapter);
43
    }
44
45
    /**
46
     * Gets a pagerfanta object for the given page and the given queryBuilder
47
     *
48
     * @param QueryBuilder $queryBuilder A query builder instance
49
     * @param integer      $currentPage  The current page we are on
50
     * @param integer      $itemsPerPage How many items per page we show
51
     *
52
     * @return Pagerfanta
53
     */
54
    protected function getPagerfantaObject($queryBuilder, $currentPage, $itemsPerPage)
55
    {
56
        $adapter = $this->getAdapter($queryBuilder);
57
        $pagerfanta = $this->getPagerFanta($adapter);
58
        $pagerfanta->setMaxPerPage($itemsPerPage);
59
        $pagerfanta->setCurrentPage($currentPage);
60
61
        return $pagerfanta;
62
    }
63
}
64