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 (#137)
by joseph
60:53 queued 35:20
created

OverridesUpdateCommand::configure()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 17
nc 2
nop 0
dl 0
loc 23
ccs 0
cts 16
cp 0
crap 6
rs 9.7
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\NamespaceHelper;
6
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\PostProcessor\FileOverrider;
7
use EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException;
8
use Symfony\Component\Console\Helper\Table;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Input\InputOption;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
class OverridesUpdateCommand extends AbstractCommand
14
{
15
    public const OPT_OVERRIDE_ACTION       = 'action';
16
    public const OPT_OVERRIDE_ACTION_SHORT = 'a';
17
18
    public const ACTION_TO_PROJECT   = 'toProject';
19
    public const ACTION_FROM_PROJECT = 'fromProject';
20
21
    /**
22
     * @var FileOverrider
23
     */
24
    protected $fileOverrider;
25
26
    public function __construct(FileOverrider $fileOverrider, NamespaceHelper $namespaceHelper, ?string $name = null)
27
    {
28
        parent::__construct($namespaceHelper, $name);
29
        $this->fileOverrider = $fileOverrider;
30
    }
31
32
    protected function execute(InputInterface $input, OutputInterface $output): void
33
    {
34
        $this->fileOverrider->setPathToProjectRoot($input->getOption(self::OPT_PROJECT_ROOT_PATH));
35
        switch ($input->getOption(self::OPT_OVERRIDE_ACTION)) {
36
            case self::ACTION_TO_PROJECT:
37
                $this->renderTableOfUpdatedFiles($this->fileOverrider->applyOverrides(), $output);
38
                $output->writeln('<info>Overrides have been applied to project</info>');
39
40
                return;
41
            case self::ACTION_FROM_PROJECT:
42
                $this->renderTableOfUpdatedFiles($this->fileOverrider->updateOverrideFiles(), $output);
43
                $output->writeln('<info>Overrides have been updated from the project</info>');
44
45
                return;
46
            default:
47
                throw new \InvalidArgumentException(
48
                    ' Invalid action ' . $input->getOption(self::OPT_OVERRIDE_ACTION)
49
                );
50
        }
51
    }
52
53
    private function renderTableOfUpdatedFiles(array $files, OutputInterface $output)
54
    {
55
        $table = new Table($output);
56
        foreach ($files as $file) {
57
            $table->addRow([$file]);
58
        }
59
        $table->render();
60
    }
61
62
    /**
63
     * @throws DoctrineStaticMetaException
64
     */
65
    protected function configure(): void
66
    {
67
        try {
68
            $this
69
                ->setName(AbstractCommand::COMMAND_PREFIX . 'overrides:update')
70
                ->setDefinition(
71
                    [
72
                        new InputOption(
73
                            self::OPT_OVERRIDE_ACTION,
74
                            self::OPT_OVERRIDE_ACTION_SHORT,
75
                            InputOption::VALUE_REQUIRED,
76
                            'One of [ fromProject,  toProject ]'
77
                        ),
78
                        $this->getProjectRootPathOption(),
79
                    ]
80
                )->setDescription(
81
                    'Update project overrides'
82
                );
83
        } catch (\Exception $e) {
84
            throw new DoctrineStaticMetaException(
85
                'Exception in ' . __METHOD__ . ': ' . $e->getMessage(),
86
                $e->getCode(),
87
                $e
88
            );
89
        }
90
    }
91
}
92