AutoLoader   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 39
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getCommands() 0 18 2
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