Completed
Pull Request — master (#1219)
by Maciej
10:59
created

AbstractPersistentCollectionFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 5
dl 0
loc 31
ccs 11
cts 11
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 17 4
createCollectionClass() 0 1 ?
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace Doctrine\ODM\MongoDB\PersistentCollection;
21
22
use Doctrine\Common\Collections\ArrayCollection;
23
use Doctrine\Common\Collections\Collection as BaseCollection;
24
use Doctrine\ODM\MongoDB\DocumentManager;
25
use Doctrine\ODM\MongoDB\PersistentCollection;
26
27
abstract class AbstractPersistentCollectionFactory implements PersistentCollectionFactory
28
{
29
    /**
30
     * {@inheritdoc}
31
     */
32 382
    public function create(DocumentManager $dm, array $mapping, BaseCollection $coll = null)
33
    {
34 382
        if ($coll === null) {
35 253
            $coll = ! empty($mapping['collectionClass'])
36 253
                ? $this->createCollectionClass($mapping['collectionClass'])
37 253
                : new ArrayCollection();
38 253
        }
39
40 382
        if (empty($mapping['collectionClass'])) {
41 382
            return new PersistentCollection($coll, $dm, $dm->getUnitOfWork());
42
        }
43
44 2
        $className = $dm->getConfiguration()->getPersistentCollectionGenerator()
45 2
            ->loadClass($mapping['collectionClass'], $dm->getConfiguration()->getAutoGeneratePersistentCollectionClasses());
46
47 2
        return new $className($coll, $dm, $dm->getUnitOfWork());
48
    }
49
50
    /**
51
     * Creates instance of collection class to be wrapped by PersistentCollection.
52
     *
53
     * @param string $collectionClass FQCN of class to instantiate
54
     * @return BaseCollection
55
     */
56
    abstract protected function createCollectionClass($collectionClass);
57
}
58