Completed
Pull Request — master (#20)
by Eric
03:18 queued 01:05
created

AliceORMContext::setKernel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A AliceORMContext::dropSchema() 0 4 1
A AliceORMContext::emptyDatabase() 0 5 1
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\ORM\EntityManagerInterface;
15
use Doctrine\ORM\Mapping\ClassMetadata;
16
use Doctrine\ORM\Tools\SchemaTool;
17
18
/**
19
 * Context to load fixtures files with Alice loader.
20
 *
21
 * @author Théo FIDRY <[email protected]>
22
 */
23
class AliceORMContext extends AbstractAliceContext
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function createSchema()
29
    {
30
        $this->getSchemaTool()->createSchema($this->getAllMetadatas());
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function dropSchema()
37
    {
38
        $this->getSchemaTool()->dropSchema($this->getAllMetadatas());
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function emptyDatabase()
45
    {
46
        $this->dropSchema();
47
        $this->createSchema();
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    protected function getPersister()
54
    {
55
        return $this->resolvePersister($this->getEntityManager());
0 ignored issues
show
Documentation introduced by
$this->getEntityManager() is of type object<Doctrine\ORM\EntityManagerInterface>, 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...
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    protected function getFixturesFinder()
62
    {
63
        return $this->kernel->getContainer()->get('hautelook_alice.doctrine.orm.fixtures_finder');
64
    }
65
66
    /**
67
     * @return SchemaTool
68
     */
69
    private function getSchemaTool()
70
    {
71
        return new SchemaTool($this->getEntityManager());
72
    }
73
74
    /**
75
     * @return ClassMetadata[]
76
     */
77
    private function getAllMetadatas()
78
    {
79
        return $this->getEntityManager()->getMetadataFactory()->getAllMetadata();
80
    }
81
82
    /**
83
     * @return EntityManagerInterface
84
     */
85
    private function getEntityManager()
86
    {
87
        return $this->kernel->getContainer()->get('doctrine.orm.entity_manager');
88
    }
89
}
90