Completed
Pull Request — experimental/sf (#3412)
by Kentaro
14:51 queued 07:29
created

AnnotationDriver::getAllClassNames()   C

Complexity

Conditions 14
Paths 63

Size

Total Lines 74

Duplication

Lines 5
Ratio 6.76 %

Code Coverage

Tests 32
CRAP Score 17.2806

Importance

Changes 0
Metric Value
cc 14
nc 63
nop 0
dl 5
loc 74
ccs 32
cts 43
cp 0.7442
crap 17.2806
rs 5.5805
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.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
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
19
{
20
    protected $trait_proxies_directory;
21
22 1324
    public function setTraitProxiesDirectory($dir)
23
    {
24 1324
        $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
                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 View Code Duplication
                if ('\\' === DIRECTORY_SEPARATOR) {
73
                    $path = str_replace('\\', '/', $path);
74
                    $this->trait_proxies_directory = str_replace('\\', '/', $this->trait_proxies_directory);
75
                    $sourceFile = str_replace('\\', '/', $sourceFile);
76
                }
77 13
                $proxyFile = str_replace($path, $this->trait_proxies_directory, $sourceFile);
78 13
                if (file_exists($proxyFile)) {
79
                    require_once $proxyFile;
80
81
                    $sourceFile = $proxyFile;
82
                } else {
83 13
                    require_once $sourceFile;
84
                }
85
86 13
                $includedFiles[] = realpath($sourceFile);
87
            }
88
        }
89
90 13
        $declared = get_declared_classes();
91
92 13
        foreach ($declared as $className) {
93 13
            $rc = new \ReflectionClass($className);
94 13
            $sourceFile = $rc->getFileName();
95 13
            if (in_array($sourceFile, $includedFiles) && !$this->isTransient($className)) {
96 13
                $classes[] = $className;
97
            }
98
        }
99
100 13
        $this->classNames = $classes;
101
102 13
        return $classes;
103
    }
104
}
105