Completed
Push — refonte ( 64e01a...7173e3 )
by Arnaud
03:31
created

AdminTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 670
Duplicated Lines 12.84 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 7
dl 86
loc 670
rs 9.93
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
B testHandleRequest() 0 149 1
B testCheckPermissionsNonUser() 0 71 1
A testCheckPermissionsNonInit() 0 52 1
B testCheckPermissionsNonGranted() 0 86 1
B testCheckPermissionsNonGrantedForAction() 0 104 1
A testCreate() 0 44 1
A testSave() 43 43 1
A testRemove() 43 43 1
B testLoad() 0 55 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace LAG\AdminBundle\Tests\AdminBundle\Admin;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use LAG\AdminBundle\Action\ActionInterface;
7
use LAG\AdminBundle\Action\Configuration\ActionConfiguration;
8
use LAG\AdminBundle\Admin\Admin;
9
use LAG\AdminBundle\Admin\Configuration\AdminConfiguration;
10
use LAG\AdminBundle\Admin\Request\RequestHandlerInterface;
11
use LAG\AdminBundle\DataProvider\DataProviderInterface;
12
use LAG\AdminBundle\DataProvider\Loader\EntityLoaderInterface;
13
use LAG\AdminBundle\Message\MessageHandlerInterface;
14
use LAG\AdminBundle\Tests\AdminTestBase;
15
use LAG\AdminBundle\Tests\Entity\TestSimpleEntity;
16
use LAG\AdminBundle\View\Factory\ViewFactory;
17
use LAG\AdminBundle\View\ViewInterface;
18
use LogicException;
19
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
20
use Symfony\Component\HttpFoundation\Request;
21
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
22
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
23
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
24
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
25
use Symfony\Component\Security\Core\User\UserInterface;
26
27
class AdminTest extends AdminTestBase
28
{
29
    public function testHandleRequest()
30
    {
31
        $configuration = $this->getMockWithoutConstructor(AdminConfiguration::class);
32
        $messageHandler = $this->getMockWithoutConstructor(MessageHandlerInterface::class);
33
        $eventDispatcher = $this->getMockWithoutConstructor(EventDispatcherInterface::class);
34
        
35
        $authorizationChecker = $this->getMockWithoutConstructor(AuthorizationCheckerInterface::class);
36
        $authorizationChecker
37
            ->expects($this->atLeastOnce())
38
            ->method('isGranted')
39
            ->willReturnCallback(function($roles) {
40
                $this->assertEquals([
41
                    'ROLE_USER',
42
                ], $roles);
43
                
44
                return true;
45
            })
46
        ;
47
    
48
        $user = $this->getMockWithoutConstructor(UserInterface::class);
49
        $user
50
            ->method('getRoles')
51
            ->willReturn([
52
                'ROLE_USER',
53
            ])
54
        ;
55
        
56
        $token = $this->getMockWithoutConstructor(TokenInterface::class);
57
        $token
58
            ->expects($this->once())
59
            ->method('getUser')
60
            ->willReturn($user)
61
        ;
62
        $tokenStorage = $this->getMockWithoutConstructor(TokenStorageInterface::class);
63
        $tokenStorage
64
            ->expects($this->once())
65
            ->method('getToken')
66
            ->willReturn($token)
67
        ;
68
    
69
        $entityLoader = $this->getMockWithoutConstructor(EntityLoaderInterface::class);
70
        $entityLoader
71
            ->expects($this->once())
72
            ->method('load')
73
            ->with([
74
                    'deleted' => false,
75
                ], [
76
                    'createdAt' => 'desc',
77
                ],
78
                10,
79
                1
80
            )
81
            ->willReturn(new ArrayCollection())
82
        ;
83
    
84
        $actionConfiguration = $this->getMockWithoutConstructor(ActionConfiguration::class);
85
        $actionConfiguration
86
            ->method('getParameter')
87
            ->willReturnMap([
88
                [
89
                    'actions', [
90
                        'list' => [],
91
                    ]
92
                ],
93
                [
94
                    'criteria', [
95
                        'deleted',
96
                    ]
97
                ],
98
                [
99
                    'order', [
100
                        'createdAt',
101
                    ]
102
                ],
103
                [
104
                    'max_per_page',
105
                    10
106
                ],
107
                [
108
                    'permissions', [
109
                        'ROLE_USER',
110
                    ]
111
                ],
112
                [
113
                    'sortable',
114
                    true
115
                ]
116
            ])
117
        ;
118
        $action = $this->getMockWithoutConstructor(ActionInterface::class);
119
        $action
120
            ->expects($this->exactly(1))
121
            ->method('getConfiguration')
122
            ->willReturn($actionConfiguration)
123
        ;
124
        $action
125
            ->method('isLoadingRequired')
126
            ->willReturn(true)
127
        ;
128
        $request = new Request([
129
            'deleted' => false,
130
            'sort' => 'createdAt',
131
            'order' => 'desc',
132
        ], [], [
133
            '_route_params' => [
134
                '_admin' => 'my_little_pony',
135
                '_action' => 'list',
136
            ]
137
        ]);
138
    
139
        $requestHandler = $this->getMockWithoutConstructor(RequestHandlerInterface::class);
140
        $requestHandler
141
            ->expects($this->once())
142
            ->method('supports')
143
            ->with($request)
144
            ->willReturn(true)
145
        ;
146
        
147
        $view = $this->getMockWithoutConstructor(ViewInterface::class);
148
        $view
149
            ->expects($this->exactly(2))
150
            ->method('getConfiguration')
151
            ->willReturn($actionConfiguration)
152
        ;
153
        
154
        $viewFactory = $this->getMockWithoutConstructor(ViewFactory::class);
155
        $viewFactory
156
            ->expects($this->once())
157
            ->method('create')
158
            ->with('list', 'my_little_pony', $configuration, $actionConfiguration)
159
            ->willReturn($view)
160
        ;
161
    
162
        $admin = new Admin(
163
            'my_little_pony',
0 ignored issues
show
Documentation introduced by
'my_little_pony' is of type string, but the function expects a object<LAG\AdminBundle\Resource\AdminResource>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
164
            $entityLoader,
0 ignored issues
show
Documentation introduced by
$entityLoader is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<LAG\AdminBundle\C...ion\AdminConfiguration>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
165
            $configuration,
0 ignored issues
show
Documentation introduced by
$configuration is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...entDispatcherInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
166
            $messageHandler,
0 ignored issues
show
Unused Code introduced by
The call to Admin::__construct() has too many arguments starting with $messageHandler.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
167
            $eventDispatcher,
168
            $authorizationChecker,
169
            $tokenStorage,
170
            $requestHandler,
171
            $viewFactory,
172
            [
173
                'list' => $action,
174
            ]
175
        );
176
        $admin->handleRequest($request);
177
    }
178
    
179
    /**
180
     * An AccessDeniedException should be raised if a non UserInterface is returned by the security token.
181
     */
182
    public function testCheckPermissionsNonUser()
183
    {
184
        $configuration = $this->getMockWithoutConstructor(AdminConfiguration::class);
185
        $messageHandler = $this->getMockWithoutConstructor(MessageHandlerInterface::class);
186
        $eventDispatcher = $this->getMockWithoutConstructor(EventDispatcherInterface::class);
187
        $authorizationChecker = $this->getMockWithoutConstructor(AuthorizationCheckerInterface::class);
188
    
189
        $token = $this->getMockWithoutConstructor(TokenInterface::class);
190
        $token
191
            ->expects($this->once())
192
            ->method('getUser')
193
            ->willReturn(false)
194
        ;
195
        $tokenStorage = $this->getMockWithoutConstructor(TokenStorageInterface::class);
196
        $tokenStorage
197
            ->expects($this->once())
198
            ->method('getToken')
199
            ->willReturn($token)
200
        ;
201
    
202
        $actionConfiguration = $this->getMockWithoutConstructor(ActionConfiguration::class);
203
        $action = $this->getMockWithoutConstructor(ActionInterface::class);
204
        $action
205
            ->expects($this->once())
206
            ->method('getConfiguration')
207
            ->willReturn($actionConfiguration)
208
        ;
209
        $entityLoader = $this->getMockWithoutConstructor(EntityLoaderInterface::class);
210
    
211
        $request = new Request([], [], [
212
            '_route_params' => [
213
                '_admin' => 'my_little_pony',
214
                '_action' => 'list',
215
            ]
216
        ]);
217
        $requestHandler = $this->getMockWithoutConstructor(RequestHandlerInterface::class);
218
        $requestHandler
219
            ->expects($this->once())
220
            ->method('supports')
221
            ->with($request)
222
            ->willReturn(true)
223
        ;
224
        
225
        $view = $this->getMockWithoutConstructor(ViewInterface::class);
226
        $viewFactory = $this->getMockWithoutConstructor(ViewFactory::class);
227
        $viewFactory
228
            ->expects($this->once())
229
            ->method('create')
230
            ->with('list', 'my_little_pony', $configuration, $actionConfiguration)
231
            ->willReturn($view)
232
        ;
233
    
234
        $admin = new Admin(
235
            'my_little_pony',
0 ignored issues
show
Documentation introduced by
'my_little_pony' is of type string, but the function expects a object<LAG\AdminBundle\Resource\AdminResource>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
236
            $entityLoader,
0 ignored issues
show
Documentation introduced by
$entityLoader is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<LAG\AdminBundle\C...ion\AdminConfiguration>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
237
            $configuration,
0 ignored issues
show
Documentation introduced by
$configuration is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...entDispatcherInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
238
            $messageHandler,
0 ignored issues
show
Unused Code introduced by
The call to Admin::__construct() has too many arguments starting with $messageHandler.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
239
            $eventDispatcher,
240
            $authorizationChecker,
241
            $tokenStorage,
242
            $requestHandler,
243
            $viewFactory,
244
            [
245
                'list' => $action,
246
            ]
247
        );
248
    
249
        $this->assertExceptionRaised(AccessDeniedException::class, function() use ($request, $admin) {
250
            $admin->handleRequest($request);
251
        });
252
    }
253
    
254
    /**
255
     * A LogicException should be raised if the current action is not set.
256
     */
257
    public function testCheckPermissionsNonInit()
258
    {
259
        $configuration = $this->getMockWithoutConstructor(AdminConfiguration::class);
260
        $messageHandler = $this->getMockWithoutConstructor(MessageHandlerInterface::class);
261
        $eventDispatcher = $this->getMockWithoutConstructor(EventDispatcherInterface::class);
262
        
263
        $authorizationChecker = $this->getMockWithoutConstructor(AuthorizationCheckerInterface::class);
264
        
265
        $user = $this->getMockWithoutConstructor(UserInterface::class);
266
        $user
267
            ->method('getRoles')
268
            ->willReturn([
269
                'ROLE_USER',
270
            ])
271
        ;
272
        
273
        $token = $this->getMockWithoutConstructor(TokenInterface::class);
274
        $token
275
            ->expects($this->once())
276
            ->method('getUser')
277
            ->willReturn($user)
278
        ;
279
        $tokenStorage = $this->getMockWithoutConstructor(TokenStorageInterface::class);
280
        $tokenStorage
281
            ->expects($this->once())
282
            ->method('getToken')
283
            ->willReturn($token)
284
        ;
285
        $action = $this->getMockWithoutConstructor(ActionInterface::class);
286
        $entityLoader = $this->getMockWithoutConstructor(EntityLoaderInterface::class);
287
        $viewFactory = $this->getMockWithoutConstructor(ViewFactory::class);
288
        $requestHandler = $this->getMockWithoutConstructor(RequestHandlerInterface::class);
289
        
290
        $admin = new Admin(
291
            'my_little_pony',
0 ignored issues
show
Documentation introduced by
'my_little_pony' is of type string, but the function expects a object<LAG\AdminBundle\Resource\AdminResource>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
292
            $entityLoader,
0 ignored issues
show
Documentation introduced by
$entityLoader is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<LAG\AdminBundle\C...ion\AdminConfiguration>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
293
            $configuration,
0 ignored issues
show
Documentation introduced by
$configuration is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...entDispatcherInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
294
            $messageHandler,
0 ignored issues
show
Unused Code introduced by
The call to Admin::__construct() has too many arguments starting with $messageHandler.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
295
            $eventDispatcher,
296
            $authorizationChecker,
297
            $tokenStorage,
298
            $requestHandler,
299
            $viewFactory,
300
            [
301
                'list' => $action,
302
            ]
303
        );
304
        
305
        $this->assertExceptionRaised(LogicException::class, function() use ($admin) {
306
            $admin->checkPermissions();
0 ignored issues
show
Bug introduced by
The method checkPermissions() does not seem to exist on object<LAG\AdminBundle\Admin\Admin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
307
        });
308
    }
309
    
310
    /**
311
     * A security exception should be raised if the user is not granted.
312
     */
313
    public function testCheckPermissionsNonGranted()
314
    {
315
        $configuration = $this->getMockWithoutConstructor(AdminConfiguration::class);
316
        $messageHandler = $this->getMockWithoutConstructor(MessageHandlerInterface::class);
317
        $eventDispatcher = $this->getMockWithoutConstructor(EventDispatcherInterface::class);
318
        
319
        $authorizationChecker = $this->getMockWithoutConstructor(AuthorizationCheckerInterface::class);
320
        $authorizationChecker
321
            ->expects($this->once())
322
            ->method('isGranted')
323
            ->willReturn(false)
324
        ;
325
        
326
        $user = $this->getMockWithoutConstructor(UserInterface::class);
327
        $user
328
            ->method('getRoles')
329
            ->willReturn([
330
                'ROLE_USER',
331
            ])
332
        ;
333
        
334
        $token = $this->getMockWithoutConstructor(TokenInterface::class);
335
        $token
336
            ->expects($this->once())
337
            ->method('getUser')
338
            ->willReturn($user)
339
        ;
340
        $tokenStorage = $this->getMockWithoutConstructor(TokenStorageInterface::class);
341
        $tokenStorage
342
            ->expects($this->once())
343
            ->method('getToken')
344
            ->willReturn($token)
345
        ;
346
        $actionConfiguration = $this->getMockWithoutConstructor(ActionConfiguration::class);
347
        $action = $this->getMockWithoutConstructor(ActionInterface::class);
348
        $action
349
            ->expects($this->once())
350
            ->method('getConfiguration')
351
            ->willReturn($actionConfiguration)
352
        ;
353
        
354
        $entityLoader = $this->getMockWithoutConstructor(EntityLoaderInterface::class);
355
    
356
        $view = $this->getMockWithoutConstructor(ViewInterface::class);
357
        
358
        $viewFactory = $this->getMockWithoutConstructor(ViewFactory::class);
359
        $viewFactory
360
            ->expects($this->once())
361
            ->method('create')
362
            ->with('list', 'my_little_pony', $configuration, $actionConfiguration)
363
            ->willReturn($view)
364
        ;
365
    
366
        $request = new Request([], [], [
367
            '_route_params' => [
368
                '_admin' => 'my_little_pony',
369
                '_action' => 'list',
370
            ]
371
        ]);
372
        $requestHandler = $this->getMockWithoutConstructor(RequestHandlerInterface::class);
373
        $requestHandler
374
            ->expects($this->once())
375
            ->method('supports')
376
            ->with($request)
377
            ->willReturn(true)
378
        ;
379
        
380
        $admin = new Admin(
381
            'my_little_pony',
0 ignored issues
show
Documentation introduced by
'my_little_pony' is of type string, but the function expects a object<LAG\AdminBundle\Resource\AdminResource>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
382
            $entityLoader,
0 ignored issues
show
Documentation introduced by
$entityLoader is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<LAG\AdminBundle\C...ion\AdminConfiguration>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
383
            $configuration,
0 ignored issues
show
Documentation introduced by
$configuration is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...entDispatcherInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
384
            $messageHandler,
0 ignored issues
show
Unused Code introduced by
The call to Admin::__construct() has too many arguments starting with $messageHandler.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
385
            $eventDispatcher,
386
            $authorizationChecker,
387
            $tokenStorage,
388
            $requestHandler,
389
            $viewFactory,
390
            [
391
                'list' => $action,
392
            ]
393
        );
394
        
395
        $this->assertExceptionRaised(AccessDeniedException::class, function() use ($admin, $request) {
396
            $admin->handleRequest($request);
397
        });
398
    }
399
    
400
    /**
401
     * A security exception should be raised if the user is not granted.
402
     */
403
    public function testCheckPermissionsNonGrantedForAction()
404
    {
405
        $configuration = $this->getMockWithoutConstructor(AdminConfiguration::class);
406
        $configuration
407
            ->method('getParameter')
408
            ->willReturnMap([
409
                ['permissions', [
410
                    'ROLE_USER',
411
                ]],
412
            ])
413
        ;
414
        $messageHandler = $this->getMockWithoutConstructor(MessageHandlerInterface::class);
415
        $eventDispatcher = $this->getMockWithoutConstructor(EventDispatcherInterface::class);
416
        $i = 0;
417
        
418
        $authorizationChecker = $this->getMockWithoutConstructor(AuthorizationCheckerInterface::class);
419
        $authorizationChecker
420
            ->expects($this->exactly(2))
421
            ->method('isGranted')
422
            ->willReturnCallback(function () use (&$i) {
423
                $i++;
424
    
425
                return $i <= 1;
426
            })
427
        ;
428
        $user = $this->getMockWithoutConstructor(UserInterface::class);
429
        $user
430
            ->method('getRoles')
431
            ->willReturn([
432
                'ROLE_USER',
433
            ])
434
        ;
435
        $token = $this->getMockWithoutConstructor(TokenInterface::class);
436
        $token
437
            ->expects($this->once())
438
            ->method('getUser')
439
            ->willReturn($user)
440
        ;
441
        $tokenStorage = $this->getMockWithoutConstructor(TokenStorageInterface::class);
442
        $tokenStorage
443
            ->expects($this->once())
444
            ->method('getToken')
445
            ->willReturn($token)
446
        ;
447
    
448
        $actionConfiguration = $this->getMockWithoutConstructor(ActionConfiguration::class);
449
        $action = $this->getMockWithoutConstructor(ActionInterface::class);
450
        $action
451
            ->expects($this->once())
452
            ->method('getConfiguration')
453
            ->willReturn($actionConfiguration)
454
        ;
455
    
456
        $entityLoader = $this->getMockWithoutConstructor(EntityLoaderInterface::class);
457
    
458
        $view = $this->getMockWithoutConstructor(ViewInterface::class);
459
        $view
460
            ->expects($this->once())
461
            ->method('getConfiguration')
462
            ->willReturn($actionConfiguration)
463
        ;
464
        
465
        $viewFactory = $this->getMockWithoutConstructor(ViewFactory::class);
466
        $viewFactory
467
            ->expects($this->once())
468
            ->method('create')
469
            ->with('list', 'my_little_pony', $configuration, $actionConfiguration)
470
            ->willReturn($view)
471
        ;
472
    
473
        $request = new Request([], [], [
474
            '_route_params' => [
475
                '_admin' => 'my_little_pony',
476
                '_action' => 'list',
477
            ]
478
        ]);
479
        $requestHandler = $this->getMockWithoutConstructor(RequestHandlerInterface::class);
480
        $requestHandler
481
            ->expects($this->once())
482
            ->method('supports')
483
            ->with($request)
484
            ->willReturn(true)
485
        ;
486
        
487
        $admin = new Admin(
488
            'my_little_pony',
0 ignored issues
show
Documentation introduced by
'my_little_pony' is of type string, but the function expects a object<LAG\AdminBundle\Resource\AdminResource>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
489
            $entityLoader,
0 ignored issues
show
Documentation introduced by
$entityLoader is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<LAG\AdminBundle\C...ion\AdminConfiguration>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
490
            $configuration,
0 ignored issues
show
Documentation introduced by
$configuration is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...entDispatcherInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
491
            $messageHandler,
0 ignored issues
show
Unused Code introduced by
The call to Admin::__construct() has too many arguments starting with $messageHandler.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
492
            $eventDispatcher,
493
            $authorizationChecker,
494
            $tokenStorage,
495
            $requestHandler,
496
            $viewFactory,
497
            [
498
                'list' => $action,
499
            ]
500
        );
501
    
502
        $this->assertExceptionRaised(AccessDeniedException::class, function() use ($admin, $request) {
503
            $admin->handleRequest($request);
504
            $admin->checkPermissions();
0 ignored issues
show
Bug introduced by
The method checkPermissions() does not seem to exist on object<LAG\AdminBundle\Admin\Admin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
505
        });
506
    }
507
    
508
    public function testCreate()
509
    {
510
        $configuration = $this->getMockWithoutConstructor(AdminConfiguration::class);
511
        $messageHandler = $this->getMockWithoutConstructor(MessageHandlerInterface::class);
512
        $eventDispatcher = $this->getMockWithoutConstructor(EventDispatcherInterface::class);
513
        $authorizationChecker = $this->getMockWithoutConstructor(AuthorizationCheckerInterface::class);
514
        $tokenStorage = $this->getMockWithoutConstructor(TokenStorageInterface::class);
515
    
516
        $entity = new TestSimpleEntity();
517
        
518
        $dataProvider = $this->getMockWithoutConstructor(DataProviderInterface::class);
519
        $dataProvider
520
            ->expects($this->once())
521
            ->method('create')
522
            ->willReturn($entity)
523
        ;
524
    
525
        $entityLoader = $this->getMockWithoutConstructor(EntityLoaderInterface::class);
526
        $entityLoader
527
            ->expects($this->atLeastOnce())
528
            ->method('getDataProvider')
529
            ->willReturn($dataProvider)
530
        ;
531
        
532
        $viewFactory = $this->getMockWithoutConstructor(ViewFactory::class);
533
        $requestHandler = $this->getMockWithoutConstructor(RequestHandlerInterface::class);
534
    
535
        $admin = new Admin(
536
            'my_little_pony',
0 ignored issues
show
Documentation introduced by
'my_little_pony' is of type string, but the function expects a object<LAG\AdminBundle\Resource\AdminResource>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
537
            $entityLoader,
0 ignored issues
show
Documentation introduced by
$entityLoader is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<LAG\AdminBundle\C...ion\AdminConfiguration>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
538
            $configuration,
0 ignored issues
show
Documentation introduced by
$configuration is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...entDispatcherInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
539
            $messageHandler,
0 ignored issues
show
Unused Code introduced by
The call to Admin::__construct() has too many arguments starting with $messageHandler.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
540
            $eventDispatcher,
541
            $authorizationChecker,
542
            $tokenStorage,
543
            $requestHandler,
544
            $viewFactory
545
        );
546
        $created = $admin->create();
0 ignored issues
show
Bug introduced by
The method create() does not exist on LAG\AdminBundle\Admin\Admin. Did you maybe mean createView()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
547
    
548
        $this->assertEquals($created, $entity);
549
        $this->assertEquals($entity, $admin->getEntities()->first());
0 ignored issues
show
Bug introduced by
The method first cannot be called on $admin->getEntities() (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
550
        $this->assertCount(1, $admin->getEntities());
551
    }
552
    
553 View Code Duplication
    public function testSave()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
554
    {
555
        $configuration = $this->getMockWithoutConstructor(AdminConfiguration::class);
556
        $eventDispatcher = $this->getMockWithoutConstructor(EventDispatcherInterface::class);
557
        $authorizationChecker = $this->getMockWithoutConstructor(AuthorizationCheckerInterface::class);
558
        $tokenStorage = $this->getMockWithoutConstructor(TokenStorageInterface::class);
559
        
560
        $messageHandler = $this->getMockWithoutConstructor(MessageHandlerInterface::class);
561
        $messageHandler
562
            ->expects($this->once())
563
            ->method('handleSuccess')
564
        ;
565
    
566
        $dataProvider = $this->getMockWithoutConstructor(DataProviderInterface::class);
567
        $dataProvider
568
            ->expects($this->exactly(2))
569
            ->method('save')
570
        ;
571
    
572
        $entityLoader = $this->getMockWithoutConstructor(EntityLoaderInterface::class);
573
        $entityLoader
574
            ->method('getDataProvider')
575
            ->willReturn($dataProvider)
576
        ;
577
    
578
        $viewFactory = $this->getMockWithoutConstructor(ViewFactory::class);
579
        $requestHandler = $this->getMockWithoutConstructor(RequestHandlerInterface::class);
580
        
581
        $admin = new Admin(
582
            'my_little_pony',
0 ignored issues
show
Documentation introduced by
'my_little_pony' is of type string, but the function expects a object<LAG\AdminBundle\Resource\AdminResource>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
583
            $entityLoader,
0 ignored issues
show
Documentation introduced by
$entityLoader is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<LAG\AdminBundle\C...ion\AdminConfiguration>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
584
            $configuration,
0 ignored issues
show
Documentation introduced by
$configuration is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...entDispatcherInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
585
            $messageHandler,
0 ignored issues
show
Unused Code introduced by
The call to Admin::__construct() has too many arguments starting with $messageHandler.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
586
            $eventDispatcher,
587
            $authorizationChecker,
588
            $tokenStorage,
589
            $requestHandler,
590
            $viewFactory
591
        );
592
        $entities[] = $admin->create();
0 ignored issues
show
Coding Style Comprehensibility introduced by
$entities was never initialized. Although not strictly required by PHP, it is generally a good practice to add $entities = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
Bug introduced by
The method create() does not exist on LAG\AdminBundle\Admin\Admin. Did you maybe mean createView()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
593
        $entities[] = $admin->create();
0 ignored issues
show
Bug introduced by
The method create() does not exist on LAG\AdminBundle\Admin\Admin. Did you maybe mean createView()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
594
        $admin->save();
0 ignored issues
show
Bug introduced by
The method save() does not seem to exist on object<LAG\AdminBundle\Admin\Admin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
595
    }
596
    
597 View Code Duplication
    public function testRemove()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
598
    {
599
        $configuration = $this->getMockWithoutConstructor(AdminConfiguration::class);
600
        $eventDispatcher = $this->getMockWithoutConstructor(EventDispatcherInterface::class);
601
        $authorizationChecker = $this->getMockWithoutConstructor(AuthorizationCheckerInterface::class);
602
        $tokenStorage = $this->getMockWithoutConstructor(TokenStorageInterface::class);
603
        
604
        $messageHandler = $this->getMockWithoutConstructor(MessageHandlerInterface::class);
605
        $messageHandler
606
            ->expects($this->once())
607
            ->method('handleSuccess')
608
        ;
609
        
610
        $dataProvider = $this->getMockWithoutConstructor(DataProviderInterface::class);
611
        $dataProvider
612
            ->expects($this->exactly(2))
613
            ->method('remove')
614
        ;
615
    
616
        $entityLoader = $this->getMockWithoutConstructor(EntityLoaderInterface::class);
617
        $entityLoader
618
            ->method('getDataProvider')
619
            ->willReturn($dataProvider)
620
        ;
621
    
622
        $viewFactory = $this->getMockWithoutConstructor(ViewFactory::class);
623
        $requestHandler = $this->getMockWithoutConstructor(RequestHandlerInterface::class);
624
        
625
        $admin = new Admin(
626
            'my_little_pony',
0 ignored issues
show
Documentation introduced by
'my_little_pony' is of type string, but the function expects a object<LAG\AdminBundle\Resource\AdminResource>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
627
            $entityLoader,
0 ignored issues
show
Documentation introduced by
$entityLoader is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<LAG\AdminBundle\C...ion\AdminConfiguration>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
628
            $configuration,
0 ignored issues
show
Documentation introduced by
$configuration is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...entDispatcherInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
629
            $messageHandler,
0 ignored issues
show
Unused Code introduced by
The call to Admin::__construct() has too many arguments starting with $messageHandler.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
630
            $eventDispatcher,
631
            $authorizationChecker,
632
            $tokenStorage,
633
            $requestHandler,
634
            $viewFactory
635
        );
636
        $entities[] = $admin->create();
0 ignored issues
show
Coding Style Comprehensibility introduced by
$entities was never initialized. Although not strictly required by PHP, it is generally a good practice to add $entities = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
Bug introduced by
The method create() does not exist on LAG\AdminBundle\Admin\Admin. Did you maybe mean createView()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
637
        $entities[] = $admin->create();
0 ignored issues
show
Bug introduced by
The method create() does not exist on LAG\AdminBundle\Admin\Admin. Did you maybe mean createView()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
638
        $admin->remove();
0 ignored issues
show
Bug introduced by
The method remove() does not seem to exist on object<LAG\AdminBundle\Admin\Admin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
639
    }
640
    
641
    public function testLoad()
642
    {
643
        $configuration = $this->getMockWithoutConstructor(AdminConfiguration::class);
644
        $messageHandler = $this->getMockWithoutConstructor(MessageHandlerInterface::class);
645
        $eventDispatcher = $this->getMockWithoutConstructor(EventDispatcherInterface::class);
646
        $authorizationChecker = $this->getMockWithoutConstructor(AuthorizationCheckerInterface::class);
647
        $tokenStorage = $this->getMockWithoutConstructor(TokenStorageInterface::class);
648
    
649
        $entityLoader = $this->getMockWithoutConstructor(EntityLoaderInterface::class);
650
        $entityLoader
651
            ->method('load')
652
            ->with([
653
                'deleted' => false,
654
            ], [
655
                'createdAt' => 'desc',
656
            ], 52, 3)
657
            ->willReturn([])
658
        ;
659
        
660
        $view = $this->getMockWithoutConstructor(ViewInterface::class);
661
        $view
662
            ->expects($this->once())
663
            ->method('setEntities')
664
            ->with(new ArrayCollection())
665
        ;
666
        $viewFactory = $this->getMockWithoutConstructor(ViewFactory::class);
667
        $requestHandler = $this->getMockWithoutConstructor(RequestHandlerInterface::class);
668
        $action = $this->getMockWithoutConstructor(ActionInterface::class);
669
        
670
        $admin = new Admin(
671
            'my_little_pony',
0 ignored issues
show
Documentation introduced by
'my_little_pony' is of type string, but the function expects a object<LAG\AdminBundle\Resource\AdminResource>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
672
            $entityLoader,
0 ignored issues
show
Documentation introduced by
$entityLoader is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<LAG\AdminBundle\C...ion\AdminConfiguration>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
673
            $configuration,
0 ignored issues
show
Documentation introduced by
$configuration is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...entDispatcherInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
674
            $messageHandler,
0 ignored issues
show
Unused Code introduced by
The call to Admin::__construct() has too many arguments starting with $messageHandler.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
675
            $eventDispatcher,
676
            $authorizationChecker,
677
            $tokenStorage,
678
            $requestHandler,
679
            $viewFactory,
680
            [
681
                'list' => $action,
682
            ]
683
        );
684
        
685
        $reflection = new \ReflectionClass($admin);
686
        $property = $reflection->getProperty('view');
687
        $property->setAccessible(true);
688
        $property->setValue($admin, $view);
689
    
690
        $admin->load([
0 ignored issues
show
Bug introduced by
The method load() does not seem to exist on object<LAG\AdminBundle\Admin\Admin>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
691
            'deleted' => false,
692
        ], [
693
            'createdAt' => 'desc',
694
        ], 52, 3);
695
    }
696
}
697