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 (#51)
by joseph
102:38 queued 99:24
created

GenerateFieldCommand::configure()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 42
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 30
CRAP Score 2.0009

Importance

Changes 0
Metric Value
dl 0
loc 42
c 0
b 0
f 0
ccs 30
cts 32
cp 0.9375
rs 8.8571
cc 2
eloc 33
nc 2
nop 0
crap 2.0009
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command;
4
5
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Generator\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 FieldGenerator  $fieldGenerator
41
     * @param NamespaceHelper $namespaceHelper
42
     * @param null|string     $name
43
     *
44
     * @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException
45
     */
46 3
    public function __construct(
47
        FieldGenerator $fieldGenerator,
48
        NamespaceHelper $namespaceHelper,
49
        ?string $name = null
50
    ) {
51 3
        parent::__construct($namespaceHelper, $name);
52 3
        $this->fieldGenerator = $fieldGenerator;
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('Exception in '.__METHOD__.': '.$e->getMessage(), $e->getCode(), $e);
100
        }
101 3
    }
102
103
104
    /**
105
     * @param InputInterface  $input
106
     * @param OutputInterface $output
107
     *
108
     * @throws DoctrineStaticMetaException
109
     */
110 2
    protected function execute(InputInterface $input, OutputInterface $output): void
111
    {
112
        try {
113 2
            $this->checkOptions($input);
114
115 2
            $output->writeln(
116 2
                '<comment>Starting generation for '.$input->getOption(self::OPT_FQN).'</comment>'
117
            );
118
119 2
            $this->fieldGenerator
120 2
                ->setPathToProjectRoot($input->getOption(AbstractCommand::OPT_PROJECT_ROOT_PATH))
121 2
                ->setProjectRootNamespace($input->getOption(AbstractCommand::OPT_PROJECT_ROOT_NAMESPACE))
122 2
                ->setTestSubFolderName($input->getOption(AbstractCommand::OPT_TEST_SUBFOLDER));
123
124 2
            $this->fieldGenerator->generateField(
125 2
                $input->getOption(self::OPT_FQN),
126 2
                $input->getOption(self::OPT_TYPE),
127 2
                null,
128 2
                $input->getOption(self::OPT_DEFAULT_VALUE) ?? null,
129 2
                $input->getOption(self::OPT_IS_UNIQUE)
130
            );
131
132 2
            $output->writeln('<info>completed</info>');
133 1
        } catch (\Exception $e) {
134 1
            throw new DoctrineStaticMetaException('Exception in '.__METHOD__.': '.$e->getMessage(), $e->getCode(), $e);
135
        }
136 2
    }
137
}
138