DebugCommand::handle()   A
last analyzed

Complexity

Conditions 6
Paths 3

Size

Total Lines 27
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 17
nc 3
nop 0
dl 0
loc 27
rs 9.0777
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Console\Commands;
6
7
use Hyde\Hyde;
8
use Hyde\Facades\Config;
9
use Composer\InstalledVersions;
10
use Hyde\Foundation\PharSupport;
11
use LaravelZero\Framework\Commands\Command;
12
13
use function str_replace;
14
use function realpath;
15
use function app;
16
use function get_included_files;
17
18
/**
19
 * Print debug information.
20
 */
21
class DebugCommand extends Command
22
{
23
    /** @var string */
24
    protected $signature = 'debug';
25
26
    /** @var string */
27
    protected $description = 'Print debug information';
28
29
    public function __construct()
30
    {
31
        parent::__construct();
32
33
        if (Config::getString('app.env', 'production') !== 'development') {
34
            $this->setHidden();
35
        }
36
    }
37
38
    public function handle(): int
39
    {
40
        $this->info('HydePHP Debug Screen');
41
        $this->newLine();
42
43
        $this->comment('Hyde Version: '.((InstalledVersions::isInstalled('hyde/hyde') ? InstalledVersions::getPrettyVersion('hyde/hyde') : null) ?: 'unreleased'));
44
        $this->comment('Framework Version: '.(InstalledVersions::getPrettyVersion('hyde/framework') ?: 'unreleased'));
45
        $this->newLine();
46
47
        $this->comment('App Env: '.(string) app('env'));
48
        $this->newLine();
49
50
        if ($this->output->isVerbose()) {
51
            $this->printVerbosePathInformation();
52
        } else {
53
            $this->comment('Project directory: '.Hyde::path());
0 ignored issues
show
Bug introduced by
The method path() does not exist on Hyde\Hyde. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
            $this->comment('Project directory: '.Hyde::/** @scrutinizer ignore-call */ path());
Loading history...
54
55
            if (PharSupport::running()) {
56
                $this->comment('Application binary path: '.get_included_files()[0]);
57
            }
58
        }
59
        $this->newLine();
60
61
        $this->line('Enabled features:');
62
        $this->printEnabledFeatures();
63
64
        return Command::SUCCESS;
65
    }
66
67
    protected function printVerbosePathInformation(): void
68
    {
69
        $this->line('Project directory:');
70
        $this->line(' > '.realpath(Hyde::path()));
71
        $this->line('Framework vendor path:');
72
        $this->line(' > '.(str_replace('/', DIRECTORY_SEPARATOR, Hyde::vendorPath()).' (vendor)'));
0 ignored issues
show
Bug introduced by
The method vendorPath() does not exist on Hyde\Hyde. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

72
        $this->line(' > '.(str_replace('/', DIRECTORY_SEPARATOR, Hyde::/** @scrutinizer ignore-call */ vendorPath()).' (vendor)'));
Loading history...
73
        $this->line(' > '.realpath(Hyde::vendorPath()).' (real)');
74
    }
75
76
    protected function printEnabledFeatures(): void
77
    {
78
        /** @var array<\Hyde\Enums\Feature> $features */
79
        $features = Config::getArray('hyde.features', []);
80
81
        foreach ($features as $feature) {
82
            $this->line(" - $feature->name");
0 ignored issues
show
Bug introduced by
The property name does not seem to exist on Hyde\Enums\Feature.
Loading history...
83
        }
84
    }
85
}
86