Completed
Push — master ( 250f6a...af675f )
by Sam
07:31
created

ViewGenerator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 5
dl 0
loc 75
rs 10
c 0
b 0
f 0
1
<?php namespace Savannabits\JetstreamInertiaGenerator\Generators;
2
3
use Savannabits\JetstreamInertiaGenerator\Generators\Traits\Helpers;
4
use Savannabits\JetstreamInertiaGenerator\Generators\Traits\Names;
5
use Savannabits\JetstreamInertiaGenerator\Generators\Traits\Columns;
6
use Illuminate\Console\Command;
7
use Illuminate\Support\Facades\Schema;
8
use Symfony\Component\Console\Input\InputArgument;
9
use Illuminate\Support\Str;
10
use Illuminate\Filesystem\Filesystem;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Output\OutputInterface;
13
14
abstract class ViewGenerator extends Command {
15
16
    use Helpers, Columns, Names;
17
18
    /**
19
     * @var Filesystem
20
     */
21
    protected Filesystem $files;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
22
23
    /**
24
     * Relations
25
     *
26
     * @var string
27
     */
28
    protected $relations = [];
29
30
    /**
31
     * Create a new controller creator command instance.
32
     *
33
     * @param Filesystem $files
34
     */
35
    public function __construct(Filesystem $files)
36
    {
37
        parent::__construct();
38
39
        $this->files = $files;
40
    }
41
42
    protected function getArguments() {
43
        return [
44
            ['table_name', InputArgument::REQUIRED, 'Name of the existing table'],
45
            // FIXME add OPTIONAL file_name argument
46
        ];
47
    }
48
49
50
    /**
51
     * Append content to file only if if the content is not present in the file
52
     *
53
     * @param $path
54
     * @param $content
55
     * @return bool
56
     */
57
    protected function appendIfNotAlreadyAppended($path, $content): bool
58
    {
59
        if (!$this->files->exists($path)) {
60
            $this->makeDirectory($path);
61
            $this->files->put($path, $content);
62
        } else if (!$this->alreadyAppended($path, $content)) {
63
            $this->files->append($path, $content);
64
        } else {
65
            return false;
66
        }
67
68
        return true;
69
70
    }
71
72
    /**
73
     * Execute the console command.
74
     *
75
     * @param InputInterface $input
76
     * @param OutputInterface $output
77
     * @return int
78
     */
79
    protected function execute(InputInterface $input, OutputInterface $output)
80
    {
81
        $this->initCommonNames($this->argument('table_name'), $this->option('model-name'));
82
83
        return parent::execute($input, $output);
84
    }
85
86
}
87