Completed
Push — master ( c7b947...966759 )
by Thomas
08:09
created

GenerateModelsCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 11

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 11
dl 0
loc 38
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 9 1
B execute() 0 25 4
1
<?php
2
namespace keeko\tools\command;
3
4
use keeko\tools\command\AbstractKeekoCommand;
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Console\Output\OutputInterface;
7
use Symfony\Component\Console\Application;
8
use Propel\Generator\Command\ModelBuildCommand;
9
use keeko\tools\utils\NamespaceResolver;
10
use Symfony\Component\Finder\Iterator\RecursiveDirectoryIterator;
11
use gossi\codegen\model\PhpClass;
12
use phootwork\lang\Text;
13
use phootwork\file\File;
14
15
class GenerateModelsCommand extends AbstractKeekoCommand {
16
	
17
	protected function configure() {
18
		$this
19
			->setName('generate:models')
20
			->setDescription('Generates propel models');
21
	
22
		$this->configureGenerateOptions();
23
	
24
		parent::configure();
25
	}
26
	
27
	protected function execute(InputInterface $input, OutputInterface $output) {
28
		// run propel command
29
		$app = new Application();
30
		$cmd = new ModelBuildCommand();
31
		$app->add($cmd);
32
		
33
		$this->runCommand('model:build', [], $app);
34
		
35
		// cleanup
36
		$namespace = $this->modelService->getDatabase()->getNamespace();
37
		$path = NamespaceResolver::getSourcePath($namespace, $this->package);
38
		
39
		$directory = new \RecursiveDirectoryIterator($this->project->getRootPath() . '/' . $path);
40
		$iterator = new \RecursiveIteratorIterator($directory);
41
		foreach ($iterator as $fileinfo) {
42
			if ($fileinfo->getExtension() == 'php') {
43
				$class = PhpClass::fromFile($fileinfo->getPathname());
44
				$ns = $class->getNamespace();
45
				if (!Text::create($ns)->startsWith($namespace)) {
46
					$file = new File($fileinfo->getPathname());
47
					$file->delete();
48
				}
49
			}
50
		}
51
	}
52
}