Passed
Push — master ( f5c22c...929873 )
by Chris
16:12
created

HopliteCommand::external()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace Leonidas\Console\Command;
4
5
use Jawira\CaseConverter\CaseConverter;
6
use Leonidas\Library\Core\Abstracts\ConvertsCaseTrait;
7
use Noodlehaus\Config;
8
use PHP_Parallel_Lint\PhpConsoleColor\ConsoleColor;
9
use PHP_Parallel_Lint\PhpConsoleHighlighter\Highlighter;
10
use Symfony\Component\Console\Command\Command;
11
use Symfony\Component\Filesystem\Filesystem;
12
13
abstract class HopliteCommand extends Command
14
{
15
    use ConvertsCaseTrait;
16
17
    protected Config $config;
18
19
    protected Filesystem $filesystem;
20
21
    protected Highlighter $highlighter;
22
23
    public function __construct(string $name = null)
24
    {
25
        $this->config = new Config($this->external('/hoplite.yml'));
26
        $this->filesystem = new Filesystem();
27
        $this->highlighter = new Highlighter(new ConsoleColor());
28
        $this->caseConverter = new CaseConverter();
29
30
        parent::__construct($name);
31
    }
32
33
    protected function config(string $key, $default = null)
34
    {
35
        return $this->config->get($key, $default);
36
    }
37
38
    protected function internal(string $path = ''): string
39
    {
40
        return dirname(__DIR__, 1) . $path;
41
    }
42
43
    protected function external(string $path = ''): string
44
    {
45
        return getcwd() . $path;
46
    }
47
48
    protected function printPhp(string $code): void
49
    {
50
        echo $this->highlighter->getWholeFile($code);
51
    }
52
53
    protected function writeFile(string $path, string $content): void
54
    {
55
        $this->filesystem->dumpFile($path, $content);
56
    }
57
}
58