Completed
Push — master ( 732c1c...de71db )
by Arjay
21s queued 11s
created

DataTablesHtmlCommand::getStub()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Yajra\DataTables\Generators;
4
5
use Illuminate\Support\Str;
6
7
class DataTablesHtmlCommand extends DataTablesMakeCommand
8
{
9
    /**
10
     * The name and signature of the console command.
11
     *
12
     * @var string
13
     */
14
    protected $signature = 'datatables:html
15
                            {name : The name of the DataTable html.}
16
                            {--dom= : The dom of the DataTable.}
17
                            {--buttons= : The buttons of the DataTable.}
18
                            {--table= : Scaffold columns from the table.}
19
                            {--builder : Ignore, added to work with parent generator.}
20
                            {--columns= : The columns of the DataTable.}';
21
22
    /**
23
     * The console command description.
24
     *
25
     * @var string
26
     */
27
    protected $description = 'Create a new DataTable html class.';
28
29
    /**
30
     * The type of class being generated.
31
     *
32
     * @var string
33
     */
34
    protected $type = 'DataTableHtml';
35
36
    /**
37
     * Build the class with the given name.
38
     *
39
     * @param string $name
40
     * @return string
41
     */
42
    protected function buildClass($name)
43
    {
44
        $stub = $this->files->get($this->getStub());
45
46
        $stub = $this->replaceNamespace($stub, $name)->replaceClass($stub, $name);
47
48
        $this->replaceBuilder($stub)
49
             ->replaceColumns($stub)
50
             ->replaceButtons($stub)
51
             ->replaceDOM($stub)
52
             ->replaceTableId($stub);
53
54
        return $stub;
55
    }
56
57
    /**
58
     * Get the stub file for the generator.
59
     *
60
     * @return string
61
     */
62 View Code Duplication
    protected function getStub()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63
    {
64
        $config = $this->laravel['config'];
65
66
        return $config->get('datatables-buttons.stub')
67
            ? base_path() . $config->get('datatables-buttons.stub') . '/html.stub'
68
            : __DIR__ . '/stubs/html.stub';
69
    }
70
71
    /**
72
     * Parse the name and format according to the root namespace.
73
     *
74
     * @param string $name
75
     * @return string
76
     */
77 View Code Duplication
    protected function qualifyClass($name)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
78
    {
79
        $rootNamespace = $this->laravel->getNamespace();
80
81
        if (Str::startsWith($name, $rootNamespace)) {
82
            return $name;
83
        }
84
85
        if (Str::contains($name, '/')) {
86
            $name = str_replace('/', '\\', $name);
87
        }
88
89
        if (! Str::contains(Str::lower($name), 'datatable')) {
90
            $name .= 'DataTableHtml';
91
        }
92
93
        return $this->getDefaultNamespace(trim($rootNamespace, '\\')) . '\\' . $name;
94
    }
95
}
96