Completed
Push — master ( 4dab7c...47087f )
by recca
20:43 queued 19:11
created

Vi   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 78
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A handle() 0 13 3
A getArguments() 0 6 1
A getOptions() 0 6 1
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
    public function __construct(Filesystem $files)
38
    {
39
        parent::__construct();
40
41
        $this->files = $files;
42
    }
43
44
    /**
45
     * Handle the command.
46
     *
47
     * @throws \InvalidArgumentException
48
     */
49
    public function handle()
50
    {
51
        $path = $this->argument('path');
52
        $text = $this->option('text');
53
        $root = function_exists('base_path') === true ? base_path() : getcwd();
54
        $path = rtrim($root, '/').'/'.$path;
55
56
        if (is_null($text) === false) {
57
            $this->files->put($path, $text);
58
        } else {
59
            $this->line($this->files->get($path));
60
        }
61
    }
62
63
    /**
64
     * Get the console command arguments.
65
     *
66
     * @return array
67
     */
68
    protected function getArguments()
69
    {
70
        return [
71
            ['path', InputArgument::REQUIRED, 'path'],
72
        ];
73
    }
74
75
    /**
76
     * Get the console command options.
77
     *
78
     * @return array
79
     */
80
    protected function getOptions()
81
    {
82
        return [
83
            ['text', null, InputOption::VALUE_OPTIONAL],
84
        ];
85
    }
86
}
87