Completed
Push — develop ( 031ed9...9561de )
by
unknown
09:21
created

Manager   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 7
c 3
b 0
f 2
lcom 1
cbo 4
dl 0
loc 59
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getLists() 0 4 1
A removeItems() 0 11 2
A attachDefaultListeners() 0 11 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\Dependency;
10
11
use Zend\EventManager\EventManagerAwareTrait;
12
use Zend\EventManager\EventInterface;
13
use Auth\Entity\UserInterface as User;
14
use Zend\Mvc\Router\RouteInterface as Router;
15
use Doctrine\ODM\MongoDB\DocumentManager;
16
17
/**
18
 *
19
 * @author Miroslav Fedeleš <[email protected]>
20
 * @author Mathias Gelhausen <[email protected]>
21
 * @since 0.27
22
 */
23
class Manager
24
{
25
    use EventManagerAwareTrait;
26
    
27
    const EVENT_GET_LISTS = 'getLists';
28
    const EVENT_REMOVE_ITEMS = 'removeItems';
29
30
    /**
31
     * @var DocumentManager
32
     */
33
    protected $documentManager;
34
    
35
    /**
36
     * @param DocumentManager $documentManager
37
     */
38
    public function __construct(DocumentManager $documentManager)
39
    {
40
        $this->documentManager = $documentManager;
41
    }
42
    
43
    /**
44
     * @param User $user
0 ignored issues
show
Bug introduced by
There is no parameter named $user. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
45
     * @param Router $router
0 ignored issues
show
Bug introduced by
There is no parameter named $router. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
46
     * @return ListInterface[]
0 ignored issues
show
Documentation introduced by
Should the return type not be \Zend\EventManager\ResponseCollection?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
47
     */
48
    public function getLists()
49
    {
50
        return $this->getEventManager()->trigger(static::EVENT_GET_LISTS, $this);
51
    }
52
 
53
    /**
54
     * @param User $user
55
     * @param Router $router
0 ignored issues
show
Bug introduced by
There is no parameter named $router. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
56
     * @return \Zend\EventManager\ResponseCollection
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
57
     */
58
    public function removeItems(User $user)
0 ignored issues
show
Coding Style introduced by
function removeItems() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
59
    {
60
        try {
61
            $this->getEventManager()->trigger(static::EVENT_REMOVE_ITEMS, $this, compact('user'));
62
            $this->documentManager->flush();
63
            return true;
64
        } catch (\Exception $e) {
65
            $this->documentManager->clear();
66
            return false;
67
        }
68
    }
69
70
    protected function attachDefaultListeners()
71
    {
72
        $this->getEventManager()->attach(static::EVENT_REMOVE_ITEMS, function (EventInterface $event) {
73
            $user = $event->getParam('user');
74
            foreach ($this->getLists() as $list) {
75
                foreach ($list->getEntities($user) as $entity) {
76
                    $this->documentManager->remove($entity);
77
                }
78
            }
79
        });
80
    }
81
}
82