Completed
Pull Request — 4.2 (#140)
by David
09:39 queued 04:42
created

GenerateCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 2
cbo 5
dl 0
loc 48
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A configure() 0 7 1
B execute() 0 25 2
1
<?php
2
namespace Mouf\Database\TDBM\Commands;
3
4
use Mouf\Database\TDBM\ConfigurationInterface;
5
use Mouf\Database\TDBM\TDBMService;
6
use Mouf\Utils\Log\Psr\MultiLogger;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Logger\ConsoleLogger;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
class GenerateCommand extends Command
13
{
14
15
    /**
16
     * @var ConfigurationInterface
17
     */
18
    private $configuration;
19
20
    public function __construct(ConfigurationInterface $configuration)
21
    {
22
        parent::__construct();
23
        $this->configuration = $configuration;
24
    }
25
26
    protected function configure()
27
    {
28
        $this->setName('tdbm:generate')
29
            ->setDescription('Generates DAOs and beans.')
30
            ->setHelp('Use this command to generate or regenerate the DAOs and beans for your project.')
31
        ;
32
    }
33
34
    protected function execute(InputInterface $input, OutputInterface $output)
35
    {
36
        // TODO: externalize composer.json file for autoloading (no more parameters for generateAllDaosAndBeans)
37
38
        $alteredConf = new AlteredConfiguration($this->configuration);
39
40
41
        $loggers = [ new ConsoleLogger($output) ];
42
43
        $logger = $alteredConf->getLogger();
44
        if ($logger) {
45
            $loggers[] = $logger;
46
        }
47
48
        $multiLogger = new MultiLogger($loggers);
49
50
        $alteredConf->setLogger($multiLogger);
51
52
        $multiLogger->notice('Starting regenerating DAOs and beans');
53
54
        $tdbmService = new TDBMService($this->configuration);
55
        $tdbmService->generateAllDaosAndBeans();
56
57
        $multiLogger->notice('Finished regenerating DAOs and beans');
58
    }
59
}
60