Passed
Push — master ( 36097f...93304f )
by Rafael
03:14
created

ORMDataLoader::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
crap 1
1
<?php
2
/*******************************************************************************
3
 *  This file is part of the GraphQL Bundle package.
4
 *
5
 *  (c) YnloUltratech <[email protected]>
6
 *
7
 *  For the full copyright and license information, please view the LICENSE
8
 *  file that was distributed with this source code.
9
 ******************************************************************************/
10
11
namespace Ynlo\GraphQLBundle\Test\FixtureLoader\DataPopulator;
12
13
use Doctrine\Bundle\DoctrineBundle\Registry;
14
use Doctrine\Common\DataFixtures\Executor\AbstractExecutor;
15
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
16
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
17
use Doctrine\DBAL\Connection;
18
use Doctrine\DBAL\Driver;
19
20
/**
21
 * Class ORMDataLoader
22
 */
23
class ORMDataLoader implements DataLoaderInterface
24
{
25
    protected $cacheDir;
26
27 22
    public function __construct($cacheDir = null)
28
    {
29 22
        $this->cacheDir = $cacheDir;
30 22
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 22
    public function supports(Registry $registry): bool
36
    {
37 22
        return $registry->getName() === 'ORM';
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 22
    public function createExecutor(Registry $registry): AbstractExecutor
44
    {
45 22
        $om = $registry->getManager();
46 22
        $purger = new ORMPurger();
47
48 22
        if (($connection = $registry->getConnection())
49 22
            && $connection instanceof Connection
50 22
            && $connection->getDriver() instanceof Driver\AbstractSQLiteDriver) {
51 22
            return new SQLiteORMExecutor($om, $purger, $this->cacheDir);
52
        }
53
54
        return new ORMExecutor($om, $purger);
55
    }
56
}
57