GenerateModelCommand   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 9
dl 0
loc 96
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 12 1
B execute() 0 66 7
1
<?php
2
3
namespace Yoghi\Bundle\MaddaBundle\Command;
4
5
use League\Flysystem\Adapter\Local;
6
use League\Flysystem\Filesystem;
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\ArrayInput;
9
use Symfony\Component\Console\Input\InputArgument;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Input\InputOption;
12
use Symfony\Component\Console\Output\BufferedOutput;
13
use Symfony\Component\Console\Output\OutputInterface;
14
use Symfony\Component\Console\Style\SymfonyStyle;
15
use Yoghi\Bundle\MaddaBundle\Finder\Finder;
16
use Yoghi\Bundle\MaddaBundle\Generator\DDDGenerator;
17
use Yoghi\Bundle\MaddaBundle\Model\Reader;
18
19
class GenerateModelCommand extends Command
20
{
21
    private $logger;
22
    private $errors;
23
24
    protected function configure()
25
    {
26
        $this
27
            ->setName('generate:model')
28
            ->setDescription('Genera tutto il modello a partire da un file yml')
29
            ->addArgument('directory', InputArgument::REQUIRED, 'Directory sorgente')
30
            ->addArgument('outputdirectory', InputArgument::REQUIRED, 'Directory output delle classi generate')
31
            ->addOption('clean', null, InputOption::VALUE_OPTIONAL, 'Option clean output directory')
32
            // ->addArgument('argument', InputArgument::OPTIONAL, 'Argument description')
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
33
            // ->addOption('option', null, InputOption::VALUE_NONE, 'Option description')
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
34
        ;
35
    }
36
37
    // protected function generateClasses(Local $fullPathFile, Local $directoryOutput, $io)
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
38
    // {
39
        // $adapter = new Local($directoryOutput);
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
40
        // $filesystem = new Filesystem($adapter);
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
41
        // $io->section('Analisi di '.$baseDirectory.'/'.$fileName);
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
42
//
43
        // $rym = new Reader();
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
44
        // $rym->readYaml($baseDirectory, $fileName);
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
45
        // $specList = $rym->getProperties();
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
46
    // }
47
48
    protected function execute(InputInterface $input, OutputInterface $output)
49
    {
50
        // throw new \Exception('boo');
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
51
52
        $directory = realpath($input->getArgument('directory'));
53
        $directoryOutput = $input->getArgument('outputdirectory');
54
55
        /* @var $logger Psr\Log\LoggerInterface */
56
        $this->logger = $this->getContainer()->get('logger');
0 ignored issues
show
Bug introduced by
The method getContainer() does not seem to exist on object<Yoghi\Bundle\Madd...d\GenerateModelCommand>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
57
58
        $io = new SymfonyStyle($input, $output);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $io. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
59
        $io->title('DDD Model Generation');
60
61
        $clean = $input->hasOption('clean');
62
        if ($clean) {
63
            $io->section('Clean output directoty');
64
            $fs = new \Symfony\Component\Filesystem\Filesystem();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $fs. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
65
            try {
66
                $fs->remove($directoryOutput);
67
            } catch (IOExceptionInterface $e) {
0 ignored issues
show
Bug introduced by
The class Yoghi\Bundle\MaddaBundle...nd\IOExceptionInterface does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
68
                $io->error($e->getMessage());
69
            }
70
            $io->text('clean of '.$directoryOutput.' completed');
71
        }
72
73
        if (is_dir($directory)) {
74
            $finder = new Finder();
75
            $finder->search($directory);
0 ignored issues
show
Bug introduced by
The call to search() misses a required argument $extension.

This check looks for function calls that miss required arguments.

Loading history...
76
            foreach ($finder->getFindedFiles() as $file) {
77
                if (pathinfo($file, PATHINFO_FILENAME) == 'model.yml') {
78
                    $io->text('Analizzo model.yml in '.pathinfo($file, PATHINFO_DIRNAME));
79
                    $dddGenerator = new DDDGenerator();
80
                    $dddGenerator->setLogger($this->logger);
81
                    $dddGenerator->analyze($file);
82
                    $dddGenerator->generate($directoryOutput);
83
                }
84
            }
85
86
            $io->section('Php-Cs-Fixer on generated files');
87
88
            $fixer = new \Symfony\CS\Console\Command\FixCommand();
89
90
            $input = new ArrayInput([
91
                'path' => $directoryOutput,
92
                '--level' => 'psr2',
93
                '--fixers' => 'eof_ending,strict_param,short_array_syntax,trailing_spaces,indentation,line_after_namespace,php_closing_tag',
94
            ]);
95
96
            $output = new BufferedOutput();
97
            $fixer->run($input, $output);
98
            $content = $output->fetch();
99
100
            $io->text($content);
101
102
            if (count($this->errors) == 0) {
103
                $io->success('Completed generation');
104
            } else {
105
                $io->error($this->errors);
106
            }
107
        } else {
108
            $io->caution('Directory '.$directory.' not valid');
109
        }
110
111
        // PER I WARNING RECUPERABILI
112
        //$io->note('Generate Class');
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
113
    }
114
}
115