Passed
Push — develop ( aa2ce5...bab8ed )
by Richard
03:43 queued 14s
created

PageMakeCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 13
c 1
b 0
f 0
dl 0
loc 34
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 5 1
A doOtherOperations() 0 9 1
A getStub() 0 3 2
A getDefaultNamespace() 0 3 1
1
<?php
2
3
namespace Riclep\Storyblok\Console;
4
5
use Illuminate\Console\GeneratorCommand;
6
use Illuminate\Support\Str;
7
8
class PageMakeCommand extends GeneratorCommand
9
{
10
	protected $name  = 'ls:page';
11
12
	protected $description = 'Create a new page class';
13
14
	protected $type = 'Page';
15
16
	protected function getStub(): string
17
	{
18
		return file_exists(resource_path('stubs/storyblok/page.stub')) ? resource_path('stubs/storyblok/page.stub') : __DIR__ . '/stubs/page.stub';
19
	}
20
21
	protected function getDefaultNamespace($rootNamespace): string
22
	{
23
		return $rootNamespace . '\Storyblok\Page';
24
	}
25
26
	public function handle(): void
27
	{
28
		parent::handle();
29
30
		$this->doOtherOperations();
31
	}
32
33
	protected function doOtherOperations(): void
34
	{
35
		$class = $this->qualifyClass($this->getNameInput());
36
		$path = $this->getPath($class);
37
		$content = file_get_contents($path);
38
39
		$content = str_replace('DummySlug', Str::kebab($this->getNameInput()), $content);
40
41
		file_put_contents($path, $content);
42
	}
43
}
44