Completed
Push — master ( 1c87cd...c75e6a )
by Alejandro
03:14
created

ConsoleHelper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 6
dl 0
loc 52
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createApp() 0 19 3
B printConfigMissingError() 0 29 2
1
<?php
2
namespace Acelaya\Doctrine\Console;
3
4
use Acelaya\Doctrine\Exception\InvalidArgumentException;
5
use Acelaya\Doctrine\Registrator\EnumTypeRegistrator;
6
use Symfony\Component\Console\Application;
7
use Symfony\Component\Console\Output\ConsoleOutput;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
class ConsoleHelper
11
{
12 2
    public static function createApp(array $config)
13
    {
14 2
        $app = new Application('acelaya/doctrine-enum-type', 'v2.1.0');
15
16 2
        if (! isset($config['enum_types']) || ! is_array($config['enum_types'])) {
17 1
            throw new InvalidArgumentException('Config param "enum_types" with list of enums not provided');
18
        }
19
20
        // Make sure auto_generate_type_files is set to true, otherwise files won't be generated if accidentally
21
        // overwritten
22 1
        $config['auto_generate_type_files'] = true;
23 1
        $enums = $config['enum_types'];
24 1
        unset($config['enum_types']);
25 1
        $registrator = new EnumTypeRegistrator($config);
26
27
        // Create command and register
28 1
        $app->add(new DumpTypeClassesCommand($registrator, $enums));
29 1
        return $app;
30
    }
31
32 1
    public static function printConfigMissingError(OutputInterface $output = null)
33
    {
34 1
        $output = $output ?: new ConsoleOutput();
35 1
        $output->writeln('<error>det-config.php not found</error>');
36 1
        $output->writeln(
37
            'You have to create a file named <options=bold>det-config.php</> in the project root or the config'
38
            . ' subdirectory that provides the configuration to generate the doctrine types classes.'
39 1
        );
40 1
        $output->writeln(<<<EOT
41
For example:
42
43
    <?php
44
    use Acelaya\Doctrine\Type\AbstractPhpEnumType;
45
    use App\Enum\Action;
46 1
    use App\Enum\Gender;
47
48
    return [
49
        'base_type_class' => AbstractPhpEnumType::class,
50
        'type_files_dir' => 'some/dir',
51
52
        'enum_types' => [
53
            Action::class,
54
            'gender_type' => Gender::class,
55
        ],
56
    ];
57
58
EOT
59 1
        );
60 1
    }
61
}
62