Failed Conditions
Pull Request — experimental/3.1 (#2532)
by Kentaro
34:08 queued 17:05
created

SchemaService   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 44
ccs 0
cts 23
cp 0
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B updateSchema() 0 34 4
1
<?php
2
/*
3
 * This file is part of EC-CUBE
4
 *
5
 * Copyright(c) 2000-2017 LOCKON CO.,LTD. All Rights Reserved.
6
 *
7
 * http://www.lockon.co.jp/
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 */
23
24
namespace Eccube\Service;
25
use Doctrine\Common\Annotations\AnnotationReader;
26
use Doctrine\ORM\EntityManager;
27
use Doctrine\ORM\Tools\SchemaTool;
28
use Eccube\Annotation\Inject;
29
use Eccube\Annotation\Service;
30
use Eccube\Doctrine\ORM\Mapping\Driver\ReloadSafeAnnotationDriver;
31
use Eccube\Util\Str;
32
33
/**
34
 * @Service
35
 */
36
class SchemaService
37
{
38
39
    /**
40
     * @Inject("orm.em")
41
     * @var EntityManager
42
     */
43
    protected $entityManager;
44
45
    public function updateSchema($generatedFiles)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
46
    {
47
        $outputDir = sys_get_temp_dir() . '/proxy_' . Str::random(12);
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
48
        mkdir($outputDir);
49
50
        try {
51
            $chain = $this->entityManager->getConfiguration()->getMetadataDriverImpl();
52
            $drivers = $chain->getDrivers();
53
            foreach ($drivers as $namespace => $oldDriver) {
54
                if ('Eccube\Entity' === $namespace) {
55
                    $newDriver = new ReloadSafeAnnotationDriver(
56
                        new AnnotationReader(),
57
                        $oldDriver->getPaths()
58
                    );
59
                    $newDriver->setFileExtension($oldDriver->getFileExtension());
60
                    $newDriver->addExcludePaths($oldDriver->getExcludePaths());
61
                    $newDriver->setTraitProxiesDirectory(realpath(__DIR__.'/../../../app/proxy/entity'));
62
                    $newDriver->setNewProxyFiles($generatedFiles);
63
                    $newDriver->setOutputDir($outputDir);
64
                    $chain->addDriver($newDriver, $namespace);
65
                }
66
            }
67
68
            $tool = new SchemaTool($this->entityManager);
69
            $metaData = $this->entityManager->getMetadataFactory()->getAllMetadata();
70
            $tool->updateSchema($metaData, true);
71
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
72
        } finally {
73
            foreach (glob("${outputDir}/*") as  $f) {
0 ignored issues
show
Coding Style introduced by
There should be 1 space after "as" as per the coding-style, but found 2.
Loading history...
74
                unlink($f);
75
            }
76
            rmdir($outputDir);
77
        }
78
    }
79
}