Completed
Push — master ( 541968...b54375 )
by Sergi Tur
02:51
created

MakeView::dottedPathToSlahesPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Acacha\AdminLTETemplateLaravel\Console;
4
5
use Acacha\AdminLTETemplateLaravel\Filesystem\Filesystem;
6
use Illuminate\Console\Command;
7
8
/**
9
 * Class MakeView.
10
 *
11
 * @package Acacha\AdminLTETemplateLaravel\Console
12
 */
13
class MakeView extends Command
14
{
15
16
    /**
17
     * The filesystem instance.
18
     *
19
     * @var Acacha\AdminLTETemplateLaravel\Filesystem\Filesystem
20
     */
21
    protected $filesystem;
22
23
    /**
24
     * The name and signature of the console command.
25
     *
26
     * @var string
27
     */
28
    protected $signature = 'make:view {name : the name of the view}';
29
30
    /**
31
     * The console command description.
32
     *
33
     * @var string
34
     */
35
    protected $description = 'Create a new view using adminlte default layout';
36
37
    /**
38
     * Create a new command instance.
39
     *
40
     * @param Filesystem $filesystem
41
     */
42
    public function __construct(Filesystem $filesystem)
43
    {
44
        parent::__construct();
45
        $this->filesystem = $filesystem;
0 ignored issues
show
Documentation Bug introduced by
It seems like $filesystem of type object<Acacha\AdminLTETe...\Filesystem\Filesystem> is incompatible with the declared type object<Acacha\AdminLTETe...\Filesystem\Filesystem> of property $filesystem.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
46
    }
47
48
    /**
49
     * Execute the console command.
50
     *
51
     */
52
    public function handle()
53
    {
54
        try {
55
            $this->filesystem->make(
56
                $path = resource_path('views/' . $this->viewPath()),
57
                $this->filesystem->get($this->getStubPath()),
58
                true
59
            );
60
            $this->info('File ' . $path . ' created');
61
        } catch (\Exception $e) {
62
            $this->error($e->getMessage());
63
        }
64
    }
65
66
    /**
67
     * Get stub path
68
     */
69
    protected function getStubPath()
70
    {
71
        return __DIR__ . '/stubs/view.stub';
72
    }
73
74
    /**
75
     * The view destination path.
76
     *
77
     * @return string
78
     */
79
    protected function viewPath()
80
    {
81
        return $this->constructViewBladeName($this->argument('name'));
82
    }
83
84
    /**
85
     * Create full relative path to blade template from view name.
86
     *
87
     * @param $name
88
     * @return string
89
     */
90
    protected function constructViewBladeName($name)
91
    {
92
        return $this->dottedPathToSlashesPath($name) . '.blade.php';
93
    }
94
95
    /**
96
     * Converts dotted notation to path slashes.
97
     *
98
     * @param $name
99
     * @return mixed
100
     */
101
    protected function dottedPathToSlashesPath($name)
102
    {
103
        return str_replace(".", "/", $name);
104
    }
105
}
106