Completed
Push — 4.0 ( 268f2c...88f012 )
by Hideki
05:48 queued 10s
created

Doctrine/ORM/Mapping/Driver/AnnotationDriver.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.ec-cube.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Eccube\Doctrine\ORM\Mapping\Driver;
15
16
use Doctrine\Common\Persistence\Mapping\MappingException;
17
18
class AnnotationDriver extends \Doctrine\ORM\Mapping\Driver\AnnotationDriver
19
{
20
    protected $trait_proxies_directory;
21
22 1332
    public function setTraitProxiesDirectory($dir)
23
    {
24 1332
        $this->trait_proxies_directory = $dir;
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 13
    public function getAllClassNames()
31
    {
32 13
        if ($this->classNames !== null) {
33 4
            return $this->classNames;
34
        }
35
36 13
        if (!$this->paths) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->paths of type string[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
37
            throw MappingException::pathRequired();
38
        }
39
40 13
        $classes = [];
41 13
        $includedFiles = [];
42
43 13
        foreach ($this->paths as $path) {
44 13
            if (!is_dir($path)) {
45
                throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath($path);
46
            }
47
48 13
            $iterator = new \RegexIterator(
49 13
                new \RecursiveIteratorIterator(
50 13
                    new \RecursiveDirectoryIterator($path, \FilesystemIterator::SKIP_DOTS),
51 13
                    \RecursiveIteratorIterator::LEAVES_ONLY
52
                ),
53 13
                '/^.+'.preg_quote($this->fileExtension).'$/i',
54 13
                \RecursiveRegexIterator::GET_MATCH
55
            );
56
57 13
            foreach ($iterator as $file) {
58 13
                $sourceFile = $file[0];
59
60 13
                if (!preg_match('(^phar:)i', $sourceFile)) {
61 13
                    $sourceFile = realpath($sourceFile);
62
                }
63
64 13 View Code Duplication
                foreach ($this->excludePaths as $excludePath) {
65
                    $exclude = str_replace('\\', '/', realpath($excludePath));
66
                    $current = str_replace('\\', '/', $sourceFile);
67
68
                    if (strpos($current, $exclude) !== false) {
69
                        continue 2;
70
                    }
71
                }
72 13
                $projectDir = realpath(__DIR__.'/../../../../../../');
73 View Code Duplication
                if ('\\' === DIRECTORY_SEPARATOR) {
74
                    $path = str_replace('\\', '/', $path);
75
                    $this->trait_proxies_directory = str_replace('\\', '/', $this->trait_proxies_directory);
76
                    $sourceFile = str_replace('\\', '/', $sourceFile);
77 13
                    $projectDir = str_replace('\\', '/', $projectDir);
78 13
                }
79
                // Replace /path/to/ec-cube to proxies path
80
                $proxyFile = str_replace($projectDir, $this->trait_proxies_directory, $path).'/'.basename($sourceFile);
81
                if (file_exists($proxyFile)) {
82
                    require_once $proxyFile;
83 13
84
                    $sourceFile = $proxyFile;
85
                } else {
86 13
                    require_once $sourceFile;
87
                }
88
89
                $includedFiles[] = realpath($sourceFile);
90 13
            }
91
        }
92 13
93 13
        $declared = get_declared_classes();
94 13
95 13
        foreach ($declared as $className) {
96 13
            $rc = new \ReflectionClass($className);
97
            $sourceFile = $rc->getFileName();
98
            if (in_array($sourceFile, $includedFiles) && !$this->isTransient($className)) {
99
                $classes[] = $className;
100 13
            }
101
        }
102 13
103
        $this->classNames = $classes;
104
105
        return $classes;
106
    }
107
}
108