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

PolicyMakeCommand::getTemplateContents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
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 PolicyMakeCommand extends \Nwidart\Modules\Commands\PolicyMakeCommand
12
{
13
    use ModuleCommandTrait;
14
15
    /**
16
     * The name of argument name.
17
     *
18
     * @var string
19
     */
20
    protected $argumentName = 'name';
21
22
    /**
23
     * The console command name.
24
     *
25
     * @var string
26
     */
27
    protected $name = 'module:make-policy';
28
29
    /**
30
     * The console command description.
31
     *
32
     * @var string
33
     */
34
    protected $description = 'Create a new policy class for the specified module.';
35
36
    public function getDefaultNamespace() : string
37
    {
38
        return $this->laravel['modules']->config('paths.generator.policies.path', 'Policies');
39
    }
40
41
    /**
42
     * Get the console command arguments.
43
     *
44
     * @return array
45
     */
46
    protected function getArguments()
47
    {
48
        return [
49
            ['name', InputArgument::REQUIRED, 'The name of the policy class.'],
50
            ['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
51
        ];
52
    }
53
54
    /**
55
     * @return mixed
56
     */
57
    protected function getTemplateContents()
58
    {
59
        $module = $this->laravel['modules']->findOrFail($this->getModuleName());
60
61
        return (new Stub('/policy.plain.stub', [
62
            'NAMESPACE' => $this->getClassNamespace($module),
63
            'CLASS'     => $this->getClass(),
64
        ]))->render();
65
    }
66
67
    /**
68
     * @return mixed
69
     */
70
    protected function getDestinationFilePath()
71
    {
72
        $path = $this->laravel['modules']->getModulePath($this->getModuleName());
73
74
        $policyPath = GenerateConfigReader::read('policies');
75
76
        return $path . $policyPath->getPath() . '/' . $this->getFileName() . '.php';
77
    }
78
79
    /**
80
     * @return string
81
     */
82
    private function getFileName()
83
    {
84
        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

84
        return Str::studly(/** @scrutinizer ignore-type */ $this->argument('name'));
Loading history...
85
    }
86
}
87