Completed
Pull Request — master (#90)
by Arnaud
16:42
created

View::getPager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace LAG\AdminBundle\View;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use LAG\AdminBundle\Action\Configuration\ActionConfiguration;
7
use LAG\AdminBundle\Admin\Configuration\AdminConfiguration;
8
use LAG\AdminBundle\Field\FieldInterface;
9
use Pagerfanta\Pagerfanta;
10
11
class View implements ViewInterface
12
{
13
    /**
14
     * @var string
15
     */
16
    private $actionName;
17
    
18
    /**
19
     * @var ActionConfiguration
20
     */
21
    private $configuration;
22
    
23
    /**
24
     * @var string
25
     */
26
    private $adminName;
27
    
28
    /**
29
     * @var array
30
     */
31
    private $entities = [];
32
    
33
    /**
34
     * @var FieldInterface[]
35
     */
36
    private $fields;
37
    
38
    /**
39
     * @var AdminConfiguration
40
     */
41
    private $adminConfiguration;
42
    
43
    /**
44
     * @var bool
45
     */
46
    private $haveToPaginate = false;
47
    
48
    /**
49
     * @var int
50
     */
51
    private $totalCount = 0;
52
    
53
    /**
54
     * @var Pagerfanta
55
     */
56
    private $pager;
57
    
58
    /**
59
     * View constructor.
60
     *
61
     * @param                     $actionName
62
     * @param                     $adminName
63
     * @param ActionConfiguration $configuration
64
     * @param AdminConfiguration  $adminConfiguration
65
     * @param array               $fields
66
     */
67
    public function __construct(
68
        $actionName,
69
        $adminName,
70
        ActionConfiguration $configuration,
71
        AdminConfiguration $adminConfiguration,
72
        array $fields = []
73
    ) {
74
        $this->actionName = $actionName;
75
        $this->configuration = $configuration;
76
        $this->adminName = $adminName;
77
        $this->fields = $fields;
78
        $this->adminConfiguration = $adminConfiguration;
79
    }
80
    
81
    /**
82
     * @return ActionConfiguration
83
     */
84
    public function getConfiguration()
85
    {
86
        return $this->configuration;
87
    }
88
    
89
    /**
90
     * @return string
91
     */
92
    public function getActionName()
93
    {
94
        return $this->actionName;
95
    }
96
    
97
    /**
98
     * @return array
99
     */
100
    public function getEntities()
101
    {
102
        return $this->entities;
103
    }
104
    
105
    /**
106
     * @param $entities
107
     */
108
    public function setEntities($entities)
109
    {
110
        if ($entities instanceof Pagerfanta) {
111
            $this->pager = $entities;
112
            $this->entities = new ArrayCollection($entities->getCurrentPageResults());
0 ignored issues
show
Bug introduced by
It seems like $entities->getCurrentPageResults() targeting Pagerfanta\Pagerfanta::getCurrentPageResults() can also be of type object<Traversable>; however, Doctrine\Common\Collecti...llection::__construct() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
Documentation Bug introduced by
It seems like new \Doctrine\Common\Col...etCurrentPageResults()) of type object<Doctrine\Common\C...ctions\ArrayCollection> is incompatible with the declared type array of property $entities.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
113
            $this->haveToPaginate = true;
114
            $this->totalCount = $entities->count();
115
        } else {
116
            $this->entities = $entities;
117
            $this->totalCount = count($entities);
118
        }
119
    }
120
    
121
    /**
122
     * @return string
123
     */
124
    public function getName()
125
    {
126
        return $this->adminName;
127
    }
128
    
129
    /**
130
     * @return FieldInterface[]
131
     */
132
    public function getFields()
133
    {
134
        return $this->fields;
135
    }
136
    
137
    /**
138
     * @return AdminConfiguration
139
     */
140
    public function getAdminConfiguration()
141
    {
142
        return $this->adminConfiguration;
143
    }
144
    
145
    /**
146
     * @return bool
147
     */
148
    public function haveToPaginate()
149
    {
150
        return $this->haveToPaginate;
151
    }
152
    
153
    /**
154
     * @return int
155
     */
156
    public function getTotalCount()
157
    {
158
        return $this->totalCount;
159
    }
160
    
161
    /**
162
     * @return Pagerfanta|null
163
     */
164
    public function getPager()
165
    {
166
        return $this->pager;
167
    }
168
}
169