Vi   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 94.44%

Importance

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