RocketApplication   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 0
cbo 3
dl 0
loc 48
ccs 0
cts 24
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A resolveCommands() 0 17 4
A getDefaultInputDefinition() 0 8 2
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