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 (#139)
by joseph
34:01 queued 31:09
created

GenerateEntityCommand::configure()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 38
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 38
rs 9.44
c 0
b 0
f 0
ccs 0
cts 29
cp 0
cc 2
nc 2
nop 0
crap 6
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command;
4
5
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Generator\EntityGenerator;
6
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Generator\Field\IdTrait;
7
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\NamespaceHelper;
8
use EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Input\InputOption;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
class GenerateEntityCommand extends AbstractCommand
14
{
15
16
    public const OPT_FQN        = 'entity-fully-qualified-name';
17
    public const OPT_FQN_SHORT  = 'f';
18
    public const DEFINITION_FQN = 'The fully qualified name of the entity you want to create';
19
20
    public const OPT_INT_PRIMARY_KEY       = 'int-primary-key';
21
    public const OPT_INT_PRIMARY_KEY_SHORT = 'd';
22
    public const DEFINITION_UUID           = 'Use an Integer primary key in place of the standard UUID primary key';
23
24
    public const OPT_ENTITY_SPECIFIC_SAVER        = 'entity-specific-saver';
25
    public const OPT_ENTITY_SPECIFIC_SAVER_SHORT  = 'c';
26
    public const DEFINITION_ENTITY_SPECIFIC_SAVER = 'Generate an implmentation of SaverInterface just for this entity';
27
28
    /**
29
     * @var EntityGenerator
30
     */
31
    protected $entityGenerator;
32
33
    /**
34
     * GenerateEntityCommand constructor.
35
     *
36
     * @param EntityGenerator $relationsGenerator
37
     * @param NamespaceHelper $namespaceHelper
38
     * @param null|string     $name
39
     *
40
     * @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException
41
     */
42
    public function __construct(
43
        EntityGenerator $relationsGenerator,
44
        NamespaceHelper $namespaceHelper,
45
        ?string $name = null
46
    ) {
47
        parent::__construct($namespaceHelper, $name);
48
        $this->entityGenerator = $relationsGenerator;
49
    }
50
51
    /**
52
     * @throws DoctrineStaticMetaException
53
     */
54
    protected function configure(): void
55
    {
56
        try {
57
            $this
58
                ->setName(AbstractCommand::COMMAND_PREFIX . 'generate:entity')
59
                ->setDefinition(
60
                    [
61
                        new InputOption(
62
                            self::OPT_FQN,
63
                            self::OPT_FQN_SHORT,
64
                            InputOption::VALUE_REQUIRED,
65
                            self::DEFINITION_FQN
66
                        ),
67
                        new InputOption(
68
                            self::OPT_INT_PRIMARY_KEY,
69
                            self::OPT_INT_PRIMARY_KEY_SHORT,
70
                            InputOption::VALUE_NONE,
71
                            self::DEFINITION_UUID
72
                        ),
73
                        new InputOption(
74
                            self::OPT_ENTITY_SPECIFIC_SAVER,
75
                            self::OPT_ENTITY_SPECIFIC_SAVER_SHORT,
76
                            InputOption::VALUE_NONE,
77
                            self::DEFINITION_ENTITY_SPECIFIC_SAVER
78
                        ),
79
                        $this->getProjectRootPathOption(),
80
                        $this->getProjectRootNamespaceOption(),
81
                        $this->getSrcSubfolderOption(),
82
                        $this->getTestSubFolderOption(),
83
                    ]
84
                )->setDescription(
85
                    'Generate an Entity'
86
                );
87
        } catch (\Exception $e) {
88
            throw new DoctrineStaticMetaException(
89
                'Exception in ' . __METHOD__ . ': ' . $e->getMessage(),
90
                $e->getCode(),
91
                $e
92
            );
93
        }
94
    }
95
96
97
    /**
98
     * @param InputInterface  $input
99
     * @param OutputInterface $output
100
     *
101
     * @throws DoctrineStaticMetaException
102
     */
103 2
    protected function execute(InputInterface $input, OutputInterface $output): void
104
    {
105
        try {
106 2
            $this->checkOptions($input);
107 2
            $output->writeln(
108 2
                '<comment>Starting generation for ' . $input->getOption(self::OPT_FQN) . '</comment>'
109
            );
110
            $idType =
111 2
                (true !== $input->getOption(self::OPT_INT_PRIMARY_KEY)) ?
112 2
                    IdTrait::UUID_FIELD_TRAIT : IdTrait::INTEGER_ID_FIELD_TRAIT;
113 2
            $this->entityGenerator
114 2
                ->setPathToProjectRoot($input->getOption(AbstractCommand::OPT_PROJECT_ROOT_PATH))
115 2
                ->setProjectRootNamespace($input->getOption(AbstractCommand::OPT_PROJECT_ROOT_NAMESPACE))
116 2
                ->setTestSubFolderName($input->getOption(AbstractCommand::OPT_TEST_SUBFOLDER))
117 2
                ->setPrimaryKeyType($idType);
118 2
            $this->entityGenerator->generateEntity(
119 2
                $input->getOption(self::OPT_FQN),
120 2
                $input->getOption(self::OPT_ENTITY_SPECIFIC_SAVER)
121
            );
122 2
            $output->writeln('<info>completed</info>');
123
        } catch (\Exception $e) {
124
            throw new DoctrineStaticMetaException(
125
                'Exception in ' . __METHOD__ . ': ' . $e->getMessage(),
126
                $e->getCode(),
127
                $e
128
            );
129
        }
130 2
    }
131
}
132