Completed
Pull Request — master (#10)
by
unknown
02:53
created

UserRepositoryCollection::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 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->registerUserRepository($repository);
25
        }
26
    }
27
28
    /**
29
     * Registers the UserRepository to the UserRepositoryCollection.
30
     *
31
     * @param UserRepository $userRepository
32
     */
33
    public function registerUserRepository(UserRepository $userRepository)
34
    {
35
        $this->userRepositories->add($userRepository);
0 ignored issues
show
Bug introduced by
The method add cannot be called on $this->userRepositories (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...
36
    }
37
38
    /**
39
     * Get the userRepositories.
40
     *
41
     * @return ArrayCollection
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