Completed
Push — master ( abc53f...bc5893 )
by Brad
10:23
created

GenerateTransition   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 59
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getStub() 0 11 3
A buildClass() 0 7 1
A getDefaultNamespace() 0 5 1
1
<?php
2
3
namespace Transitions\Console;
4
5
use Illuminate\Console\GeneratorCommand;
6
7
class GenerateTransition extends GeneratorCommand
8
{
9
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'make:transition {name} {--request-only} {--response-only}';
16
    /**
17
     * The console command description.
18
     *
19
     * @var string
20
     */
21
    protected $description = 'Create an HTTP transition';
22
23
    /**
24
     * Get the stub file for the generator.
25
     *
26
     * @return string
27
     */
28
    protected function getStub()
29
    {
30
        if ($this->option('request-only')) {
31
            return __DIR__ . '/../../stubs/request_only_transition.stub';
32
        }
33
        if ($this->option('response-only')) {
34
            return __DIR__ . '/../../stubs/response_only_transition.stub';
35
        }
36
37
        return __DIR__ . '/../../stubs/transition.stub';
38
    }
39
40
    /**
41
     * Build the model class with the given name.
42
     *
43
     * @param  string $name
44
     * @return string
45
     */
46
    protected function buildClass($name)
47
    {
48
49
        $stub = $this->files->get($this->getStub());
50
51
        return $this->replaceNamespace($stub, $name)->replaceClass($stub, $name);
52
    }
53
54
    /**
55
     * Get the default namespace for the class.
56
     *
57
     * @param  string $rootNamespace
58
     * @return string
59
     */
60
    protected function getDefaultNamespace($rootNamespace)
61
    {
62
63
        return "$rootNamespace\\Http\\Transitions";
64
    }
65
}
66