Completed
Push — master ( 01b890...8110dc )
by Robbie
01:11
created

SilverStripeLoader::getTasks()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
ccs 8
cts 8
cp 1
rs 9.4285
cc 2
eloc 8
nc 2
nop 0
crap 2
1
<?php
2
3
namespace SilverLeague\Console\Framework\Loader;
4
5
use SilverLeague\Console\Command\Factory;
6
use SilverLeague\Console\Framework\ConsoleBase;
7
use SilverStripe\Core\ClassInfo;
8
use SilverStripe\Core\Injector\Injector;
9
10
/**
11
 * The class responsible for loading/instantiating SilverStripe and accessing its class hierarchy, etc
12
 *
13
 * @package silverstripe-console
14
 * @author  Robbie Averill <[email protected]>
15
 */
16
class SilverStripeLoader extends ConsoleBase
17
{
18
    /**
19
     * Return a set of Tasks from SilverStripe
20
     *
21
     * @return array
22
     */
23 1
    public function getTasks()
24
    {
25 1
        $commands = [];
26 1
        $tasks = ClassInfo::subclassesFor('SilverStripe\\Dev\\BuildTask');
27
28
        // Remove the BuildTask itself
29 1
        array_shift($tasks);
30
31 1
        foreach ($tasks as $taskClass) {
32 1
            $task = Injector::inst()->get($taskClass);
33 1
            $commands[] = $this->getCommandFactory()->getCommandFromTask($task);
34
        }
35
36 1
        return $commands;
37
    }
38
39
    /**
40
     * Get a new command factory instance to generate the console Command
41
     *
42
     * @return Factory
43
     */
44 2
    public function getCommandFactory()
45
    {
46 2
        return new Factory($this->getApplication());
47
    }
48
}
49