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 ( f85b6d...dc1691 )
by Shea
7s
created

MakeCommand::getNamespace()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 6
nc 1
nop 1
1
<?php
2
3
namespace Caffeinated\Modules\Console\Generators;
4
5
use Caffeinated\Modules\Modules;
6
use Illuminate\Console\Command as CommandGenerator;
7
use Illuminate\Filesystem\Filesystem;
8
9
class MakeCommand extends CommandGenerator
10
{
11
	/**
12
     * Module folders to be created.
13
     *
14
	 * @var array
15
	 */
16
	protected $listFolders = [];
17
18
	/**
19
     * Module files to be created.
20
     *
21
	 * @var array
22
	 */
23
	protected $listFiles = [];
24
25
	/**
26
     * Module signature option.
27
     *
28
	 * @var array
29
	 */
30
	protected $signOption = [];
31
32
	/**
33
     * Module stubs used to populate defined files.
34
     *
35
	 * @var array
36
	 */
37
	protected $listStubs = [];
38
39
	/**
40
     * The modules instance.
41
     *
42
	 * @var Modules
43
	 */
44
	protected $module;
45
46
	/**
47
     * The modules path.
48
     *
49
	 * @var string
50
	 */
51
	protected $modulePath;
52
53
	/**
54
     * The modules info.
55
     *
56
	 * @var Illuminate\Support\Collection;
57
	 */
58
	protected $moduleInfo;
59
60
	/**
61
     * The filesystem instance.
62
     *
63
	 * @var Filesystem
64
	 */
65
	protected $files;
66
67
	/**
68
     * Array to store the configuration details.
69
     *
70
     * @var array
71
     */
72
    protected $container;
73
74
    /**
75
     * String to store the command type.
76
     *
77
     * @var string
78
     */
79
    protected $type;
80
81
    /**
82
     * Create a new command instance.
83
     *
84
     * @param Filesystem  $files
85
     * @param Modules  $module
86
     */
87
    public function __construct(Filesystem $files, Modules $module)
88
    {
89
        parent::__construct();
90
91
        $this->files  = $files;
92
        $this->module = $module;
93
    }
94
95
    /**
96
     * Execute the console command.
97
     *
98
     * @return mixed
99
     */
100
    public function fire()
101
    {
102
        $slug = $this->parseSlug($this->argument('slug'));
103
        $name = $this->parseName($this->argument('name'));
104
105
        if ($this->module->exists($slug)) {
106
        	$this->modulePath = $this->module->getPath();
107
        	$this->moduleInfo = collect($this->module->where('slug', $slug)->first());
108
        	
109
        	$this->container['slug'] = $slug;
110
        	$this->container['name'] = $name;
111
112
        	return $this->generate();
113
        }
114
115
        return $this->error('Module '.$this->container['slug'].' does not exist.');
116
    }
117
118
    /**
119
     * generate the console command.
120
     *
121
     * @return mixed
122
     */
123
    protected function generate()
124
    {
125
    	foreach ($this->listFiles as $key => $file) {
126
    		$filePath = $this->makeFilePath($this->listFolders[$key], $this->container['name']);
127
128
    		$this->resolveByPath( $filePath );
129
130
    		$file = $this->formatContent($file);
131
    		$filePath = str_replace(basename($filePath), '', $filePath);
132
    		$filePath = $filePath.$file;
133
134
    		if ($this->files->exists($filePath))
135
    		{
136
    			return $this->error($this->type.' already exists!');
137
    		}
138
139
    		$this->makeDirectory($filePath);
140
141
    		foreach ($this->signOption as $option) {
142
    			if ( $this->option($option) )
143
    			{
144
    				$stubFile = $this->listStubs[$option][$key];
145
    				$this->resolveByOption( $this->option($option) );
146
    				break;
147
    			}
148
	    	}
149
150
    		if (! isset($stubFile))
151
    		{
152
    			$stubFile = $this->listStubs['default'][$key];
153
    		}
154
    		
155
    		$this->files->put(
156
    			$filePath, 
157
    			$this->getStubContent($stubFile)
158
    		);
159
		}
160
161
		return $this->info($this->type.' generated successfully.');
162
    }
163
164
    /**
165
     * Resolve Container after getting file path
166
     * 
167
     * @param  string $FilePath
0 ignored issues
show
Documentation introduced by
There is no parameter named $FilePath. Did you maybe mean $filePath?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
168
     * @return Array
169
     */
170
    protected function resolveByPath($filePath){}
171
172
    /**
173
     * Resolve Container after getting input option
174
     * 
175
     * @param  string $option
176
     * @return Array
177
     */
178
    protected function resolveByOption($option){}
179
180
    /**
181
     * Parse Slug Name Of The Module
182
     * 
183
     * @param  string $slug
184
     * @return string      
185
     */
186
    protected function parseSlug($slug)
187
    {
188
    	$slug = studly_case($slug);
189
190
    	if (str_contains($slug, '/'))
191
    	{
192
    		$slug = str_replace('/', '', $slug);
193
    	}
194
195
    	if (str_contains($slug, '\\'))
196
    	{
197
    		$slug = str_replace('\\', '', $slug);
198
    	}
199
200
    	return strtolower($slug);
201
    }
202
203
    /**
204
     * Parse Class Name Of The Module
205
     * 
206
     * @param  string $slug
0 ignored issues
show
Bug introduced by
There is no parameter named $slug. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
207
     * @return string      
208
     */
209
    protected function parseName($name)
210
    {
211
    	if (str_contains($name, '\\'))
212
    	{
213
    		$name = str_replace('\\', '/', $name);
214
    	}
215
216
    	if (str_contains($name, '/'))
217
    	{
218
    		$formats = collect( explode('/', $name) )->map(function($name){
219
    			return studly_case($name);
220
    		});
221
222
    		$name = $formats->implode('/');
223
    	}
224
    	else
225
    	{
226
    		$name = studly_case($name);
227
    	}
228
229
    	return $name;
230
    }
231
232
    /**
233
     * Make FilePath
234
     * 
235
     * @param  string $folder
236
     * @param  string $name  
237
     * @return string        
238
     */
239
    protected function makeFilePath($folder, $name)
240
    {
241
    	$folder = ltrim($folder, '\/');
242
    	$folder = rtrim($folder, '\/');
243
244
    	$name = ltrim($name, '\/');
245
    	$name = rtrim($name, '\/');
246
247
    	return
248
    		$this->modulePath.DIRECTORY_SEPARATOR.
249
    		$this->moduleInfo->get('namespace').DIRECTORY_SEPARATOR.
250
    		$folder.DIRECTORY_SEPARATOR.$name;
251
    }
252
253
    /**
254
     * Make FileName 
255
     * 
256
     * @param  string $filePath
257
     * @return string          
258
     */
259
    protected function makeFileName($filePath)
260
    {
261
    	return basename($filePath);
262
    }
263
264
    /**
265
     * Build the directory for the class if necessary.
266
     *
267
     * @param  string  $path
268
     * @return string
269
     */
270
    protected function makeDirectory($path)
271
    {
272
        if (! $this->files->isDirectory(dirname($path))) {
273
            $this->files->makeDirectory(dirname($path), 0777, true, true);
274
        }
275
    }
276
277
    /**
278
     * Get Namespace of the current file
279
     * 
280
     * @param  string $file
281
     * @return string      
282
     */
283
    protected function getNamespace($file)
284
    {
285
    	$namespace = str_replace($this->modulePath, '', $file);
286
    	$namespace = str_replace(basename($namespace), '', $namespace);
287
    	$namespace = ltrim($namespace, '\/');
288
    	$namespace = rtrim($namespace, '\/');
289
    	
290
    	return str_replace('/', '\\', $namespace);
291
    }
292
293
    /**
294
	 * Get stub content by key.
295
	 *
296
	 * @param int  $key
0 ignored issues
show
Bug introduced by
There is no parameter named $key. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
297
	 * @return string
298
	 */
299
	protected function getStubContent($stubName)
300
	{
301
		$stubPath = __DIR__.'/../../../resources/stubs/';
302
303
		return $this->formatContent($this->files->get($stubPath.$stubName));
304
	}
305
306
    /**
307
	 * Replace placeholder text with correct values.
308
	 *
309
	 * @return string
310
	 */
311
	protected function formatContent($content){}
312
}