Passed
Push — master ( ad5a85...40ce26 )
by Arthur
23:10
created

ClassGeneratorCommand::getFileName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: arthur
5
 * Date: 09.03.19
6
 * Time: 17:15.
7
 */
8
9
namespace Foundation\Generator\Abstracts;
10
11
use Foundation\Core\Larapi;
12
use Foundation\Core\Module;
13
use Foundation\Generator\Events\CommandGeneratedEvent;
14
use Illuminate\Contracts\Filesystem\FileExistsException;
15
use Illuminate\Support\Str;
16
use Nwidart\Modules\Commands\GeneratorCommand;
17
use Symfony\Component\Console\Input\InputArgument;
18
19
abstract class ClassGeneratorCommand extends AbstractGeneratorCommand
20
{
21
22
    /**
23
     * Get the console command arguments.
24
     *
25
     * @return array
26
     */
27
    protected function setArguments() :array
28
    {
29
        return [
30
            ['name', InputArgument::OPTIONAL, 'The name of the ' . $this->getGeneratorName() . '.']
31
        ];
32
    }
33
34
    protected function handleNameArgument()
35
    {
36
        return $this->ask('Specify the name of the ' . $this->getGeneratorName() . '.');
37
    }
38
39
    /**
40
     * @return string
41
     */
42
    protected function getFileName() :string
43
    {
44
        return $this->getClassName() . '.php';
45
    }
46
47
    /**
48
     * Get class namespace.
49
     *
50
     *
51
     * @return string
52
     */
53
    public function getClassNamespace(): string
54
    {
55
        return $this->getModule()->getNamespace() . str_replace('/', '\\', $this->filePath);
56
    }
57
58
    protected function getClassName(){
59
        $className = $this->getArgument('name');
60
        if($className===null){
61
            $this->error('class name not specified');
62
            throw new \Exception('Name of ' . $this->getGeneratorName() . ' not set.');
63
        }
64
        return $className;
65
    }
66
67
    /**
68
     * Get the console command options.
69
     *
70
     * @return array
71
     */
72
    protected function setOptions() :array
73
    {
74
        return [];
75
    }
76
}
77