GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( c21a18...869bac )
by Asao
01:28
created

ToBootstrap3::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace Tuum\Pagination\ToHtml;
3
4
use Tuum\Pagination\Paginate\Page;
5
use Tuum\Pagination\Paginate\Paginate;
6
use Tuum\Pagination\Paginate\PaginateInterface;
7
8
class ToBootstrap3 implements ToHtmlInterface
9
{
10
    /**
11
     * @var Paginate
12
     */
13
    private $paginate;
14
15
    /**
16
     * ToBootstrap3 constructor.
17
     *
18
     * @param Paginate $paginate
19
     */
20
    public function __construct($paginate)
21
    {
22
        $this->paginate = $paginate;
23
    }
24
25
    /**
26
     * @param PaginateInterface $paginate
27
     * @return ToHtmlInterface
28
     */
29
    public function setPaginate(PaginateInterface $paginate)
30
    {
31
        $this->paginate = $paginate;
0 ignored issues
show
Documentation Bug introduced by
$paginate is of type object<Tuum\Pagination\P...nate\PaginateInterface>, but the property $paginate was declared to be of type object<Tuum\Pagination\Paginate\Paginate>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
32
        return $this;
33
    }
34
35
    /**
36
     * @return string
37
     */
38
    public function __toString()
39
    {
40
        return $this->toString();
41
    }
42
43
    /**
44
     * @return string
45
     */
46
    public function toString()
47
    {
48
        $paginate = $this->paginate;
49
        $html     = '<ul class="pagination">';
50
        $html     .= $this->liLabel($paginate->getPrevPage(), '&lt;');
51
        $html     .= $this->li($paginate->getFirstPage());
52
        foreach ($paginate as $page) {
53
            $html .= $this->li($page);
54
        }
55
        $html .= $this->li($paginate->getLastPage());
56
        $html     .= $this->liLabel($paginate->getNextPage(), '&gt;');
57
        $html .= '</ul>';
58
59
        return $html;
60
    }
61
62
    /**
63
     * @param Page $p
64
     * @return string
65
     */
66
    private function li(Page $p, $label = null)
67
    {
68
        $label = $label ?: $p->getPage();
69
        if ($p->isDisabled()) {
70
            return '<li class="disabled"><a href="#" >...</a></li>';
71
        }
72
        if ($p->isCurrent()) {
73
            return "<li class=\"active\"><a href=\"#\" >{$label}<span class='sr-only'>current</span></a></li>\n";
74
        }
75
76
        return "<li><a href=\"{$p->getUrl()}\" >{$label}</a></li>\n";
77
    }
78
    
79
    private function liLabel(Page $p, $label)
80
    {
81
        if ($p->isCurrent()) {
82
            return "<li class=\"disabled\"><a href=\"#\" >{$label}</a></li>\n";
83
        }
84
85
        return "<li><a href=\"{$p->getUrl()}\" >{$label}</a></li>\n";
86
    }
87
}