RocketApplication::resolveCommands()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 17
ccs 0
cts 13
cp 0
rs 9.2
cc 4
eloc 9
nc 3
nop 1
crap 20
1
<?php
2
3
/*
4
 * This file is part of the "RocketORM" package.
5
 *
6
 * https://github.com/RocketORM/ORM
7
 *
8
 * For the full license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Rocket\ORM\Console;
13
14
use Rocket\ORM\Rocket;
15
use Symfony\Component\Console\Application;
16
use Symfony\Component\Console\Input\InputOption;
17
use Symfony\Component\Finder\Finder;
18
use Symfony\Component\Finder\SplFileInfo;
19
20
/**
21
 * @author Sylvain Lorinet <[email protected]>
22
 */
23
class RocketApplication extends Application
24
{
25
    protected $config;
26
27
    /**
28
     * @param string $name
29
     * @param string $version
30
     */
31
    public function __construct($name = 'Rocket', $version = Rocket::VERSION)
32
    {
33
        parent::__construct($name, $version);
34
    }
35
36
    /**
37
     * @param Finder $finder
38
     *
39
     * @return array
40
     */
41
    public function resolveCommands(Finder $finder)
42
    {
43
        $commands = [];
44
45
        /** @var SplFileInfo $file */
46
        foreach ($finder as $file) {
47
            $reflectionClass = new \ReflectionClass('\\Rocket\\ORM\\Command\\' . $file->getBasename('.php'));
48
            if (!$reflectionClass->isSubclassOf('\\Symfony\\Component\\Console\\Command\\Command') || $reflectionClass->isAbstract()) {
49
                continue;
50
            }
51
52
            $className = $reflectionClass->getName();
53
            $commands[] = new $className;
54
        }
55
56
        return $commands;
57
    }
58
59
    /**
60
     * @return \Symfony\Component\Console\Input\InputDefinition
61
     */
62
    protected function getDefaultInputDefinition()
63
    {
64
        $definition = parent::getDefaultInputDefinition();
65
        $definition->addOption(new InputOption('--rocket-config', '-rc', InputOption::VALUE_OPTIONAL, 'The Rocket configuration file path', getenv('ROCKET_CONFIG') ?: null));
66
        $definition->addOption(new InputOption('--connection', '-con', InputOption::VALUE_OPTIONAL, 'The default database connection to use'));
67
68
        return $definition;
69
    }
70
}
71