DeployDefinitionFileFinder   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 48
ccs 0
cts 24
cp 0
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A find() 0 22 2
A __construct() 0 4 1
1
<?php
2
3
namespace Deployee\Plugins\Deploy\Finder;
4
5
use Symfony\Component\Finder\Finder;
6
7
class DeployDefinitionFileFinder
8
{
9
    const DEPLOY_FILENAME_PATTERN = '/^(DeployDefinition\_|Deploy\_).*\.php$/';
10
11
    /**
12
     * @var string
13
     */
14
    private $searchRoot;
15
16
    /**
17
     * @var Finder
18
     */
19
    private $finder;
20
21
    /**
22
     * @param string $searchRoot
23
     */
24
    public function __construct(string $searchRoot)
25
    {
26
        $this->searchRoot = $searchRoot;
27
        $this->finder = new Finder();
28
    }
29
30
    /**
31
     * @return \ArrayObject
32
     */
33
    public function find(): \ArrayObject
34
    {
35
        $this->finder
36
            ->files()
37
            ->name(self::DEPLOY_FILENAME_PATTERN)
38
            ->depth("<= 2")
39
            ->sort(function(\SplFileInfo $a, \SplFileInfo $b){
40
                $sortNameA = substr($a->getBasename(), strpos($a->getBasename(), '_')+1);
41
                $sortNameB = substr($b->getBasename(), strpos($b->getBasename(), '_')+1);
42
                return strcmp($sortNameA, $sortNameB);
43
            })
44
            ->in([$this->searchRoot]);
45
46
        $classMap = new \ArrayObject();
47
        foreach($this->finder as $file){
48
            $filename = $file->getBasename();
49
            $className = substr($filename, 0, strrpos($filename, '.'));
50
51
            $classMap[$className] = $file->getRealPath();
52
        }
53
54
        return $classMap;
55
    }
56
}
57