Conditions | 7 |
Paths | 21 |
Total Lines | 66 |
Code Lines | 41 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
48 | protected function execute(InputInterface $input, OutputInterface $output) |
||
49 | { |
||
50 | // throw new \Exception('boo'); |
||
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'); |
||
57 | |||
58 | $io = new SymfonyStyle($input, $output); |
||
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(); |
||
65 | try { |
||
66 | $fs->remove($directoryOutput); |
||
67 | } catch (IOExceptionInterface $e) { |
||
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); |
||
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'); |
||
113 | } |
||
114 | } |
||
115 |
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.