ClassHelper::getClassMap()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 2
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace WebComplete\core\utils\helpers;
4
5
use hanneskod\classtools\Iterator\ClassIterator;
6
use Symfony\Component\Finder\Finder;
7
8
class ClassHelper
9
{
10
11
    /**
12
     * @param string $directory
13
     * @param string $namePattern
14
     *
15
     * @return array
16
     * @throws \Exception
17
     */
18
    public function getClassMap(string $directory, string $namePattern = '*.php'): array
19
    {
20
        $result = [];
21
        $finder = new Finder();
22
        $finder->in($directory)->files()->name($namePattern);
23
        $iterator = new ClassIterator($finder);
24
        foreach ($iterator->getClassMap() as $class => $splFileInfo) {
25
            $result[$splFileInfo->getRealPath()] = $class;
26
        }
27
        return $result;
28
    }
29
}
30