GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#77)
by joseph
15:21
created

GenerateFieldCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 130
Duplicated Lines 0 %

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
wmc 5
eloc 73
dl 0
loc 130
ccs 55
cts 60
cp 0.9167
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A configure() 0 45 2
A execute() 0 28 2
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command;
4
5
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Generator\Field\FieldGenerator;
6
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\NamespaceHelper;
7
use EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
class GenerateFieldCommand extends AbstractCommand
13
{
14
15
    public const OPT_FQN         = 'field-fully-qualified-name';
16
    public const OPT_FQN_SHORT   = 'f';
17
    public const DEFINITION_NAME = 'The fully qualified name of the property you want to generate';
18
19
    public const OPT_TYPE        = 'field-property-doctrine-type';
20
    public const OPT_TYPE_SHORT  = 'y';
21
    public const DEFINITION_TYPE = 'The data type of the property you want to generate';
22
23
    public const OPT_DEFAULT_VALUE        = 'default';
24
    public const OPT_DEFAULT_VALUE_SHORT  = 'd';
25
    public const DEFINITION_DEFAULT_VALUE = 'The default value, defaults to null '
26
                                            . '(which also marks the field as nullable)';
27
28
    public const OPT_IS_UNIQUE        = 'is-unique';
29
    public const OPT_IS_UNIQUE_SHORT  = 'u';
30
    public const DEFINITION_IS_UNIQUE = 'This field is unique, duplicates are not allowed';
31
32
    /**
33
     * @var FieldGenerator
34
     */
35
    protected $fieldGenerator;
36
37
    /**
38
     * GenerateEntityCommand constructor.
39
     *
40
     * @param \EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Generator\Field\FieldGenerator $fieldSetterGenerator
41
     * @param NamespaceHelper                                                                   $namespaceHelper
42
     * @param null|string                                                                       $name
43
     *
44
     * @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException
45
     */
46 3
    public function __construct(
47
        FieldGenerator $fieldSetterGenerator,
48
        NamespaceHelper $namespaceHelper,
49
        ?string $name = null
50
    ) {
51 3
        parent::__construct($namespaceHelper, $name);
52 3
        $this->fieldGenerator = $fieldSetterGenerator;
53 3
    }
54
55
    /**
56
     * @throws DoctrineStaticMetaException
57
     */
58 3
    protected function configure(): void
59
    {
60
        try {
61
            $this
62 3
                ->setName(AbstractCommand::COMMAND_PREFIX . 'generate:field')
63 3
                ->setDefinition(
64
                    [
65 3
                        new InputOption(
66 3
                            self::OPT_FQN,
67 3
                            self::OPT_FQN_SHORT,
68 3
                            InputOption::VALUE_REQUIRED,
69 3
                            self::DEFINITION_NAME
70
                        ),
71 3
                        new InputOption(
72 3
                            self::OPT_TYPE,
73 3
                            self::OPT_TYPE_SHORT,
74 3
                            InputOption::VALUE_REQUIRED,
75 3
                            self::DEFINITION_TYPE
76
                        ),
77 3
                        new InputOption(
78 3
                            self::OPT_DEFAULT_VALUE,
79 3
                            self::OPT_DEFAULT_VALUE_SHORT,
80 3
                            InputOption::VALUE_OPTIONAL,
81 3
                            self::DEFINITION_DEFAULT_VALUE,
82 3
                            null
83
                        ),
84 3
                        new InputOption(
85 3
                            self::OPT_IS_UNIQUE,
86 3
                            self::OPT_IS_UNIQUE_SHORT,
87 3
                            InputOption::VALUE_NONE,
88 3
                            self::DEFINITION_IS_UNIQUE
89
                        ),
90 3
                        $this->getProjectRootPathOption(),
91 3
                        $this->getProjectRootNamespaceOption(),
92 3
                        $this->getSrcSubfolderOption(),
93 3
                        $this->getTestSubFolderOption(),
94
                    ]
95 3
                )->setDescription(
96 3
                    'Generate a field'
97
                );
98
        } catch (\Exception $e) {
99
            throw new DoctrineStaticMetaException(
100
                'Exception in ' . __METHOD__ . ': ' . $e->getMessage(),
101
                $e->getCode(),
102
                $e
103
            );
104
        }
105 3
    }
106
107
108
    /**
109
     * @param InputInterface  $input
110
     * @param OutputInterface $output
111
     *
112
     * @throws DoctrineStaticMetaException
113
     */
114 2
    protected function execute(InputInterface $input, OutputInterface $output): void
115
    {
116
        try {
117 2
            $this->checkOptions($input);
118
119 2
            $output->writeln(
120 2
                '<comment>Starting generation for ' . $input->getOption(self::OPT_FQN) . '</comment>'
121
            );
122
123 2
            $this->fieldGenerator
124 2
                ->setPathToProjectRoot($input->getOption(AbstractCommand::OPT_PROJECT_ROOT_PATH))
125 2
                ->setProjectRootNamespace($input->getOption(AbstractCommand::OPT_PROJECT_ROOT_NAMESPACE))
126 2
                ->setTestSubFolderName($input->getOption(AbstractCommand::OPT_TEST_SUBFOLDER));
127
128 2
            $this->fieldGenerator->generateField(
129 2
                $input->getOption(self::OPT_FQN),
130 2
                $input->getOption(self::OPT_TYPE),
131 2
                null,
132 2
                $input->getOption(self::OPT_DEFAULT_VALUE) ?? null,
133 2
                $input->getOption(self::OPT_IS_UNIQUE)
134
            );
135
136 2
            $output->writeln('<info>completed</info>');
137 1
        } catch (\Exception $e) {
138 1
            throw new DoctrineStaticMetaException(
139 1
                'Exception in ' . __METHOD__ . ': ' . $e->getMessage(),
140 1
                $e->getCode(),
141 1
                $e
142
            );
143
        }
144 2
    }
145
}
146