SilverStripeLoader   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 51
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getTasks() 0 21 4
A getCommandFactory() 0 4 1
A taskIsAbstract() 0 5 1
1
<?php
2
3
namespace SilverLeague\Console\Framework\Loader;
4
5
use ReflectionClass;
6
use SilverLeague\Console\Command\Factory;
7
use SilverLeague\Console\Framework\ConsoleBase;
8
use SilverStripe\Core\ClassInfo;
9
use SilverStripe\Core\Injector\Injector;
10
use SilverStripe\Dev\BuildTask;
11
12
/**
13
 * The class responsible for loading/instantiating SilverStripe and accessing its class hierarchy, etc
14
 *
15
 * @package silverstripe-console
16
 * @author  Robbie Averill <[email protected]>
17
 */
18
class SilverStripeLoader extends ConsoleBase
19
{
20
    /**
21
     * Return a set of Tasks from SilverStripe
22
     *
23 3
     * @return array
24
     */
25 3
    public function getTasks()
26 3
    {
27
        $commands = [];
28
        $tasks = ClassInfo::subclassesFor(BuildTask::class);
29 3
30
        // Remove the BuildTask itself
31 3
        array_shift($tasks);
32 3
33 3
        foreach ($tasks as $taskClass) {
34
            if ($this->taskIsAbstract($taskClass)) {
35
                continue;
36 3
            }
37
38
            $task = Injector::inst()->get($taskClass);
39
            if ($command = $this->getCommandFactory()->getCommandFromTask($task)) {
40
                $commands[] = $command;
41
            }
42
        }
43
44 4
        return $commands;
45
    }
46 4
47
    /**
48
     * Get a new command factory instance to generate the console Command
49
     *
50
     * @return Factory
51
     */
52
    public function getCommandFactory()
53
    {
54
        return new Factory($this->getApplication());
55
    }
56
57
    /**
58
     * Check whether the given task class is abstract
59
     *
60
     * @param string $className
61
     * @return bool
62
     */
63
    protected function taskIsAbstract($className)
64
    {
65
        $reflection = new ReflectionClass($className);
66
        return $reflection->isAbstract();
67
    }
68
}
69