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 ( 1978d2...e2f699 )
by William
03:55
created

Hateoas/Representation/OffsetRepresentation.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Hateoas\Representation;
4
5
use Hateoas\Configuration\Annotation as Hateoas;
6
use JMS\Serializer\Annotation as Serializer;
7
8
/**
9
 * @Serializer\ExclusionPolicy("all")
10
 * @Serializer\XmlRoot("collection")
11
 * @Serializer\AccessorOrder("custom", custom = {"offset", "limit", "total"})
12
 *
13
 * @Hateoas\Relation(
14
 *      "first",
15
 *      href = @Hateoas\Route(
16
 *          "expr(object.getRoute())",
17
 *          parameters = "expr(object.getParameters(0))",
18
 *          absolute = "expr(object.isAbsolute())"
19
 *      )
20
 * )
21
 * @Hateoas\Relation(
22
 *      "last",
23
 *      href = @Hateoas\Route(
24
 *          "expr(object.getRoute())",
25
 *          parameters = "expr(object.getParameters((object.getTotal() - 1) - (object.getTotal() - 1) % object.getLimit()))",
26
 *          absolute = "expr(object.isAbsolute())"
27
 *      ),
28
 *      exclusion = @Hateoas\Exclusion(
29
 *          excludeIf = "expr(object.getTotal() === null)"
30
 *      )
31
 * )
32
 * @Hateoas\Relation(
33
 *      "next",
34
 *      href = @Hateoas\Route(
35
 *          "expr(object.getRoute())",
36
 *          parameters = "expr(object.getParameters(object.getOffset() + object.getLimit()))",
37
 *          absolute = "expr(object.isAbsolute())"
38
 *      ),
39
 *      exclusion = @Hateoas\Exclusion(
40
 *          excludeIf = "expr(object.getTotal() !== null && (object.getOffset() + object.getLimit()) >= object.getTotal())"
41
 *      )
42
 * )
43
 * @Hateoas\Relation(
44
 *      "previous",
45
 *      href = @Hateoas\Route(
46
 *          "expr(object.getRoute())",
47
 *          parameters = "expr(object.getParameters((object.getOffset() > object.getLimit()) ? object.getOffset() - object.getLimit() : 0))",
48
 *          absolute = "expr(object.isAbsolute())"
49
 *      ),
50
 *      exclusion = @Hateoas\Exclusion(
51
 *          excludeIf = "expr(! object.getOffset())"
52
 *      )
53
 * )
54
 *
55
 * @author Premi Giorgio <[email protected]>
56
 */
57
class OffsetRepresentation extends AbstractSegmentedRepresentation
58
{
59
    /**
60
     * @var int
61
     *
62
     * @Serializer\Expose
63
     * @Serializer\XmlAttribute
64
     */
65
    private $offset;
66
67
    /**
68
     * @var string
69
     */
70
    private $offsetParameterName;
71
72
    /**
73
     * @param CollectionRepresentation $inline
74
     * @param string $route
75
     * @param integer|null $offset
76
     * @param integer $limit
77
     * @param integer $total
78
     */
79 View Code Duplication
    public function __construct(
80
        $inline,
81
        $route,
82
        array $parameters        = array(),
83
        $offset,
84
        $limit,
85
        $total                   = null,
86
        $offsetParameterName     = null,
87
        $limitParameterName      = null,
88
        $absolute                = false
89
    ) {
90
        parent::__construct($inline, $route, $parameters, $limit, $total, $limitParameterName, $absolute);
91
92
        $this->offset              = $offset;
93
        $this->offsetParameterName = $offsetParameterName  ?: 'offset';
94
    }
95
96
    /**
97
     * @return int
98
     */
99
    public function getOffset()
100
    {
101
        return $this->offset;
102
    }
103
104
    /**
105
     * @param  null  $offset
106
     * @param  null  $limit
107
     * @return array
108
     */
109
    public function getParameters($offset = null, $limit = null)
110
    {
111
        $parameters = parent::getParameters($limit);
112
113
        unset($parameters[$this->offsetParameterName]);
114
115
        if (null === $offset) {
116
            $offset = $this->getOffset();
117
        }
118
119
        if ($offset) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $offset of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
120
            $parameters[$this->offsetParameterName] = $offset;
121
            $this->moveParameterToEnd($parameters, $this->getLimitParameterName());
122
        }
123
124
        return $parameters;
125
    }
126
127
    /**
128
     * @return string
129
     */
130
    public function getOffsetParameterName()
131
    {
132
        return $this->offsetParameterName;
133
    }
134
}
135