Passed
Pull Request — master (#963)
by butschster
09:56
created

InfoCommand::perform()   B

Complexity

Conditions 9
Paths 72

Size

Total Lines 40
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 90

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
dl 0
loc 40
ccs 0
cts 26
cp 0
rs 8.0555
c 1
b 0
f 0
cc 9
nc 72
nop 2
crap 90
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Command\Tokenizer;
6
7
use Spiral\Boot\DirectoriesInterface;
8
use Spiral\Console\Attribute\AsCommand;
9
use Spiral\Console\Command;
10
use Spiral\Tokenizer\Config\TokenizerConfig;
11
12
#[AsCommand(
13
    name: 'tokenizer:info',
14
    description: 'Get information about tokenizer directories to scan'
15
)]
16
final class InfoCommand extends Command
17
{
18
    public function perform(TokenizerConfig $config, DirectoriesInterface $dirs): int
19
    {
20
        $this->info('Included directories:');
21
        $grid = $this->table(['Directory', 'Scope']);
22
        foreach ($config->getDirectories() as $directory) {
23
            $grid->addRow([\str_replace($dirs->get('root'), '', $directory), '']);
24
        }
25
        foreach ($config->getScopes() as $scope => $data) {
26
            foreach ($data['directories'] ?? [] as $directory) {
27
                $grid->addRow([\str_replace($dirs->get('root'), '', $directory), $scope]);
28
            }
29
        }
30
31
        $grid->render();
32
33
        $this->newLine();
34
35
        $this->info('Excluded directories:');
36
        $grid = $this->table(['Directory', 'Scope']);
37
        foreach ($config->getExcludes() as $directory) {
38
            $grid->addRow([\str_replace($dirs->get('root'), '', $directory), '']);
39
        }
40
        foreach ($config->getScopes() as $scope => $data) {
41
            foreach ($data['exclude'] ?? [] as $directory) {
42
                $grid->addRow([\str_replace($dirs->get('root'), '', $directory), $scope]);
43
            }
44
        }
45
46
        $grid->render();
47
48
        $this->newLine();
49
        $this->info(
50
            \sprintf('Tokenizer cache: %s', $config->isCacheEnabled() ? '<success>enabled</>' : '<error>disabled</>'),
51
        );
52
        if (!$config->isCacheEnabled()) {
53
            $this->comment('To enable cache, add "TOKENIZER_CACHE_TARGETS=true" to your .env file.');
54
            $this->comment('Read more at https://spiral.dev/docs/advanced-tokenizer/#class-listeners');
55
        }
56
57
        return self::SUCCESS;
58
    }
59
}
60