RocketGenerateSqlCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 4
dl 0
loc 54
ccs 0
cts 32
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
B execute() 0 32 4
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\Command;
13
14
use Rocket\ORM\Console\Command\AbstractCommand;
15
use Rocket\ORM\Generator\Database\DatabaseGenerator;
16
use Rocket\ORM\Generator\Schema\Schema;
17
use Symfony\Component\Console\Input\InputInterface;
18
use Symfony\Component\Console\Output\OutputInterface;
19
20
/**
21
 * @author Sylvain Lorinet <[email protected]>
22
 */
23
class RocketGenerateSqlCommand extends AbstractCommand
24
{
25
    /**
26
     *
27
     */
28
    protected function configure()
29
    {
30
        $this
31
            ->setName('generate:sql')
32
            ->setDescription('Generate SQL file for all schemas')
33
        ;
34
    }
35
36
    /**
37
     * @param InputInterface  $input
38
     * @param OutputInterface $output
39
     *
40
     * @throws \Exception
41
     *
42
     * @return int
43
     */
44
    protected function execute(InputInterface $input, OutputInterface $output)
45
    {
46
        $schemas = $this->getSchemas($this->getSchemaPath());
47
        $output->write('Generating ' . sizeof($schemas) . ' SQL schemas files... ');
48
        $this->verbose($output, '');
49
50
        try {
51
            $databaseGenerator = new DatabaseGenerator($this->getSqlOutputPath());
52
            /** @var Schema $schema */
53
            foreach ($schemas as $schema) {
54
                $this->verbose($output, sprintf(' > "%s.%s", with %d table%s... ',
55
                    $schema->connection,
56
                    $schema->database,
57
                    sizeof($schema->getTables()),
58
                    1 < sizeof($schema->getTables()) ? 's' : ''
59
                ), false);
60
61
                $databaseGenerator->generate($schema);
62
63
                $this->verbose($output, '<info>OK</info>');
64
            }
65
        } catch (\Exception $e) {
66
            $output->writeln('<error>FAIL</error>');
67
68
            throw $e;
69
        }
70
71
        $output->writeln('<info>Success</info>');
72
        $output->writeln('Generated files are located in <options=underscore>"' . $this->getSqlOutputPath() . '"</options=underscore>');
73
74
        return 0;
75
    }
76
}
77