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

ORMDataLoader   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 32
ccs 12
cts 13
cp 0.9231
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 3 1
A __construct() 0 3 1
A createExecutor() 0 12 4
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