TransformerMakeCommand::replaceClass()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
namespace Yajra\DataTables\Commands;
4
5
use Illuminate\Support\Str;
6
use Illuminate\Console\GeneratorCommand;
7
8
class TransformerMakeCommand extends GeneratorCommand
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'make:transformer
16
                            {name : The name of the class}
17
                            {include? : Name of the class to include.}';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Create a new Transformer Class';
25
26
    /**
27
     * The type of class being generated.
28
     *
29
     * @var string
30
     */
31
    protected $type = 'Transformer';
32
33
    /**
34
     * Replace the class name for the given stub.
35
     *
36
     * @param string $stub Contents of the stub
37
     * @param string $name The class name
38
     *
39
     * @return string
40
     */
41
    protected function replaceClass($stub, $name)
42
    {
43
        $stub = parent::replaceClass($stub, $name . 'Transformer');
44
        $stub = str_replace('Dummy', ucfirst($this->argument('name')), $stub);
45
        $stub = str_replace('dummy', lcfirst($this->argument('name')), $stub);
46
47
        if ($this->argument('include')) {
48
            $stub = str_replace('Item', ucfirst($this->argument('include')), $stub);
49
            $stub = str_replace('item', lcfirst($this->argument('include')), $stub);
50
        }
51
52
        return $stub;
53
    }
54
55
    /**
56
     * Get the stub file for the generator.
57
     *
58
     * @return string
59
     */
60
    protected function getStub()
61
    {
62
        return $this->argument('include') ?
63
            __DIR__ . '/stubs/transformer.inc.stub' :
64
            __DIR__ . '/stubs/transformer.stub';
65
    }
66
67
    /**
68
     * Get the default namespace for the class.
69
     *
70
     * @param string $rootNamespace The root namespace
71
     *
72
     * @return string
73
     */
74
    protected function getDefaultNamespace($rootNamespace)
75
    {
76
        return $rootNamespace.'\Transformers';
77
    }
78
79
    /**
80
     * Get the destination class path.
81
     *
82
     * @param string $name Name of the class with namespace
83
     *
84
     * @return string
85
     */
86
    protected function getPath($name)
87
    {
88
        $name = Str::replaceFirst($this->rootNamespace(), '', $name);
89
90
        return $this->laravel['path'].'/'.str_replace('\\', '/', $name).'Transformer.php';
91
    }
92
}
93