MakeNewBundleFile::createFile()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
namespace LaravelLangBundler\Commands;
4
5
class MakeNewBundleFile extends LaravelLangBundlerCommand
6
{
7
    /**
8
     * The name and signature of the console command.
9
     *
10
     * @var string
11
     */
12
    protected $signature = 'langb:new {path}';
13
14
    /**
15
     * The console command description.
16
     *
17
     * @var string
18
     */
19
    protected $description = 'Make a new empty bundle file.';
20
21
    /**
22
     * Execute the console command.
23
     */
24
    public function handle()
25
    {
26
        $this->setUp();
27
28
        $pathArray = collect(explode('.', $this->argument('path')));
29
30
        $filename = $pathArray->pop().'.php';
31
32
        $pathArray->prepend('bundles');
33
34
        $basePath = resource_path('lang'.DIRECTORY_SEPARATOR);
35
36
        $path = $this->buildPath($pathArray->all(), $basePath);
37
38
        $this->createFile($path, $filename);
39
40
        $this->info('Bundle file successfully created!');
41
    }
42
43
    /**
44
     * Create file from stub.
45
     *
46
     * @param string $path
47
     * @param string $filename
48
     */
49
    protected function createFile($path, $filename)
50
    {
51
        $filePath = $path.$filename;
52
53
        $stub = __DIR__.DIRECTORY_SEPARATOR.'bundle-file-stub.php';
54
55
        if (!$this->filesystem->exists($filePath)) {
56
            $this->filesystem->copy($stub, $filePath);
57
        }
58
    }
59
}
60