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

GenerateEntityCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Test Coverage

Coverage 80.77%

Importance

Changes 0
Metric Value
wmc 5
eloc 61
dl 0
loc 112
ccs 42
cts 52
cp 0.8077
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A execute() 0 22 2
A configure() 0 38 2
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\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 GenerateEntityCommand extends AbstractCommand
13
{
14
15
    public const OPT_FQN        = 'entity-fully-qualified-name';
16
    public const OPT_FQN_SHORT  = 'f';
17
    public const DEFINITION_FQN = 'The fully qualified name of the entity you want to create';
18
19
    public const OPT_UUID        = 'uuid-primary-key';
20
    public const OPT_UUID_SHORT  = 'u';
21
    public const DEFINITION_UUID = 'Use a UUID in place of the standard primary key';
22
23
    public const OPT_ENTITY_SPECIFIC_SAVER        = 'entity-specific-saver';
24
    public const OPT_ENTITY_SPECIFIC_SAVER_SHORT  = 'c';
25
    public const DEFINITION_ENTITY_SPECIFIC_SAVER = 'Generate an implmentation of SaverInterface just for this entity';
26
27
    /**
28
     * @var EntityGenerator
29
     */
30
    protected $entityGenerator;
31
32
    /**
33
     * GenerateEntityCommand constructor.
34
     *
35
     * @param EntityGenerator $relationsGenerator
36
     * @param NamespaceHelper $namespaceHelper
37
     * @param null|string     $name
38
     *
39
     * @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException
40
     */
41 3
    public function __construct(
42
        EntityGenerator $relationsGenerator,
43
        NamespaceHelper $namespaceHelper,
44
        ?string $name = null
45
    ) {
46 3
        parent::__construct($namespaceHelper, $name);
47 3
        $this->entityGenerator = $relationsGenerator;
48 3
    }
49
50
    /**
51
     * @throws DoctrineStaticMetaException
52
     */
53 3
    protected function configure(): void
54
    {
55
        try {
56
            $this
57 3
                ->setName(AbstractCommand::COMMAND_PREFIX . 'generate:entity')
58 3
                ->setDefinition(
59
                    [
60 3
                        new InputOption(
61 3
                            self::OPT_FQN,
62 3
                            self::OPT_FQN_SHORT,
63 3
                            InputOption::VALUE_REQUIRED,
64 3
                            self::DEFINITION_FQN
65
                        ),
66 3
                        new InputOption(
67 3
                            self::OPT_UUID,
68 3
                            self::OPT_UUID_SHORT,
69 3
                            InputOption::VALUE_NONE,
70 3
                            self::DEFINITION_UUID
71
                        ),
72 3
                        new InputOption(
73 3
                            self::OPT_ENTITY_SPECIFIC_SAVER,
74 3
                            self::OPT_ENTITY_SPECIFIC_SAVER_SHORT,
75 3
                            InputOption::VALUE_NONE,
76 3
                            self::DEFINITION_ENTITY_SPECIFIC_SAVER
77
                        ),
78 3
                        $this->getProjectRootPathOption(),
79 3
                        $this->getProjectRootNamespaceOption(),
80 3
                        $this->getSrcSubfolderOption(),
81 3
                        $this->getTestSubFolderOption(),
82
                    ]
83 3
                )->setDescription(
84 3
                    'Generate an Entity'
85
                );
86
        } catch (\Exception $e) {
87
            throw new DoctrineStaticMetaException(
88
                'Exception in ' . __METHOD__ . ': ' . $e->getMessage(),
89
                $e->getCode(),
90
                $e
91
            );
92
        }
93 3
    }
94
95
96
    /**
97
     * @param InputInterface  $input
98
     * @param OutputInterface $output
99
     *
100
     * @throws DoctrineStaticMetaException
101
     */
102 2
    protected function execute(InputInterface $input, OutputInterface $output): void
103
    {
104
        try {
105 2
            $this->checkOptions($input);
106 2
            $output->writeln(
107 2
                '<comment>Starting generation for ' . $input->getOption(self::OPT_FQN) . '</comment>'
108
            );
109 2
            $this->entityGenerator
110 2
                ->setPathToProjectRoot($input->getOption(AbstractCommand::OPT_PROJECT_ROOT_PATH))
111 2
                ->setProjectRootNamespace($input->getOption(AbstractCommand::OPT_PROJECT_ROOT_NAMESPACE))
112 2
                ->setTestSubFolderName($input->getOption(AbstractCommand::OPT_TEST_SUBFOLDER))
113 2
                ->setUseUuidPrimaryKey($input->getOption(self::OPT_UUID));
114 2
            $this->entityGenerator->generateEntity(
115 2
                $input->getOption(self::OPT_FQN),
116 2
                $input->getOption(self::OPT_ENTITY_SPECIFIC_SAVER)
117
            );
118 2
            $output->writeln('<info>completed</info>');
119
        } catch (\Exception $e) {
120
            throw new DoctrineStaticMetaException(
121
                'Exception in ' . __METHOD__ . ': ' . $e->getMessage(),
122
                $e->getCode(),
123
                $e
124
            );
125
        }
126 2
    }
127
}
128