These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /* |
||
3 | * This file is part of Pomm's Cli package. |
||
4 | * |
||
5 | * (c) 2014 - 2015 Grégoire HUBERT <[email protected]> |
||
6 | * |
||
7 | * For the full copyright and license information, please view the LICENSE |
||
8 | * file that was distributed with this source code. |
||
9 | */ |
||
10 | namespace PommProject\Cli\Command; |
||
11 | |||
12 | use PommProject\Foundation\ParameterHolder; |
||
13 | use PommProject\ModelManager\Generator\ModelGenerator; |
||
14 | use Symfony\Component\Console\Command\Command; |
||
15 | use Symfony\Component\Console\Input\InputInterface; |
||
16 | use Symfony\Component\Console\Input\InputOption; |
||
17 | use Symfony\Component\Console\Output\OutputInterface; |
||
18 | |||
19 | /** |
||
20 | * GenerateRelationModel |
||
21 | * |
||
22 | * Model generation command. |
||
23 | * |
||
24 | * @package Cli |
||
25 | * @copyright 2014 - 2015 Grégoire HUBERT |
||
26 | * @author Grégoire HUBERT |
||
27 | * @license X11 {@link http://opensource.org/licenses/mit-license.php} |
||
28 | * @see PommAwareCommand |
||
29 | */ |
||
30 | View Code Duplication | class GenerateRelationModel extends RelationAwareCommand |
|
0 ignored issues
–
show
|
|||
31 | { |
||
32 | /** |
||
33 | * configure |
||
34 | * |
||
35 | * @see Command |
||
36 | */ |
||
37 | public function configure() |
||
38 | { |
||
39 | $this |
||
40 | ->setName('pomm:generate:model') |
||
41 | ->setDescription('Generate a new model file.') |
||
42 | ; |
||
43 | parent::configure(); |
||
44 | $this |
||
45 | ->addOption( |
||
46 | 'force', |
||
47 | null, |
||
48 | InputOption::VALUE_NONE, |
||
49 | 'Force overwriting an existing file.' |
||
50 | ) |
||
51 | ->addOption( |
||
52 | 'psr4', |
||
53 | null, |
||
54 | InputOption::VALUE_NONE, |
||
55 | 'Use PSR4 structure.' |
||
56 | ) |
||
57 | ; |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * execute |
||
62 | * |
||
63 | * @see Command |
||
64 | */ |
||
65 | protected function execute(InputInterface $input, OutputInterface $output) |
||
66 | { |
||
67 | parent::execute($input, $output); |
||
68 | |||
69 | $session = $this->mustBeModelManagerSession($this->getSession()); |
||
70 | |||
71 | $this->pathFile = $this->getPathFile($input->getArgument('config-name'), $this->relation, 'Model', '', $input->getOption('psr4')); |
||
72 | $this->namespace = $this->getNamespace($input->getArgument('config-name')); |
||
73 | |||
74 | $this->updateOutput( |
||
75 | $output, |
||
76 | (new ModelGenerator( |
||
77 | $session, |
||
78 | $this->schema, |
||
79 | $this->relation, |
||
80 | $this->pathFile, |
||
81 | $this->namespace |
||
82 | ))->generate(new ParameterHolder(['force' => $input->getOption('force')])) |
||
83 | ); |
||
84 | } |
||
85 | } |
||
86 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.