Paginator   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 94
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A onPostDeserialize() 0 4 1
A setPage() 0 6 1
A getTotal() 0 4 1
A perPage() 0 4 1
A currentPage() 0 4 1
A getLastPage() 0 4 1
A items() 0 4 1
A __construct() 0 4 1
1
<?php
2
3
namespace Realshadow\Redtube\Entities;
4
5
use Illuminate\Support\Collection;
6
use JMS\Serializer\Annotation as JMS;
7
8
9
/**
10
 * Paginator
11
 *
12
 * @package Realshadow\Redtube\Entities
13
 * @author Lukáš Homza <[email protected]>
14
 *
15
 * @JMS\XmlRoot("root")
16
 */
17
class Paginator
18
{
19
20
    /**
21
     * @var int $page
22
     *
23
     * @JMS\Exclude()
24
     */
25
    private $page = 1;
26
27
    /**
28
     * @var int $total
29
     *
30
     * @JMS\Type("integer")
31
     * @JMS\SerializedName("count")
32
     */
33
    private $total = 0;
34
35
    /**
36
     * @var Collection|Videos $items
37
     *
38
     * @JMS\Type("Realshadow\Redtube\Entities\Videos")
39
     * @JMS\SerializedName("videos")
40
     */
41
    private $items;
42
43
    /**
44
     */
45
    public function __construct()
46
    {
47
        $this->items = new Collection;
48
    }    
49
    
50
    /**
51
     * @JMS\PostDeserialize()
52
     */
53
    public function onPostDeserialize()
54
    {
55
        $this->items = $this->items->flatten();
56
    }
57
58
    /**
59
     * @param int $page
60
     *
61
     * @return Paginator
62
     */
63
    public function setPage($page)
64
    {
65
        $this->page = $page;
66
67
        return $this;
68
    }
69
70
    /**
71
     * @return int
72
     */
73
    public function getTotal()
74
    {
75
        return $this->total;
76
    }
77
78
    /**
79
     * @return int
80
     */
81
    public function perPage()
82
    {
83
        return $this->items->count();
0 ignored issues
show
Bug introduced by
The method count does only exist in Illuminate\Support\Collection, but not in Realshadow\Redtube\Entities\Videos.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
84
    }
85
86
    /**
87
     * @return int
88
     */
89
    public function currentPage()
90
    {
91
        return $this->page;
92
    }
93
94
    /**
95
     * @return float
96
     */
97
    public function getLastPage()
98
    {
99
        return ceil($this->total / $this->perPage());
100
    }
101
102
    /**
103
     * @return Collection
104
     */
105
    public function items()
106
    {
107
        return $this->items;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->items; of type Illuminate\Support\Colle...Redtube\Entities\Videos adds the type Realshadow\Redtube\Entities\Videos to the return on line 107 which is incompatible with the return type documented by Realshadow\Redtube\Entities\Paginator::items of type Illuminate\Support\Collection.
Loading history...
108
    }
109
110
}
111