Completed
Pull Request — master (#10)
by
unknown
05:39 queued 02:04
created

UserRepositoryCollection   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A all() 0 4 1
A findRepositoryByClassName() 0 10 3
A addUserRepository() 0 4 1
1
<?php
2
3
namespace SumoCoders\FrameworkMultiUserBundle\User;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use SumoCoders\FrameworkMultiUserBundle\Exception\RepositoryNotRegisteredException;
7
8
class UserRepositoryCollection
9
{
10
    /**
11
     * @var array
12
     */
13
    private $userRepositories;
14
15
    /**
16
     * UserRepositoryCollection constructor.
17
     *
18
     * @param array $userRepositories
19
     */
20
    public function __construct(array $userRepositories)
21
    {
22
        $this->userRepositories = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Doctrine\Common\Collections\ArrayCollection() of type object<Doctrine\Common\C...ctions\ArrayCollection> is incompatible with the declared type array of property $userRepositories.

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...
23
        foreach ($userRepositories as $repository) {
24
            $this->addUserRepository($repository);
25
        }
26
    }
27
28
    /**
29
     * Registers the UserRepository to the UserRepositoryCollection.
30
     *
31
     * @param UserRepository $userRepository
32
     */
33
    public function addUserRepository(UserRepository $userRepository)
34
    {
35
        $this->userRepositories[] = $userRepository;
36
    }
37
38
    /**
39
     * Get the userRepositories.
40
     *
41
     * @return array
42
     */
43
    public function all()
44
    {
45
        return $this->userRepositories;
46
    }
47
48
    /**
49
     * Find the UserRepository for a given User Class.
50
     *
51
     * @param $className
52
     *
53
     * @throws RepositoryNotRegisteredException
54
     *
55
     * @return UserRepository
56
     */
57
    public function findRepositoryByClassName($className)
58
    {
59
        foreach ($this->userRepositories as $repository) {
60
            if ($repository->supportsClass($className)) {
61
                return $repository;
62
            }
63
        }
64
65
        throw RepositoryNotRegisteredException::withClassName($className);
66
    }
67
}
68