Passed
Push — master ( b86a9b...818b3e )
by Thierry
02:35
created

PaginationRenderer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * PaginationRenderer.php - Paginator renderer
5
 *
6
 * Render pagination links.
7
 *
8
 * @package jaxon-core
0 ignored issues
show
Coding Style introduced by
Package name "jaxon-core" is not valid; consider "Jaxoncore" instead
Loading history...
9
 * @author Thierry Feuzeu <[email protected]>
10
 * @copyright 2016 Thierry Feuzeu <[email protected]>
11
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
12
 * @link https://github.com/jaxon-php/jaxon-core
13
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
14
15
namespace Jaxon\App\View;
16
17
use Jaxon\Request\Call\Paginator;
18
19
use function array_map;
20
use function array_pop;
21
use function array_shift;
22
23
class PaginationRenderer
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class PaginationRenderer
Loading history...
24
{
25
    /**
26
     * The viev renderer.
27
     *
28
     * @var ViewRenderer
29
     */
30
    protected $xRenderer = null;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
31
32
    /**
33
     * The class constructor
34
     *
35
     * @param ViewRenderer  $xRenderer
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
36
     */
37
    public function __construct(ViewRenderer $xRenderer)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
38
    {
39
        $this->xRenderer = $xRenderer;
40
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
41
42
    /**
43
     * Render a link to a page.
44
     *
45
     * @param string $sTemplate    The template for the link to the page
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
46
     * @param string $sText    The text of the link if it is enabled
0 ignored issues
show
Coding Style introduced by
Expected 5 spaces after parameter name; 4 found
Loading history...
47
     * @param string $sCall    The call of the link if it is enabled
0 ignored issues
show
Coding Style introduced by
Expected 5 spaces after parameter name; 4 found
Loading history...
48
     *
49
     * @return null|Store
50
     */
51
    protected function renderLink(string $sTemplate, string $sText, string $sCall): ?Store
52
    {
53
        return $this->xRenderer->render('pagination::links/' . $sTemplate, [
54
            'text' => $sText,
55
            'call' => $sCall,
56
        ]);
57
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
58
59
    /**
60
     * Render an HTML pagination control.
61
     *
62
     * @param Paginator $xPaginator The paginator
63
     *
64
     * @return null|Store
65
     */
66
    public function render(Paginator $xPaginator): ?Store
67
    {
68
        $aLinks = array_map(function($aPage) {
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
69
            return $this->renderLink($aPage[0], $aPage[1], $aPage[2]);
70
        }, $xPaginator->links());
71
        $aPrevLink = array_shift($aLinks); // The first entry in the array
72
        $aNextLink = array_pop($aLinks); // The last entry in the array
73
74
        return $this->xRenderer->render('pagination::wrapper', [
75
            'links' => $aLinks,
76
            'prev' => $aPrevLink,
77
            'next' => $aNextLink,
78
        ]);
79
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
80
}
81