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 (#154)
by joseph
34:48
created

GenerateFieldCommand::configure()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 45
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 30
CRAP Score 2.0116

Importance

Changes 0
Metric Value
eloc 36
dl 0
loc 45
ccs 30
cts 35
cp 0.8571
rs 9.344
c 0
b 0
f 0
nc 2
nop 0
cc 2
crap 2.0116
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 null|string                                                                       $name
42
     *
43
     * @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException
44
     */
45 6
    public function __construct(
46
        FieldGenerator $fieldSetterGenerator,
47
        ?string $name = null
48
    ) {
49 6
        parent::__construct($name);
50 6
        $this->fieldGenerator = $fieldSetterGenerator;
51 6
    }
52
53
    /**
54
     * @throws DoctrineStaticMetaException
55
     */
56 6
    protected function configure(): void
57
    {
58
        try {
59
            $this
60 6
                ->setName(AbstractCommand::COMMAND_PREFIX . 'generate:field')
61 6
                ->setDefinition(
62
                    [
63 6
                        new InputOption(
64 6
                            self::OPT_FQN,
65 6
                            self::OPT_FQN_SHORT,
66 6
                            InputOption::VALUE_REQUIRED,
67 6
                            self::DEFINITION_NAME
68
                        ),
69 6
                        new InputOption(
70 6
                            self::OPT_TYPE,
71 6
                            self::OPT_TYPE_SHORT,
72 6
                            InputOption::VALUE_REQUIRED,
73 6
                            self::DEFINITION_TYPE
74
                        ),
75 6
                        new InputOption(
76 6
                            self::OPT_DEFAULT_VALUE,
77 6
                            self::OPT_DEFAULT_VALUE_SHORT,
78 6
                            InputOption::VALUE_OPTIONAL,
79 6
                            self::DEFINITION_DEFAULT_VALUE,
80 6
                            null
81
                        ),
82 6
                        new InputOption(
83 6
                            self::OPT_IS_UNIQUE,
84 6
                            self::OPT_IS_UNIQUE_SHORT,
85 6
                            InputOption::VALUE_NONE,
86 6
                            self::DEFINITION_IS_UNIQUE
87
                        ),
88 6
                        $this->getProjectRootPathOption(),
89 6
                        $this->getProjectRootNamespaceOption(),
90 6
                        $this->getSrcSubfolderOption(),
91 6
                        $this->getTestSubFolderOption(),
92
                    ]
93 6
                )->setDescription(
94 6
                    'Generate a field'
95
                );
96
        } catch (\Exception $e) {
97
            throw new DoctrineStaticMetaException(
98
                'Exception in ' . __METHOD__ . ': ' . $e->getMessage(),
99
                $e->getCode(),
100
                $e
101
            );
102
        }
103 6
    }
104
105
106
    /**
107
     * @param InputInterface  $input
108
     * @param OutputInterface $output
109
     *
110
     * @throws DoctrineStaticMetaException
111
     */
112 6
    protected function execute(InputInterface $input, OutputInterface $output): void
113
    {
114
        try {
115 6
            $this->checkOptions($input);
116
117 6
            $output->writeln(
118 6
                '<comment>Starting generation for ' . $input->getOption(self::OPT_FQN) . '</comment>'
119
            );
120
121 6
            $this->fieldGenerator
122 6
                ->setPathToProjectRoot($input->getOption(AbstractCommand::OPT_PROJECT_ROOT_PATH))
123 6
                ->setProjectRootNamespace($input->getOption(AbstractCommand::OPT_PROJECT_ROOT_NAMESPACE))
124 6
                ->setTestSubFolderName($input->getOption(AbstractCommand::OPT_TEST_SUBFOLDER));
125
126 6
            $this->fieldGenerator->generateField(
127 6
                $input->getOption(self::OPT_FQN),
128 6
                $input->getOption(self::OPT_TYPE),
129 6
                null,
130 6
                $input->getOption(self::OPT_DEFAULT_VALUE) ?? null,
131 6
                $input->getOption(self::OPT_IS_UNIQUE)
132
            );
133
134 6
            $output->writeln('<info>completed</info>');
135 3
        } catch (\Exception $e) {
136 3
            throw new DoctrineStaticMetaException(
137 3
                'Exception in ' . __METHOD__ . ': ' . $e->getMessage(),
138 3
                $e->getCode(),
139 3
                $e
140
            );
141
        }
142 6
    }
143
}
144