Completed
Push — master ( 95608f...d78a07 )
by Andreas
14s queued 10s
created

AbstractPersistentCollectionFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 32
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
createCollectionClass() 0 1 ?
A create() 0 17 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ODM\MongoDB\PersistentCollection;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Collection as BaseCollection;
9
use Doctrine\ODM\MongoDB\DocumentManager;
10
use Doctrine\ODM\MongoDB\PersistentCollection;
11
12
/**
13
 * Abstract factory for creating persistent collection classes.
14
 */
15
abstract class AbstractPersistentCollectionFactory implements PersistentCollectionFactory
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20 421
    public function create(DocumentManager $dm, array $mapping, ?BaseCollection $coll = null) : PersistentCollectionInterface
21
    {
22 421
        if ($coll === null) {
23 247
            $coll = ! empty($mapping['collectionClass'])
24 6
                ? $this->createCollectionClass($mapping['collectionClass'])
25 247
                : new ArrayCollection();
26
        }
27
28 421
        if (empty($mapping['collectionClass'])) {
29 419
            return new PersistentCollection($coll, $dm, $dm->getUnitOfWork());
30
        }
31
32 7
        $className = $dm->getConfiguration()->getPersistentCollectionGenerator()
33 7
            ->loadClass($mapping['collectionClass'], $dm->getConfiguration()->getAutoGeneratePersistentCollectionClasses());
34
35 7
        return new $className($coll, $dm, $dm->getUnitOfWork());
36
    }
37
38
    /**
39
     * Creates instance of collection class to be wrapped by PersistentCollection.
40
     *
41
     * @param string $collectionClass FQCN of class to instantiate
42
     *
43
     * @return BaseCollection
44
     */
45
    abstract protected function createCollectionClass(string $collectionClass) : BaseCollection;
46
}
47