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 ( c1782c...59d6bd )
by Shea
04:56 queued 02:48
created

ModuleMakeControllerHandler   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 129
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A fire() 14 14 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

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\Handlers;
3
4
use Caffeinated\Modules\Modules;
5
use Illuminate\Console\Command;
6
use Illuminate\Filesystem\Filesystem;
7
use Illuminate\Support\Str;
8
9 View Code Duplication
class ModuleMakeControllerHandler
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...
10
{
11
	/**
12
	 * @var \Caffeinated\Modules\Modules
13
	 */
14
	protected $module;
15
16
	/**
17
	 * @var \Illuminate\Filesystem\Filesystem
18
	 */
19
	protected $finder;
20
21
	/**
22
	 * @var \Illuminate\Console\Command
23
	 */
24
	protected $console;
25
26
	/**
27
	 * @var string $moduleName The name of the module
28
	 */
29
	protected $moduleName;
30
31
	/**
32
	 * @var string $className The name of the request class
33
	 */
34
	protected $className;
35
36
	/**
37
	 * Constructor method.
38
	 *
39
	 * @param \Caffeinated\Modules\Modules      $module
40
	 * @param \Illuminate\Filesystem\Filesystem $finder
41
	 */
42
	public function __construct(Modules $module, Filesystem $finder)
43
	{
44
		$this->module = $module;
45
		$this->finder = $finder;
46
	}
47
48
	/**
49
	 * Fire off the handler.
50
	 *
51
	 * @param  \Illuminate\Console\Command $console
52
	 * @param  string                      $slug
53
	 * @param  string                      $class
54
	 * @return bool
55
	 */
56
	public function fire(Command $console, $slug, $class)
57
	{
58
		$this->console       = $console;
59
		$this->moduleName    = Str::studly($slug);
60
		$this->className     = studly_case($class);
61
62
		if ($this->module->exists($slug)) {
63
			$this->makeFile();
64
65
			return $this->console->info("Created Module Controller: [$slug] ".$this->getFilename());
66
		}
67
68
		return $this->console->info("Module [$slug] does not exist.");
69
	}
70
71
	/**
72
	 * Create new migration file.
73
	 *
74
	 * @return int
75
	 */
76
	protected function makeFile()
77
	{
78
		return $this->finder->put($this->getDestinationFile(), $this->getStubContent());
79
	}
80
81
	/**
82
	 * Get file destination.
83
	 *
84
	 * @return string
85
	 */
86
	protected function getDestinationFile()
87
	{
88
		return $this->getPath().$this->formatContent($this->getFilename());
89
	}
90
91
	/**
92
	 * Get module migration path.
93
	 *
94
	 * @return string
95
	 */
96
	protected function getPath()
97
	{
98
		$path = $this->module->getModulePath($this->moduleName);
99
100
		return $path.'Http/Controllers/';
101
	}
102
103
	/**
104
	 * Get migration filename.
105
	 *
106
	 * @return string
107
	 */
108
	protected function getFilename()
109
	{
110
		return $this->className.'.php';
111
	}
112
113
	/**
114
	 * Get stub content.
115
	 *
116
	 * @return string
117
	 */
118
	protected function getStubContent()
119
	{
120
		return $this->formatContent($this->finder->get(__DIR__.'/../Stubs/controller.stub'));
121
	}
122
123
	/**
124
	 * Replace placeholder text with correct values.
125
	 *
126
	 * @param  string $content
127
	 * @return string
128
	 */
129
	protected function formatContent($content)
130
	{
131
		return str_replace(
132
			['{{className}}', '{{moduleName}}', '{{namespace}}'],
133
			[$this->className, $this->moduleName, $this->module->getNamespace()],
134
			$content
135
		);
136
	}
137
}
138