AutoLoader::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace SyncFS;
4
5
use Symfony\Component\Finder\Finder;
6
7
/**
8
 * Class AutoLoader
9
 *
10
 * @author Matej Velikonja <[email protected]>
11
 */
12
class AutoLoader
13
{
14
    /**
15
     * @var string
16
     */
17
    private $libDir;
18
19
    /**
20
     * @param string $libDir | Directory to lib folder
21
     */
22 5
    public function __construct($libDir)
23
    {
24 5
        $this->libDir = $libDir;
25 5
    }
26
27
    /**
28
     * Returns an array of initialized commands.
29
     *
30
     * @return array
31
     */
32 5
    public function getCommands()
33
    {
34 5
        $finder = new Finder();
35
        $finder
36 5
            ->files()
37 5
            ->in($this->libDir . '/Command')
38 5
            ->name('/(\w+)Command.php/');
39
40 5
        $commands = array();
41
        /** @var \SplFileInfo $file */
42 5
        foreach ($finder as $file) {
43 5
            $className  = str_replace('.php', '', $file->getFilename());
44 5
            $className  = '\\SyncFS\\Command\\' . $className;
45 5
            $commands[] = new $className();
46 5
        }
47
48 5
        return $commands;
49
    }
50
}
51