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
Push — master ( 0a6f96...b0c756 )
by Ross
12s queued 10s
created

GenerateFieldCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
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  = 'd';
21
    public const DEFINITION_TYPE = 'The data type of the property you want to generate';
22
23
    public const OPT_NOT_NULLABLE        = 'not-nullable';
24
    public const OPT_NOT_NULLABLE_SHORT  = 'z';
25
    public const DEFINITION_NOT_NULLABLE = 'This field will not be nullable';
26
27
    public const OPT_IS_UNIQUE        = 'is-unique';
28
    public const OPT_IS_UNIQUE_SHORT  = 'u';
29
    public const DEFINITION_IS_UNIQUE = 'This field is unique, duplicates are not allowed';
30
31
    /**
32
     * @var FieldGenerator
33
     */
34
    protected $fieldGenerator;
35
36
    /**
37
     * GenerateEntityCommand constructor.
38
     *
39
     * @param FieldGenerator  $fieldGenerator
40
     * @param NamespaceHelper $namespaceHelper
41
     * @param null|string     $name
42
     *
43
     * @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException
44
     */
45
    public function __construct(
46
        FieldGenerator $fieldGenerator,
47
        NamespaceHelper $namespaceHelper,
48
        ?string $name = null
49
    ) {
50
        parent::__construct($namespaceHelper, $name);
51
        $this->fieldGenerator = $fieldGenerator;
52
    }
53
54
    /**
55
     * @throws DoctrineStaticMetaException
56
     */
57
    protected function configure(): void
58
    {
59
        try {
60
            $this
61
                ->setName(AbstractCommand::COMMAND_PREFIX.'generate:field')
62
                ->setDefinition(
63
                    [
64
                        new InputOption(
65
                            self::OPT_FQN,
66
                            self::OPT_FQN_SHORT,
67
                            InputOption::VALUE_REQUIRED,
68
                            self::DEFINITION_NAME
69
                        ),
70
                        new InputOption(
71
                            self::OPT_TYPE,
72
                            self::OPT_TYPE_SHORT,
73
                            InputOption::VALUE_REQUIRED,
74
                            self::DEFINITION_TYPE
75
                        ),
76
                        new InputOption(
77
                            self::OPT_NOT_NULLABLE,
78
                            self::OPT_NOT_NULLABLE_SHORT,
79
                            InputOption::VALUE_NONE,
80
                            self::DEFINITION_NOT_NULLABLE
81
                        ),
82
                        new InputOption(
83
                            self::OPT_IS_UNIQUE,
84
                            self::OPT_IS_UNIQUE_SHORT,
85
                            InputOption::VALUE_NONE,
86
                            self::DEFINITION_IS_UNIQUE
87
                        ),
88
                        $this->getProjectRootPathOption(),
89
                        $this->getProjectRootNamespaceOption(),
90
                        $this->getSrcSubfolderOption(),
91
                        $this->getTestSubFolderOption(),
92
                    ]
93
                )->setDescription(
94
                    'Generate a field'
95
                );
96
        } catch (\Exception $e) {
97
            throw new DoctrineStaticMetaException('Exception in '.__METHOD__.': '.$e->getMessage(), $e->getCode(), $e);
98
        }
99
    }
100
101
102
    /**
103
     * @param InputInterface  $input
104
     * @param OutputInterface $output
105
     *
106
     * @throws DoctrineStaticMetaException
107
     */
108
    protected function execute(InputInterface $input, OutputInterface $output): void
109
    {
110
        try {
111
            $this->checkOptions($input);
112
113
            $output->writeln(
114
                '<comment>Starting generation for '.$input->getOption(self::OPT_FQN).'</comment>'
115
            );
116
117
            $this->fieldGenerator
118
                ->setPathToProjectRoot($input->getOption(AbstractCommand::OPT_PROJECT_ROOT_PATH))
119
                ->setProjectRootNamespace($input->getOption(AbstractCommand::OPT_PROJECT_ROOT_NAMESPACE))
120
                ->setTestSubFolderName($input->getOption(AbstractCommand::OPT_TEST_SUBFOLDER));
121
122
            $this->fieldGenerator->generateField(
123
                $input->getOption(self::OPT_FQN),
124
                $input->getOption(self::OPT_TYPE),
125
                null,
126
                !(bool)$input->getOption(self::OPT_NOT_NULLABLE),
127
                $input->getOption(self::OPT_IS_UNIQUE)
128
            );
129
130
            $output->writeln('<info>completed</info>');
131
        } catch (\Exception $e) {
132
            throw new DoctrineStaticMetaException('Exception in '.__METHOD__.': '.$e->getMessage(), $e->getCode(), $e);
133
        }
134
    }
135
}
136