Completed
Pull Request — develop (#274)
by
unknown
09:44
created

RemoveController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 45
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A factory() 0 6 1
A __construct() 0 4 1
A indexAction() 0 18 3
1
<?php
2
/**
3
 * @filesource
4
 * @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de)
5
 * @license MIT
6
 * @author Miroslav Fedeleš <[email protected]>
7
 * @since 0.27
8
 */
9
namespace Auth\Controller;
10
11
use Zend\Mvc\Controller\AbstractActionController;
12
use Zend\Mvc\Controller\ControllerManager;
13
use Auth\Dependency\ModuleManager as Dependencies;
14
15
class RemoveController extends AbstractActionController
16
{
17
    /**
18
     * @var Dependencies
19
     */
20
    protected $dependencies;
21
22
    /**
23
     * @param ControllerManager $controllerManager
24
     * @return \Auth\Controller\RemoveController
25
     */
26
    public static function factory(ControllerManager $controllerManager)
27
    {
28
        $serviceManager = $controllerManager->getServiceLocator();
29
        
30
        return new static($serviceManager->get('Auth/Dependency/ModuleManager'));
0 ignored issues
show
Documentation introduced by
$serviceManager->get('Au...endency/ModuleManager') is of type object|array, but the function expects a object<Auth\Dependency\ModuleManager>.

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...
31
    }
32
    
33
    /**
34
     * @param Dependencies $dependencies
35
     */
36
    public function __construct(Dependencies $dependencies)
37
    {
38
        $this->dependencies = $dependencies;
39
    }
40
41
    public function indexAction()
42
    {
43
        $user = $this->serviceLocator->get('AuthenticationService')->getUser();
44
        
45
        if ($this->params()->fromPost('confirm'))
46
        {
47
            foreach ($this->dependencies as $dependency) /* @var $dependency \Auth\Dependency\ModuleInterface */
48
            {
49
                $dependency->removeItems($user);
50
            }
51
        }
52
        
53
        return [
54
            'dependencies' => $this->dependencies,
55
            'user' => $user,
56
            'router' => $this->getEvent()->getRouter()
57
        ];
58
    }
59
}
60