PagerfantaController   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 16
lcom 1
cbo 5
dl 0
loc 100
rs 10
c 0
b 0
f 0

16 Methods

Rating   Name   Duplication   Size   Complexity  
A defaultViewAction() 0 4 1
A defaultShortViewAction() 0 4 1
A twitterBootstrapViewAction() 0 4 1
A twitterBootstrap3ViewAction() 0 4 1
A viewWithOptionsAction() 0 4 1
A viewWithoutFirstPageParamAction() 0 4 1
A defaultTranslatedViewAction() 0 4 1
A twitterBootstrapTranslatedViewAction() 0 4 1
A twitterBootstrap3TranslatedViewAction() 0 4 1
A myView1Action() 0 4 1
A viewWithRouteParamsAction() 0 4 1
A defaultWithRequestAction() 0 11 1
A renderPagerfanta() 0 10 1
A buildTemplateName() 0 4 1
A createPagerfanta() 0 6 1
A createAdapter() 0 7 1
1
<?php
2
3
namespace WhiteOctober\PagerfantaTestBundle\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6
use Pagerfanta\Pagerfanta;
7
use Pagerfanta\Adapter\FixedAdapter;
8
use Symfony\Component\HttpFoundation\Request;
9
10
class PagerfantaController extends Controller
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Bundle\Framework...e\Controller\Controller has been deprecated with message: since Symfony 4.2, use "Symfony\Bundle\FrameworkBundle\Controller\AbstractController" instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
11
{
12
    public function defaultViewAction()
13
    {
14
        return $this->renderPagerfanta('defaultView');
15
    }
16
17
    public function defaultShortViewAction()
18
    {
19
        return $this->renderPagerfanta('defaultShortView');
20
    }
21
22
    public function twitterBootstrapViewAction()
23
    {
24
        return $this->renderPagerfanta('twitterBootstrapView');
25
    }
26
27
    public function twitterBootstrap3ViewAction()
28
    {
29
        return $this->renderPagerfanta('twitterBootstrap3View');
30
    }
31
32
    public function viewWithOptionsAction()
33
    {
34
        return $this->renderPagerfanta('viewWithOptions');
35
    }
36
37
    public function viewWithoutFirstPageParamAction(Request $request)
38
    {
39
        return $this->defaultWithRequestAction($request, 'viewWithoutFirstPageParam');
40
    }
41
42
    public function defaultTranslatedViewAction()
43
    {
44
        return $this->renderPagerfanta('defaultTranslatedView');
45
    }
46
47
    public function twitterBootstrapTranslatedViewAction()
48
    {
49
        return $this->renderPagerfanta('twitterBootstrapTranslatedView');
50
    }
51
52
    public function twitterBootstrap3TranslatedViewAction()
53
    {
54
        return $this->renderPagerfanta('twitterBootstrap3TranslatedView');
55
    }
56
57
    public function myView1Action()
58
    {
59
        return $this->renderPagerfanta('myView1');
60
    }
61
62
    public function viewWithRouteParamsAction($test = null)
0 ignored issues
show
Unused Code introduced by
The parameter $test is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
63
    {
64
        return $this->renderPagerfanta('viewWithRouteParams');
65
    }
66
67
    public function defaultWithRequestAction(Request $request, $name = 'defaultView')
68
    {
69
        $template = $this->buildTemplateName($name);
70
        $pagerfanta = $this->createPagerfanta();
71
        $pagerfanta->setMaxPerPage($request->query->get('maxPerPage', 10));
72
        $pagerfanta->setCurrentPage($request->query->get('currentPage', 1));
73
74
        return $this->render($template, array(
75
            'pagerfanta' => $pagerfanta,
76
        ));
77
    }
78
79
    private function renderPagerfanta($name)
80
    {
81
        $template = $this->buildTemplateName($name);
82
        $pagerfanta = $this->createPagerfanta();
83
84
        return $this->render($template, array(
85
            'pagerfanta' => $pagerfanta
86
        ));
87
88
    }
89
90
    private function buildTemplateName($name)
91
    {
92
        return sprintf('WhiteOctoberPagerfantaTestBundle:Pagerfanta:%s.html.twig', $name);
93
    }
94
95
    private function createPagerfanta()
96
    {
97
        $adapter = $this->createAdapter();
98
99
        return new Pagerfanta($adapter);
100
    }
101
102
    private function createAdapter()
103
    {
104
        $nbResults = 100;
105
        $results = range(1, $nbResults);
106
107
        return new FixedAdapter($nbResults, $results);
108
    }
109
}
110