Completed
Push — master ( f02f16...4dab7c )
by recca
23:04 queued 21:46
created

Vi::getArguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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