Completed
Push — master ( 45d696...4f8ab3 )
by Sergi Tur
02:36
created

MakeView   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 81
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 12 2
A getStubPath() 0 4 1
A viewPath() 0 4 1
A constructViewBaldeName() 0 3 1
A dottedPathToSlahesPath() 0 4 1
1
<?php
2
3
namespace Acacha\AdminLTETemplateLaravel\Console;
4
5
use Illuminate\Console\Command;
6
7
/**
8
 * Class MakeView.
9
 *
10
 * @package Acacha\AdminLTETemplateLaravel\Console
11
 */
12
class MakeView extends Command
13
{
14
    /**
15
     * The name and signature of the console command.
16
     *
17
     * @var string
18
     */
19
    protected $signature = 'make:view {name : the name of the view}';
20
21
    /**
22
     * The console command description.
23
     *
24
     * @var string
25
     */
26
    protected $description = 'Create a new view using adminlte default layout';
27
28
    /**
29
     * Create a new command instance.
30
     *
31
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
32
     */
33
    public function __construct()
34
    {
35
        parent::__construct();
36
    }
37
38
    /**
39
     * Execute the console command.
40
     *
41
     *
42
     */
43
    public function handle()
44
    {
45
        try {
46
            $this->filesystem->overwrite(
0 ignored issues
show
Bug introduced by
The property filesystem does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
47
                $path = resource_path('views/' . $this->viewPath()),
48
                $this->filesystem->get($this->getStubPath())
49
            );
50
            $this->info('File ' . $path . ' created');
51
        } catch (\Exception $e) {
52
            print_r($e->getMessage());
53
        }
54
    }
55
56
    /**
57
     * Get stub path
58
     */
59
    protected function getStubPath()
60
    {
61
        return __DIR__ . '/stubs/view.stub';
62
    }
63
64
    /**
65
     * The view destination path.
66
     *
67
     * @return string
68
     */
69
    protected function viewPath()
70
    {
71
        return $this->constructViewBaldeName($this->argument('name'));
72
    }
73
74
    /**
75
     * Create full relative path to blade template from view name.
76
     * @param $name
77
     * @return string
78
     */
79
    protected function constructViewBaldeName($name) {
80
        return $this->dottedPathToSlahesPath($name) . '.blade.php';
81
    }
82
83
    /**
84
     * Converts dotted notation to path slashes.
85
     * @param $name
86
     * @return mixed
87
     */
88
    protected function dottedPathToSlahesPath($name) {
89
        return str_replace(".", "/",$name);
90
91
    }
92
}
93