Completed
Push — master ( 1fcafd...dc160c )
by Arnaud
18s queued 11s
created

View   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 231
Duplicated Lines 0 %

Test Coverage

Coverage 30.19%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
eloc 50
c 3
b 0
f 1
dl 0
loc 231
ccs 16
cts 53
cp 0.3019
rs 10
wmc 20

18 Methods

Rating   Name   Duplication   Size   Complexity  
A __call() 0 3 1
A __construct() 0 20 1
A setEntities() 0 15 3
A getTotalCount() 0 3 1
A getPager() 0 3 1
A getActionName() 0 3 1
A getBase() 0 3 1
A getMenus() 0 3 1
A getEntities() 0 3 1
A getConfiguration() 0 3 1
A getForms() 0 3 1
A getAdminConfiguration() 0 3 1
A getName() 0 3 1
A getHeaders() 0 3 1
A getFields() 0 3 1
A getTemplate() 0 3 1
A haveToPaginate() 0 3 1
A getData() 0 3 1
1
<?php
2
3
namespace LAG\AdminBundle\View;
4
5
use ArrayIterator;
6
use Doctrine\Common\Collections\ArrayCollection;
7
use Doctrine\Common\Collections\Collection;
8
use LAG\AdminBundle\Configuration\ActionConfiguration;
9
use LAG\AdminBundle\Configuration\AdminConfiguration;
10
use LAG\AdminBundle\Field\FieldInterface;
11
use LAG\AdminBundle\Menu\MenuItem;
0 ignored issues
show
Bug introduced by
The type LAG\AdminBundle\Menu\MenuItem was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Pagerfanta\Pagerfanta;
13
use Symfony\Component\Form\FormInterface;
14
15
class View implements ViewInterface
16
{
17
    /**
18
     * @var string
19
     */
20
    private $actionName;
21
22
    /**
23
     * @var ActionConfiguration
24
     */
25
    private $configuration;
26
27
    /**
28
     * @var string
29
     */
30
    private $adminName;
31
32
    /**
33
     * @var array|Collection
34
     */
35
    private $entities = [];
36
37
    /**
38
     * @var FieldInterface[]
39
     */
40
    private $fields;
41
42
    /**
43
     * @var AdminConfiguration
44
     */
45
    private $adminConfiguration;
46
47
    /**
48
     * @var bool
49
     */
50
    private $haveToPaginate = false;
51
52
    /**
53
     * @var int
54
     */
55
    private $totalCount = 0;
56
57
    /**
58
     * @var Pagerfanta
59
     */
60
    private $pager;
61
62
    /**
63
     * @var FieldInterface[]
64
     */
65
    private $headers;
66
67
    /**
68
     * @var MenuItem[]
69
     */
70
    private $menus;
71
72
    /**
73
     * @var FormInterface[]
74
     */
75
    private $forms;
76
77
    /**
78
     * @var string
79
     */
80
    private $base;
81
82
    /**
83
     * View constructor.
84
     *
85
     * @param FieldInterface[]    $fields
86
     * @param FormInterface[]     $forms
87
     * @param FieldInterface[]    $headers
88
     */
89 8
    public function __construct(
90
        string $actionName,
91
        string $adminName,
92
        ActionConfiguration $configuration,
93
        AdminConfiguration $adminConfiguration,
94
        string $base = '',
95
        array $fields = [],
96
        array $forms = [],
97
        array $menus = [],
98
        array $headers = []
99
    ) {
100 8
        $this->actionName = $actionName;
101 8
        $this->configuration = $configuration;
102 8
        $this->adminName = $adminName;
103 8
        $this->fields = $fields;
104 8
        $this->adminConfiguration = $adminConfiguration;
105 8
        $this->headers = $headers;
106 8
        $this->menus = $menus;
107 8
        $this->forms = $forms;
108 8
        $this->base = $base;
109 8
    }
110
111
    public function __call($name, $arguments)
112
    {
113
        return $this->configuration->getParameter($name);
114
    }
115
116
    public function getData()
117
    {
118
        return $this->entities;
119
    }
120
121
    /**
122
     * @return ActionConfiguration
123
     */
124
    public function getConfiguration()
125
    {
126
        return $this->configuration;
127
    }
128
129
    /**
130
     * @return string
131
     */
132
    public function getActionName()
133
    {
134
        return $this->actionName;
135
    }
136
137
    /**
138
     * @return Collection|Pagerfanta|array
139
     */
140
    public function getEntities()
141
    {
142
        return $this->entities;
143 4
    }
144
145 4
    /**
146
     * @param mixed $entities
147
     */
148
    public function setEntities($entities)
149
    {
150
        if ($entities instanceof Pagerfanta) {
151
            $this->pager = $entities;
152
            $results = $entities->getCurrentPageResults();
153
154
            if ($results instanceof ArrayIterator) {
155
                $results = $results->getArrayCopy();
156 4
            }
157 4
            $this->entities = new ArrayCollection($results);
0 ignored issues
show
Bug introduced by
It seems like $results can also be of type iterable; however, parameter $elements of Doctrine\Common\Collecti...llection::__construct() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

157
            $this->entities = new ArrayCollection(/** @scrutinizer ignore-type */ $results);
Loading history...
158
            $this->haveToPaginate = true;
159 4
            $this->totalCount = $entities->count();
160
        } else {
161
            $this->entities = $entities;
162
            $this->totalCount = count($entities);
163
        }
164
    }
165
166
    /**
167
     * @return string
168
     */
169
    public function getName()
170
    {
171
        return $this->adminName;
172
    }
173
174
    /**
175
     * @return FieldInterface[]
176
     */
177
    public function getFields()
178
    {
179
        return $this->fields;
180
    }
181
182
    /**
183
     * @return AdminConfiguration
184
     */
185
    public function getAdminConfiguration()
186
    {
187
        return $this->adminConfiguration;
188
    }
189
190
    /**
191
     * @return bool
192
     */
193
    public function haveToPaginate()
194
    {
195
        return $this->haveToPaginate;
196
    }
197
198
    /**
199
     * @return int
200
     */
201
    public function getTotalCount()
202
    {
203
        return $this->totalCount;
204
    }
205
206
    /**
207
     * @return Pagerfanta|null
208
     */
209
    public function getPager()
210
    {
211
        return $this->pager;
212
    }
213
214
    /**
215
     * @return FieldInterface[]
216
     */
217
    public function getHeaders()
218
    {
219
        return $this->headers;
220
    }
221
222
    /**
223
     * @return MenuItem[]
224
     */
225
    public function getMenus(): array
226
    {
227
        return $this->menus;
228
    }
229
230
    public function getTemplate(): string
231
    {
232
        return $this->configuration->getParameter('template');
233
    }
234
235
    /**
236
     * @return FormInterface[]
237
     */
238
    public function getForms(): array
239
    {
240
        return $this->forms;
241
    }
242
243
    public function getBase(): string
244
    {
245
        return $this->base;
246
    }
247
}
248