Passed
Pull Request — master (#979)
by Maxim
09:37
created

InfoCommand::perform()   C

Complexity

Conditions 12
Paths 72

Size

Total Lines 59
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 156

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 38
c 1
b 0
f 0
dl 0
loc 59
ccs 0
cts 41
cp 0
rs 6.9666
cc 12
nc 72
nop 2
crap 156

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Command\Tokenizer;
6
7
use Spiral\Boot\DirectoriesInterface;
8
use Spiral\Console\Command;
9
use Spiral\Tokenizer\Config\TokenizerConfig;
10
11
final class InfoCommand extends Command
12
{
13
    protected const NAME = 'tokenizer:info';
14
    protected const DESCRIPTION = 'Get information about tokenizer directories to scan';
15
16
    public function perform(TokenizerConfig $config, DirectoriesInterface $dirs): int
17
    {
18
        $this->info('Included directories:');
19
        $grid = $this->table(['Directory', 'Scope']);
20
        foreach ($config->getDirectories() as $directory) {
21
            $grid->addRow([\str_replace($dirs->get('root'), '', $directory), '']);
22
        }
23
        foreach ($config->getScopes() as $scope => $data) {
24
            foreach ($data['directories'] ?? [] as $directory) {
25
                $grid->addRow([\str_replace($dirs->get('root'), '', $directory), $scope]);
26
            }
27
        }
28
29
        $grid->render();
30
31
        $this->newLine();
32
33
        $this->info('Excluded directories:');
34
        $grid = $this->table(['Directory', 'Scope']);
35
        foreach ($config->getExcludes() as $directory) {
36
            $grid->addRow([\str_replace($dirs->get('root'), '', $directory), '']);
37
        }
38
        foreach ($config->getScopes() as $scope => $data) {
39
            foreach ($data['exclude'] ?? [] as $directory) {
40
                $grid->addRow([\str_replace($dirs->get('root'), '', $directory), $scope]);
41
            }
42
        }
43
44
        $grid->render();
45
46
        $this->newLine();
47
48
        $this->info('Loaders:');
49
        $grid = $this->table(['Loader', 'Status']);
50
51
        $grid->addRow(['Classes', $config->isLoadClassesEnabled()
52
            ? '<info>enabled</>'
53
            : '<error>disabled</>. <comment>To enable, add "TOKENIZER_LOAD_CLASSES=true" to your .env file.</>']);
54
        $grid->addRow(['Enums', $config->isLoadEnumsEnabled()
55
            ? '<info>enabled</>'
56
            : '<error>disabled</>. <comment>To enable, add "TOKENIZER_LOAD_ENUMS=true" to your .env file.</>']);
57
        $grid->addRow(
58
            ['Interfaces', $config->isLoadInterfacesEnabled()
59
                ? '<info>enabled</>'
60
                : '<error>disabled</>. <comment>To enable, add "TOKENIZER_LOAD_INTERFACES=true" to your .env file.</>']
61
        );
62
63
        $grid->render();
64
65
        $this->newLine();
66
        $this->info(
67
            \sprintf('Tokenizer cache: %s', $config->isCacheEnabled() ? '<info>enabled</>' : '<error>disabled</>'),
68
        );
69
        if (!$config->isCacheEnabled()) {
70
            $this->comment('To enable cache, add "TOKENIZER_CACHE_TARGETS=true" to your .env file.');
71
            $this->comment('Read more at https://spiral.dev/docs/advanced-tokenizer/#class-listeners');
72
        }
73
74
        return self::SUCCESS;
75
    }
76
}
77