GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

TestCase::createEntitySchema()   B
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 24
rs 8.5125
cc 5
eloc 14
nc 5
nop 2
1
<?php
2
/*
3
 * This file is part of the prooph/php-ddd-cargo-sample package.
4
 * (c) Alexander Miertsch <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
namespace CodelinerTest\CargoBackend;
10
11
use Codeliner\CargoBackend\Infrastructure\Persistence\Doctrine\Type\LegsDoctrineType;
12
use Codeliner\CargoBackend\Infrastructure\Persistence\Doctrine\Type\TrackingIdDoctrineType;
13
use PHPUnit_Framework_TestCase;
14
use Doctrine\ORM\EntityManager;
15
use Doctrine\DBAL\Types\Type;
16
/**
17
 *  TestCase
18
 * 
19
 * @author Alexander Miertsch <[email protected]>
20
 */
21
class TestCase extends PHPUnit_Framework_TestCase
22
{
23
    protected $entityManager;
24
    protected $schemaTool;
25
    
26
    /**
27
     *
28
     * @return EntityManager
29
     */
30
    public function getTestEntityManager()
31
    {
32
        if (null === $this->entityManager) {
33
            $conn = \Doctrine\DBAL\DriverManager::getConnection(array(
0 ignored issues
show
Unused Code introduced by
$conn is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
34
                'driver' => 'pdo_sqlite',
35
                'dbname' => ':memory:'
36
            ));
37
38
            $config = new \Doctrine\ORM\Configuration();
39
40
            $config->setAutoGenerateProxyClasses(true);
41
            $config->setProxyDir(\sys_get_temp_dir());
42
            $config->setProxyNamespace(get_class($this) . '\Entities');
43
            $config->setMetadataDriverImpl(
44
                new \Doctrine\ORM\Mapping\Driver\XmlDriver(
45
                    array(
46
                        __DIR__ . '/../src/Infrastructure/Persistence/Doctrine/ORM'
47
                    )
48
                )
49
            );
50
            
51
            $config->setNamingStrategy(new \Doctrine\ORM\Mapping\UnderscoreNamingStrategy());
52
53
            $config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
54
            $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
55
            
56
            $this->entityManager = \Doctrine\ORM\EntityManager::create(array(
57
                'driver' => 'pdo_sqlite',
58
                'memory' => true
59
            ), $config);
60
            
61
            //Add custom DDD types to map ValueObjects correctly
62
            if (!Type::hasType('cargo_itinerary_legs')) {
63
                Type::addType('cargo_itinerary_legs', LegsDoctrineType::class);
64
            }
65
66
            if (!Type::hasType('cargo_tracking_id')) {
67
                Type::addType('cargo_tracking_id', TrackingIdDoctrineType::class);
68
            }
69
        }
70
        
71
        
72
        return $this->entityManager;
73
    }
74
75
    public function createEntitySchema($entityNameOrNamespace, $pathToEntityDir = null)
76
    {
77
        if (!is_null($pathToEntityDir)) {
78
            $dir = opendir($pathToEntityDir);
79
80
            $entityNameOrNamespace = trim($entityNameOrNamespace, '\\');
81
82
            while($file = readdir($dir)) {
83
                if (0 !== strpos($file, '.')) {
84
                    $entityClass = $entityNameOrNamespace . '\\' . str_replace('.php', '', $file);
85
                    $this->createEntitySchema($entityClass);
86
                }
87
            }
88
89
            return;
90
        }
91
92
        if (null === $this->schemaTool) {
93
            $this->schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->getTestEntityManager());
94
        }
95
        $schema = $this->getTestEntityManager()->getClassMetadata($entityNameOrNamespace);
96
        $this->schemaTool->dropSchema(array($schema));
97
        $this->schemaTool->createSchema(array($schema));
98
    }
99
}
100