Completed
Pull Request — master (#20)
by Eric
02:44
created

AliceODMContext::getDocumentManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Fidry\AliceBundleExtension package.
5
 *
6
 * (c) Théo FIDRY <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Fidry\AliceBundleExtension\Context\Doctrine;
13
14
use Doctrine\ODM\MongoDB\DocumentManager;
15
use Doctrine\ODM\MongoDB\SchemaManager;
16
17
/**
18
 * Context to load fixtures files with Alice loader.
19
 *
20
 * @author Théo FIDRY <[email protected]>
21
 */
22
class AliceODMContext extends AbstractAliceContext
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function createSchema()
28
    {
29
        $schemaManager = $this->getSchemaManager();
30
31
        $schemaManager->createCollections();
32
        $schemaManager->ensureIndexes();
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function dropSchema()
39
    {
40
        $schemaManager = $this->getSchemaManager();
41
42
        $schemaManager->deleteIndexes();
43
        $schemaManager->dropCollections();
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function emptyDatabase()
50
    {
51
        $this->dropSchema();
52
        $this->createSchema();
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    protected function getPersister()
59
    {
60
        return $this->resolvePersister($this->getDocumentManager());
0 ignored issues
show
Documentation introduced by
$this->getDocumentManager() is of type object<Doctrine\ODM\MongoDB\DocumentManager>, but the function expects a object<Nelmio\Alice\PersisterInterface>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    protected function getFixturesFinder()
67
    {
68
        return $this->kernel->getContainer()->get('hautelook_alice.doctrine.mongodb.fixtures_finder');
69
    }
70
71
    /**
72
     * @return SchemaManager
73
     */
74
    private function getSchemaManager()
75
    {
76
        return $this->getDocumentManager()->getSchemaManager();
77
    }
78
79
    /**
80
     * @return DocumentManager
81
     */
82
    private function getDocumentManager()
83
    {
84
        return $this->kernel->getContainer()->get('doctrine_mongodb.odm.default_document_manager');
85
    }
86
}
87