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

Vi   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 78
ccs 20
cts 20
cp 1
rs 10
c 2
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\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