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

GenerateRelationsCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Test Coverage

Coverage 80.38%

Importance

Changes 0
Metric Value
wmc 6
eloc 55
dl 0
loc 110
ccs 41
cts 51
cp 0.8038
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A configure() 0 26 2
A execute() 0 38 3
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command;
4
5
use Doctrine\ORM\Tools\Console\MetadataFilter;
6
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Generator\RelationsGenerator;
7
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\NamespaceHelper;
8
use EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException;
9
use Symfony\Component\Console\Helper\ProgressBar;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Input\InputOption;
12
use Symfony\Component\Console\Output\OutputInterface;
13
14
class GenerateRelationsCommand extends AbstractCommand
15
{
16
17
    public const OPT_FILTER       = 'filter';
18
    public const OPT_FILTER_SHORT = 'f';
19
20
    /**
21
     * @var RelationsGenerator
22
     */
23
    protected $relationsGenerator;
24
25
    /**
26
     * GenerateRelationsCommand constructor.
27
     *
28
     * @param RelationsGenerator $relationsGenerator
29
     * @param NamespaceHelper    $namespaceHelper
30
     * @param null|string        $name
31
     *
32
     * @throws DoctrineStaticMetaException
33
     */
34 2
    public function __construct(
35
        RelationsGenerator $relationsGenerator,
36
        NamespaceHelper $namespaceHelper,
37
        ?string $name = null
38
    ) {
39 2
        parent::__construct($namespaceHelper, $name);
40 2
        $this->relationsGenerator = $relationsGenerator;
41 2
    }
42
43
44
    /**
45
     * @throws DoctrineStaticMetaException
46
     */
47 2
    protected function configure(): void
48
    {
49
        try {
50
            $this
51 2
                ->setName(AbstractCommand::COMMAND_PREFIX . 'generate:relations')
52 2
                ->setDefinition(
53
                    [
54 2
                        new InputOption(
55 2
                            self::OPT_FILTER,
56 2
                            self::OPT_FILTER_SHORT,
57 2
                            InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
58 2
                            'A string pattern used to match entities that should be processed.'
59
                        ),
60 2
                        $this->getProjectRootPathOption(),
61 2
                        $this->getProjectRootNamespaceOption(),
62 2
                        $this->getSrcSubfolderOption(),
63
                    ]
64 2
                )->setDescription(
65
                    'Generate relations traits for your entities. '
66 2
                    . 'Optionally filter down the list of entities to generate relationship traits for'
67
                );
68
        } catch (\Exception $e) {
69
            throw new DoctrineStaticMetaException(
70
                'Exception in ' . __METHOD__ . ': ' . $e->getMessage(),
71
                $e->getCode(),
72
                $e
73
            );
74
        }
75 2
    }
76
77
78
    /**
79
     * @param InputInterface  $input
80
     * @param OutputInterface $output
81
     *
82
     * @return void
83
     * @throws DoctrineStaticMetaException
84
     * @SuppressWarnings(PHPMD)
85
     */
86 1
    protected function execute(InputInterface $input, OutputInterface $output): void
87
    {
88
        try {
89 1
            $this->checkOptions($input);
90 1
            $entityManager = $this->getEntityManager();
91
92
            /**
93
             * @var ClassMetadata[] $metadatas
94
             */
95 1
            $metadatas = $entityManager->getMetadataFactory()->getAllMetadata();
96 1
            $metadatas = MetadataFilter::filter($metadatas, $input->getOption('filter'));
97 1
            $this->relationsGenerator
98 1
                ->setPathToProjectRoot($input->getOption(AbstractCommand::OPT_PROJECT_ROOT_PATH))
99 1
                ->setProjectRootNamespace($input->getOption(AbstractCommand::OPT_PROJECT_ROOT_NAMESPACE));
100
101 1
            $output->writeln(
102
                '<comment>Starting relations generation for '
103 1
                . implode(
104 1
                    ' ',
105 1
                    $input->getOption('filter')
106 1
                ) . '</comment>'
107
            );
108 1
            $progress = new ProgressBar($output, count($metadatas));
109 1
            $progress::setFormatDefinition('custom', ' %current%/%max% -- %message%');
110 1
            $progress->start();
111 1
            foreach ($metadatas as $metadata) {
112 1
                $progress->setMessage('<comment>Generating for ' . $metadata->name . '</comment>');
113 1
                $this->relationsGenerator->generateRelationCodeForEntity($metadata->name);
114 1
                $progress->setMessage('<info>done</info>');
115 1
                $progress->advance();
116
            }
117 1
            $progress->finish();
118 1
            $output->writeln('completed');
119
        } catch (\Exception $e) {
120
            throw new DoctrineStaticMetaException(
121
                'Exception in ' . __METHOD__ . ': ' . $e->getMessage(),
122
                $e->getCode(),
123
                $e
124
            );
125
        }
126 1
    }
127
}
128