Completed
Push — master ( e80380...ba59f9 )
by Derek Stephen
02:23
created

ProxyGenerator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 15 1
B execute() 0 26 4
1
<?php
2
/**
3
 * User: delboy1978uk
4
 * Date: 14/08/15
5
 * Time: 15:56
6
 */
7
8
namespace Del\ProxyGenerator\Command;
9
10
use Del\ProxyGenerator\Service\ProxyGeneratorService;
11
use Exception;
12
use Symfony\Component\Console\Command\Command;
13
use Symfony\Component\Console\Input\InputArgument;
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Output\OutputInterface;
16
17
class ProxyGenerator extends Command
18
{
19
    private $proxyGeneratorService;
20
21 1
    protected function configure()
22
    {
23 1
        $this->setName('create')
24 1
             ->setDescription('Creates new classes extending vendor classes with a certain interface, and implementing a different given interface.')
25 1
             ->setHelp("Pass the 3rd party interface to replace, the new interface, and the folder to check")
26 1
             ->addArgument('scanInterface', InputArgument::REQUIRED, 'The interface to scan for and list in an array of classes to extend in the scanDirectory')
27 1
             ->addArgument('replaceInterface', InputArgument::REQUIRED, 'The interface your extending class will implement')
28 1
             ->addArgument('scanDirectory', InputArgument::REQUIRED, 'The relative directory from the projectDirectory of classes to scan through and extend.')
29 1
             ->addArgument('targetNamespace', InputArgument::REQUIRED, 'The base namespace of the classes you are scanning through')
30 1
             ->addArgument('replaceNamespace', InputArgument::REQUIRED, 'The new base namespace.')
31 1
             ->addArgument('targetDirectory', InputArgument::OPTIONAL, 'The folder to generate the classes in.')
32 1
             ->addArgument('projectDirectory', InputArgument::OPTIONAL, 'The project\'s root directory.')
33
        ;
34 1
        $this->proxyGeneratorService = new ProxyGeneratorService();
35 1
    }
36
37 1
    protected function execute(InputInterface $input, OutputInterface $output)
38
    {
39 1
        $currentDir = realpath(getcwd().DIRECTORY_SEPARATOR.'..');
40 1
        $projectDirectory = $input->getArgument('projectDirectory');
41 1
        $targetDirectory = !is_null($input->getArgument('targetDirectory')) ? $input->getArgument('targetDirectory') : 'src';
42 1
        $scanDirectory = $input->getArgument('scanDirectory');
43 1
        $scanInterface = $input->getArgument('scanInterface');
44 1
        $replaceInterface = $input->getArgument('replaceInterface');
45 1
        $targetNamespace = $input->getArgument('targetNamespace');
46 1
        $replaceNamespace = $input->getArgument('replaceNamespace');
47
48 1
        $dir = empty($projectDirectory) ? $currentDir : realpath($projectDirectory);
49 1
        $svc = new ProxyGeneratorService($dir);
50 1
        $svc->setTargetPath($targetDirectory);
51 1
        $svc->setScanPath($scanDirectory);
52 1
        $svc->setScanInterface($scanInterface);
53 1
        $svc->setReplaceInterface($replaceInterface);
54 1
        $svc->setTargetNamespace($targetNamespace);
55 1
        $svc->setReplaceNamespace($replaceNamespace);
56
        
57 1
        $classes = $svc->generate();
58 1
        $output->writeln('Classes generated in '.$targetDirectory);
59 1
        foreach ($classes as $class) {
60 1
            $output->writeln('Generated '.$class.'.');
61
        }
62
    }
63
}