Passed
Push — master ( 139939...b4b8e8 )
by Arthur
21:54 queued 17s
created

TestMakeCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getFileName() 0 3 1
A getTemplateContents() 0 8 1
A getDestinationFilePath() 0 7 1
A getArguments() 0 5 1
A getDefaultNamespace() 0 3 1
1
<?php
2
3
namespace Foundation\Generator\Commands;
4
5
use Illuminate\Support\Str;
6
use Nwidart\Modules\Support\Config\GenerateConfigReader;
7
use Nwidart\Modules\Support\Stub;
8
use Nwidart\Modules\Traits\ModuleCommandTrait;
9
use Symfony\Component\Console\Input\InputArgument;
10
11
class TestMakeCommand extends \Nwidart\Modules\Commands\TestMakeCommand
12
{
13
    use ModuleCommandTrait;
14
15
    protected $argumentName = 'name';
16
    protected $name = 'module:make-test';
17
    protected $description = 'Create a new test class for the specified module.';
18
19
    public function getDefaultNamespace() : string
20
    {
21
        return $this->laravel['modules']->config('paths.generator.test.path', 'Tests');
22
    }
23
24
    /**
25
     * Get the console command arguments.
26
     *
27
     * @return array
28
     */
29
    protected function getArguments()
30
    {
31
        return [
32
            ['name', InputArgument::REQUIRED, 'The name of the form request class.'],
33
            ['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
34
        ];
35
    }
36
37
    /**
38
     * @return mixed
39
     */
40
    protected function getTemplateContents()
41
    {
42
        $module = $this->laravel['modules']->findOrFail($this->getModuleName());
43
44
        return (new Stub('/unit-test.stub', [
45
            'NAMESPACE' => $this->getClassNamespace($module),
46
            'CLASS'     => $this->getClass(),
47
        ]))->render();
48
    }
49
50
    /**
51
     * @return mixed
52
     */
53
    protected function getDestinationFilePath()
54
    {
55
        $path = $this->laravel['modules']->getModulePath($this->getModuleName());
56
57
        $testPath = GenerateConfigReader::read('test');
58
59
        return $path . $testPath->getPath() . '/' . $this->getFileName() . '.php';
60
    }
61
62
    /**
63
     * @return string
64
     */
65
    private function getFileName()
66
    {
67
        return Str::studly($this->argument('name'));
0 ignored issues
show
Bug introduced by
It seems like $this->argument('name') can also be of type string[]; however, parameter $value of Illuminate\Support\Str::studly() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

67
        return Str::studly(/** @scrutinizer ignore-type */ $this->argument('name'));
Loading history...
68
    }
69
}
70