GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( db112f...a1e198 )
by Shea
02:53
created

MakeRequestCommand   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 137
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 1
A fire() 15 15 2
A makeFile() 4 4 1
A getDestinationFile() 4 4 1
A getPath() 6 6 1
A getFilename() 4 4 1
A getStubContent() 4 4 1
A formatContent() 8 8 1
A getArguments() 7 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace Caffeinated\Modules\Console\Generators;
3
4
use Caffeinated\Modules\Modules;
5
use Illuminate\Console\Command;
6
use Illuminate\Filesystem\Filesystem;
7
use Illuminate\Support\Str;
8
use Symfony\Component\Console\Input\InputArgument;
9
10 View Code Duplication
class MakeRequestCommand extends Command
0 ignored issues
show
Duplication introduced by
This class 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...
11
{
12
    /**
13
     * The console command name.
14
     *
15
     * @var string
16
     */
17
    protected $name = 'make:module:request';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Create a new module form request class';
25
26
    /**
27
     * Array to store the configuration details.
28
     *
29
     * @var array
30
     */
31
    protected $container;
32
33
    /**
34
     * Create a new command instance.
35
     *
36
     * @param Filesystem  $files
37
     * @param Modules  $module
38
     */
39
    public function __construct(Filesystem $files, Modules $module)
40
    {
41
        parent::__construct();
42
43
        $this->files  = $files;
44
        $this->module = $module;
45
    }
46
47
    /**
48
     * Execute the console command.
49
     *
50
     * @return mixed
51
     */
52
    public function fire()
53
    {
54
        $this->container['slug']      = strtolower($this->argument('slug'));
55
        $this->container['className'] = $this->argument('name');
56
57
        if ($this->module->exists($this->container['slug'])) {
58
            $this->container['module'] = $this->module->getProperties($this->container['slug']);
59
60
            $this->makeFile();
61
62
            return $this->info('Module request created successfully.');
63
        }
64
65
        return $this->error('Module does not exist.');
66
    }
67
68
    /**
69
     * Create a new migration file.
70
     *
71
     * @return int
72
     */
73
    protected function makeFile()
74
    {
75
        return $this->files->put($this->getDestinationFile(), $this->getStubContent());
76
    }
77
78
    /**
79
     * Get file destination.
80
     *
81
     * @return string
82
     */
83
    protected function getDestinationFile()
84
    {
85
        return $this->getPath().$this->formatContent($this->getFilename());
86
    }
87
88
    /**
89
     * Get module migration path.
90
     *
91
     * @return string
92
     */
93
    protected function getPath()
94
    {
95
        $path = $this->module->getModulePath($this->container['slug']);
96
97
        return $path.'Http/Requests/';
98
    }
99
100
    /**
101
     * Get the migration filename.
102
     *
103
     * @return string
104
     */
105
    protected function getFilename()
106
    {
107
        return $this->container['className'].'.php';
108
    }
109
110
    /**
111
     * Get the stub content.
112
     *
113
     * @return string
114
     */
115
    protected function getStubContent()
116
    {
117
        return $this->formatContent($this->files->get(__DIR__.'/../../../resources/stubs/request.stub'));
118
    }
119
120
    /**
121
	 * Replace placeholder text with correct values.
122
	 *
123
	 * @return string
124
	 */
125
	protected function formatContent($content)
126
    {
127
        return str_replace(
128
			['{{className}}', '{{namespace}}', '{{path}}'],
129
			[$this->container['className'], $this->container['module']['namespace'], $this->module->getNamespace()],
130
			$content
131
		);
132
    }
133
134
    /**
135
     * Get the console command arguments.
136
     *
137
     * @return array
138
     */
139
    protected function getArguments()
140
    {
141
        return [
142
            ['slug', InputArgument::REQUIRED, 'The slug of the module'],
143
            ['name', InputArgument::REQUIRED, 'The name of the controller']
144
        ];
145
    }
146
}
147