Completed
Push — dev ( af9673...c6f8ca )
by Zach
02:21
created

MakeNewBundleFile::buildDirectoryStructure()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 8

Duplication

Lines 7
Ratio 43.75 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 2
dl 7
loc 16
rs 9.4285
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/');
35
36
        $path = $this->buildPath($pathArray, $basePath);
0 ignored issues
show
Documentation introduced by
$pathArray is of type object<Illuminate\Support\Collection>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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__.'/bundle-file-stub.php';
54
55
        if (!$this->filesystem->exists($filePath)) {
56
            $this->filesystem->copy($stub, $filePath);
57
        }
58
    }
59
}
60