Code Duplication    Length = 72-93 lines in 2 locations

sources/lib/Command/GenerateEntity.php 1 location

@@ 30-122 (lines=93) @@
27
 * @license   X11 {@link http://opensource.org/licenses/mit-license.php}
28
 * @see       PommAwareCommand
29
 */
30
class GenerateEntity extends RelationAwareCommand
31
{
32
    /**
33
     * configure
34
     *
35
     * @see Command
36
     */
37
    protected function configure()
38
    {
39
        $this
40
            ->setName('pomm:generate:entity')
41
            ->setDescription('Generate an Entity class.')
42
            ->setHelp(<<<HELP
43
This command generates an empty FlexibleEntity class in the given directory with the given namespace. By default, it creates a tree structure in the following format: ConfigName/NameSchema.
44
45
In order to comply with the project’s autoloading rules, it is possible to prefix this directory structure and / or namespace:
46
47
<info>pomm:generate:entity -d sources/lib/Model -a 'Vendor\Project\Model' --psr4 builder_name</info>
48
49
HELP
50
        )
51
        ;
52
        parent::configure();
53
    }
54
55
    /**
56
     * configureOptionals
57
     *
58
     * @see PommAwareCommand
59
     */
60
    protected function configureOptionals()
61
    {
62
        parent::configureOptionals()
63
            ->addOption(
64
                'force',
65
                null,
66
                InputOption::VALUE_NONE,
67
                'Force overwriting an existing file.'
68
            )
69
            ->addOption(
70
                'psr4',
71
                null,
72
                InputOption::VALUE_NONE,
73
                'Use PSR4 structure.'
74
            )
75
            ->addOption(
76
                'path-pattern',
77
                null,
78
                InputOption::VALUE_REQUIRED,
79
                'Use a different directory pattern when generating classes.',
80
                '{session}/{schema}Schema'
81
            )
82
        ;
83
84
        return $this;
85
    }
86
87
    /**
88
     * execute
89
     *
90
     * @see Command
91
     */
92
    protected function execute(InputInterface $input, OutputInterface $output)
93
    {
94
        parent::execute($input, $output);
95
96
        $session = $this->mustBeModelManagerSession($this->getSession());
97
98
        $this->pathFile = $this->getPathFile(
99
            $input->getArgument('config-name'),
100
            $this->relation,
101
            '',
102
            '',
103
            $input->getOption('psr4'),
104
            $input->getOption('path-pattern')
105
        );
106
        $this->namespace = $this->getNamespace($input->getArgument('config-name'), null, $input->getOption('path-pattern'));
107
108
        $this->updateOutput(
109
            $output,
110
            (new EntityGenerator(
111
                $session,
112
                $this->schema,
113
                $this->relation,
114
                $this->pathFile,
115
                $this->namespace,
116
                $this->flexible_container
117
            ))->generate(new ParameterHolder(['force' => $input->getOption('force')]))
118
        );
119
120
        return 0;
121
    }
122
}
123

sources/lib/Command/GenerateRelationModel.php 1 location

@@ 30-101 (lines=72) @@
27
 * @license   X11 {@link http://opensource.org/licenses/mit-license.php}
28
 * @see       PommAwareCommand
29
 */
30
class GenerateRelationModel extends RelationAwareCommand
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
            ->addOption(
58
                'path-pattern',
59
                null,
60
                InputOption::VALUE_REQUIRED,
61
                'Use a different directory pattern when generating classes.',
62
                '{session}/{schema}Schema'
63
            )
64
        ;
65
    }
66
67
    /**
68
     * execute
69
     *
70
     * @see Command
71
     */
72
    protected function execute(InputInterface $input, OutputInterface $output)
73
    {
74
        parent::execute($input, $output);
75
76
        $session = $this->mustBeModelManagerSession($this->getSession());
77
78
        $this->pathFile  = $this->getPathFile(
79
            $input->getArgument('config-name'),
80
            $this->relation,
81
            'Model',
82
            '',
83
            $input->getOption('psr4'),
84
            $input->getOption('path-pattern')
85
        );
86
        $this->namespace = $this->getNamespace($input->getArgument('config-name'), null, $input->getOption('path-pattern'));
87
88
        $this->updateOutput(
89
            $output,
90
            (new ModelGenerator(
91
                $session,
92
                $this->schema,
93
                $this->relation,
94
                $this->pathFile,
95
                $this->namespace
96
            ))->generate(new ParameterHolder(['force' => $input->getOption('force')]))
97
        );
98
99
        return 0;
100
    }
101
}
102