Passed
Push — master ( a05e52...524499 )
by Caen
03:18 queued 12s
created

Command   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 7
Bugs 0 Features 1
Metric Value
eloc 6
c 7
b 0
f 1
dl 0
loc 33
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A createClickableFilepath() 0 3 2
A infoComment() 0 3 2
A inlineGray() 0 3 1
A gray() 0 3 1
A indentedLine() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Console\Concerns;
6
7
use Hyde\Hyde;
8
use LaravelZero\Framework\Commands\Command as BaseCommand;
9
10
/**
11
 * @see \Hyde\Framework\Testing\Feature\CommandTest
12
 */
13
abstract class Command extends BaseCommand
14
{
15
    /**
16
     * Create a filepath that can be opened in the browser from a terminal.
17
     */
18
    public static function createClickableFilepath(string $filepath): string
19
    {
20
        return 'file://'.str_replace('\\', '/', realpath($filepath) ?: Hyde::path($filepath));
21
    }
22
23
    /**
24
     * Write a nicely formatted and consistent message to the console. Using InfoComment for a lack of a better term.
25
     */
26
    public function infoComment(string $info, string $comment, ?string $moreInfo = null): void
27
    {
28
        $this->line("<info>$info</info> [<comment>$comment</comment>]".($moreInfo ? " <info>$moreInfo</info>" : ''));
29
    }
30
31
    /** @experimental This method may change (or be removed) before the 1.0.0 release */
32
    public function gray(string $string): void
33
    {
34
        $this->line($this->inlineGray($string));
35
    }
36
37
    /** @experimental This method may change (or be removed) before the 1.0.0 release */
38
    public function inlineGray(string $string): string
39
    {
40
        return "<fg=gray>$string</>";
41
    }
42
43
    public function indentedLine(int $indent, string $string): void
44
    {
45
        $this->line(str_repeat(' ', $indent).$string);
46
    }
47
}
48