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 (#199)
by joseph
21:04
created

SetFieldCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 50
dl 0
loc 96
ccs 0
cts 63
cp 0
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A execute() 0 23 2
A configure() 0 30 2
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command;
4
5
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Generator\Field\EntityFieldSetter;
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 SetFieldCommand extends AbstractCommand
13
{
14
    public const OPT_ENTITY       = 'entity';
15
    public const OPT_ENTITY_SHORT = 'o';
16
17
    public const OPT_FIELD       = 'field';
18
    public const OPT_FIELD_SHORT = 't';
19
    /**
20
     * @var \EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Generator\Field\EntityFieldSetter
21
     */
22
    protected $entityFieldSetter;
23
24
    /**
25
     * SetFieldCommand constructor.
26
     *
27
     * @param \EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Generator\Field\EntityFieldSetter $entityFieldSetter
28
     * @param null|string                                                                          $name
29
     *
30
     * @throws DoctrineStaticMetaException
31
     */
32
    public function __construct(
33
        EntityFieldSetter $entityFieldSetter,
34
        ?string $name = null
35
    ) {
36
        parent::__construct($name);
37
        $this->entityFieldSetter = $entityFieldSetter;
38
    }
39
40
41
    /**
42
     * @throws DoctrineStaticMetaException
43
     */
44
    public function configure(): void
45
    {
46
        try {
47
            $this->setName(AbstractCommand::COMMAND_PREFIX . 'set:field')
48
                 ->setDefinition(
49
                     [
50
                         new InputOption(
51
                             self::OPT_ENTITY,
52
                             self::OPT_ENTITY_SHORT,
53
                             InputOption::VALUE_REQUIRED,
54
                             'Entity Fully Qualified Name'
55
                         ),
56
                         new InputOption(
57
                             self::OPT_FIELD,
58
                             self::OPT_FIELD_SHORT,
59
                             InputOption::VALUE_REQUIRED,
60
                             'Field Fully Qualified Name'
61
                         ),
62
                         $this->getProjectRootPathOption(),
63
                         $this->getProjectRootNamespaceOption(),
64
                         $this->getSrcSubfolderOption(),
65
                     ]
66
                 )->setDescription(
67
                     'Set an Entity as having a Field'
68
                 );
69
        } catch (\Exception $e) {
70
            throw new DoctrineStaticMetaException(
71
                'Exception in ' . __METHOD__ . ': ' . $e->getMessage(),
72
                $e->getCode(),
73
                $e
74
            );
75
        }
76
    }
77
78
    /**
79
     * @param InputInterface  $input
80
     * @param OutputInterface $output
81
     *
82
     * @return int|null|void
83
     * @throws DoctrineStaticMetaException
84
     */
85
    public function execute(InputInterface $input, OutputInterface $output)
86
    {
87
        try {
88
            $output->writeln(
89
                '<comment>Setting Entity '
90
                . $input->getOption(static::OPT_ENTITY)
91
                . ' has Field ' . $input->getOption(static::OPT_FIELD)
92
                . '</comment>'
93
            );
94
            $this->checkOptions($input);
95
            $this->entityFieldSetter
96
                ->setPathToProjectRoot($input->getOption(AbstractCommand::OPT_PROJECT_ROOT_PATH))
97
                ->setProjectRootNamespace($input->getOption(AbstractCommand::OPT_PROJECT_ROOT_NAMESPACE))
98
                ->setEntityHasField(
99
                    $input->getOption(static::OPT_ENTITY),
100
                    $input->getOption(static::OPT_FIELD)
101
                );
102
            $output->writeln('<info>completed</info>');
103
        } catch (\Exception $e) {
104
            throw new DoctrineStaticMetaException(
105
                'Exception in ' . __METHOD__ . ': ' . $e->getMessage(),
106
                $e->getCode(),
107
                $e
108
            );
109
        }
110
    }
111
}
112