Completed
Pull Request — develop (#311)
by
unknown
17:12
created

CollectionFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 39
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A createCollectionClass() 0 13 3
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de)
7
 * @license   MIT
8
 * @author Miroslav Fedeleš <[email protected]>
9
 * @since 0.28
10
 */
11
namespace Core\Repository\DoctrineMongoODM;
12
13
use Doctrine\ODM\MongoDB\PersistentCollection\AbstractPersistentCollectionFactory;
14
use Core\Repository\RepositoryService;
15
use Core\Entity\Collection\AttachedEntitiesCollection;
16
17
class CollectionFactory extends AbstractPersistentCollectionFactory
18
{
19
    
20
    /**
21
     * @var callable
22
     */
23
    protected $repositoriesFactory;
24
    
25
    /**
26
     * @var RepositoryService
27
     */
28
    protected $repositories;
29
    
30
    /**
31
     * @param RepositoryService $repositories
0 ignored issues
show
Documentation introduced by
There is no parameter named $repositories. Did you maybe mean $repositoriesFactory?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

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

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

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

Loading history...
32
     */
33
    public function __construct(callable $repositoriesFactory)
34
    {
35
        $this->repositoriesFactory = $repositoriesFactory;
36
    }
37
38
    /**
39
     * {@inheritDoc}
40
     * @see \Doctrine\ODM\MongoDB\PersistentCollection\AbstractPersistentCollectionFactory::createCollectionClass()
41
     */
42
    protected function createCollectionClass($collectionClass)
43
    {
44
        switch ($collectionClass) {
45
            case AttachedEntitiesCollection::class:
46
                if (!isset($this->repositories)) {
47
                    $repositoriesFactory = $this->repositoriesFactory;
48
                    $this->repositories = $repositoriesFactory();
49
                }
50
                return new $collectionClass($this->repositories);
51
            default:
52
                return new $collectionClass();
53
        }
54
    }
55
}
56