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 (#837)
by E
07:31 queued 05:03
created

GeneratorQueue   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 57
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 3

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A run() 0 8 2
A addToQueue() 0 4 1
A getAllowedQueue() 0 10 2
A getStepCount() 0 11 3
1
<?php declare(strict_types=1);
2
3
namespace ApiGen\Generator;
4
5
use ApiGen\Contracts\Console\Helper\ProgressBarInterface;
6
use ApiGen\Contracts\Generator\GeneratorQueueInterface;
7
use ApiGen\Contracts\Generator\StepCounterInterface;
8
use ApiGen\Contracts\Generator\TemplateGenerators\ConditionalTemplateGeneratorInterface;
9
use ApiGen\Contracts\Generator\TemplateGenerators\TemplateGeneratorInterface;
10
11
final class GeneratorQueue implements GeneratorQueueInterface
12
{
13
    /**
14
     * @var ProgressBarInterface
15
     */
16
    private $progressBar;
17
18
    /**
19
     * @var TemplateGeneratorInterface[]
20
     */
21
    private $queue = [];
22
23 8
    public function __construct(ProgressBarInterface $progressBar)
24
    {
25 8
        $this->progressBar = $progressBar;
26 8
    }
27
28 2
    public function run(): void
29
    {
30 2
        $this->progressBar->init($this->getStepCount());
31
32 2
        foreach ($this->getAllowedQueue() as $templateGenerator) {
33 2
            $templateGenerator->generate();
34
        }
35 2
    }
36
37 8
    public function addToQueue(TemplateGeneratorInterface $templateGenerator): void
38
    {
39 8
        $this->queue[] = $templateGenerator;
40 8
    }
41
42
    /**
43
     * @return TemplateGeneratorInterface[]
44
     */
45
    private function getAllowedQueue(): array
46
    {
47 4
        return array_filter($this->queue, function (TemplateGeneratorInterface $generator) {
48 4
            if ($generator instanceof ConditionalTemplateGeneratorInterface) {
49 1
                return $generator->isAllowed();
50
            }
51
52 3
            return true;
53 4
        });
54
    }
55
56 3
    private function getStepCount(): int
57
    {
58 3
        $steps = 0;
59 3
        foreach ($this->getAllowedQueue() as $templateGenerator) {
60 3
            if ($templateGenerator instanceof StepCounterInterface) {
61 2
                $steps += $templateGenerator->getStepCount();
62
            }
63
        }
64
65 3
        return $steps;
66
    }
67
}
68