AboutCommand   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 33
dl 0
loc 59
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0
wmc 13

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A configure() 0 4 1
F execute() 0 30 11
1
<?php declare(strict_types=1);
2
3
/*
4
 * This file is part of Biurad opensource projects.
5
 *
6
 * @copyright 2019 Biurad Group (https://biurad.com/)
7
 * @license   https://opensource.org/licenses/BSD-3-Clause License
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Flange\Commands;
14
15
use Flange\Application;
16
use Psr\Container\ContainerInterface;
17
use Symfony\Component\Console\Attribute\AsCommand;
18
use Symfony\Component\Console\Command\Command;
19
use Symfony\Component\Console\Helper\TableSeparator;
20
use Symfony\Component\Console\Input\InputInterface;
21
use Symfony\Component\Console\Output\OutputInterface;
22
use Symfony\Component\Console\Style\SymfonyStyle;
23
24
/**
25
 * A console command to display information about the current project.
26
 *
27
 * @author Divine Niiquaye Ibok <[email protected]>
28
 */
29
#[AsCommand('about', 'Display information about the current project.')]
30
final class AboutCommand extends Command
31
{
32
    protected static $defaultName = 'about';
33
    protected static $defaultDescription = 'Display information about the current project';
34
35
    public function __construct(private ContainerInterface $container)
36
    {
37
        parent::__construct(self::$defaultName);
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    protected function configure(): void
44
    {
45
        $this->setHelp(
46
            <<<'EOT'
47
The <info>%command.name%</info> command displays information about the current PHP Flange project.
48
49
The <info>PHP</info> section displays important configuration that could affect your application. The values might
50
be different between web and CLI.
51
EOT
52
        );
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    protected function execute(InputInterface $input, OutputInterface $output): int
59
    {
60
        $io = new SymfonyStyle($input, $output);
61
        $container = $this->container;
62
63
        $rows = [
64
            ['<info>PHP Flange Framework</>'],
65
            new TableSeparator(),
66
            ['Version', Application::VERSION],
67
            ['Long-Term Support', 4 === Application::VERSION[2] ? 'Yes' : 'No'],
68
            new TableSeparator(),
69
            ['<info>Kernel</>'],
70
            new TableSeparator(),
71
            ['Container', $container::class],
72
            ['Debug', $container instanceof Application ? ($container->isDebug() ? 'true' : 'false') : 'n/a'],
73
            new TableSeparator(),
74
            ['<info>PHP</>'],
75
            new TableSeparator(),
76
            ['Version', \PHP_VERSION],
77
            ['Architecture', (\PHP_INT_SIZE * 8).' bits'],
78
            ['Intl locale', \class_exists(\Locale::class, false) && \Locale::getDefault() ? \Locale::getDefault() : 'n/a'],
79
            ['Timezone', \date_default_timezone_get().' (<comment>'.(new \DateTime())->format(\DateTime::W3C).'</>)'],
80
            ['OPcache', \extension_loaded('Zend OPcache') && \filter_var(\ini_get('opcache.enable'), \FILTER_VALIDATE_BOOLEAN) ? 'true' : 'false'],
81
            ['APCu', \extension_loaded('apcu') && \filter_var(\ini_get('apc.enabled'), \FILTER_VALIDATE_BOOLEAN) ? 'true' : 'false'],
82
            ['Xdebug', \extension_loaded('xdebug') ? 'true' : 'false'],
83
        ];
84
85
        $io->table([], $rows);
86
87
        return self::SUCCESS;
88
    }
89
}
90