Completed
Push — master ( fb3a05...e80380 )
by Derek Stephen
02:17
created

ProxyGenerator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 94.59%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 51
ccs 35
cts 37
cp 0.9459
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 15 1
B execute() 0 30 5
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 2
    protected function configure()
22
    {
23 2
        $this->setName('create')
24 2
             ->setDescription('Creates new classes extending vendor classes with a certain interface, and implementing a different given interface.')
25 2
             ->setHelp("Pass the 3rd party interface to replace, the new interface, and the folder to check")
26 2
             ->addArgument('scanInterface', InputArgument::REQUIRED, 'The interface to scan for and list in an array of classes to extend in the scanDirectory')
27 2
             ->addArgument('replaceInterface', InputArgument::REQUIRED, 'The interface your extending class will implement')
28 2
             ->addArgument('scanDirectory', InputArgument::REQUIRED, 'The relative directory from the projectDirectory of classes to scan through and extend.')
29 2
             ->addArgument('targetNamespace', InputArgument::REQUIRED, 'The base namespace of the classes you are scanning through')
30 2
             ->addArgument('replaceNamespace', InputArgument::REQUIRED, 'The new base namespace.')
31 2
             ->addArgument('targetDirectory', InputArgument::OPTIONAL, 'The folder to generate the classes in.')
32 2
             ->addArgument('projectDirectory', InputArgument::OPTIONAL, 'The project\'s root directory.')
33
        ;
34 2
        $this->proxyGeneratorService = new ProxyGeneratorService();
35 2
    }
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
        try {
58 1
            $classes = $svc->generate();
59 1
            $output->writeln('Classes generated in '.$targetDirectory);
60 1
            foreach ($classes as $class) {
61 1
                $output->writeln('Generated '.$class.'.');
62
            }
63
        } catch (Exception $e) {
64
            $output->writeln('Error. '.$e->getMessage());
65
        }
66
    }
67
}