Completed
Push — master ( da89f6...8759f3 )
by recca
01:28
created

Vi::handle()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 9
nc 4
nop 0
dl 0
loc 13
ccs 9
cts 9
cp 1
crap 3
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
namespace Recca0120\Terminal\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Filesystem\Filesystem;
7
use Symfony\Component\Console\Input\InputOption;
8
use Symfony\Component\Console\Input\InputArgument;
9
10
class Vi extends Command
11
{
12
    /**
13
     * The console command name.
14
     *
15
     * @var string
16
     */
17
    protected $name = 'vi';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Vi Editor';
25
26
    /**
27
     * $files.
28
     *
29
     * @var \Illuminate\Filesystem\Filesystem
30
     */
31
    protected $files;
32
33
    /**
34
     * __construct.
35
     *
36
     * @param \Illuminate\Filesystem\Filesystem $files
37
     */
38 2
    public function __construct(Filesystem $files)
39
    {
40 2
        parent::__construct();
41
42 2
        $this->files = $files;
43 2
    }
44
45
    /**
46
     * Handle the command.
47
     *
48 2
     * @throws \InvalidArgumentException
49
     */
50 2
    public function handle()
51 2
    {
52 2
        $path = $this->argument('path');
53 2
        $text = $this->option('text');
54
        $root = function_exists('base_path') === true ? base_path() : getcwd();
55 2
        $path = trim($root, '/').'/'.$path;
56 1
57 1
        if (is_null($text) === false) {
58 1
            $this->files->put($path, $text);
59
        } else {
60 2
            $this->line($this->files->get($path));
61
        }
62
    }
63
64
    /**
65
     * Get the console command arguments.
66
     *
67 2
     * @return array
68
     */
69
    protected function getArguments()
70 2
    {
71 2
        return [
72
            ['path', InputArgument::REQUIRED, 'path'],
73
        ];
74
    }
75
76
    /**
77
     * Get the console command options.
78
     *
79 2
     * @return array
80
     */
81
    protected function getOptions()
82 2
    {
83 2
        return [
84
            ['text', null, InputOption::VALUE_OPTIONAL],
85
        ];
86
    }
87
}
88