PolicyMakeCommand::getDestinationFilePath()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Rawilk\LaravelModules\Commands\Generators;
4
5
use Rawilk\LaravelModules\Support\Config\GenerateConfigReader;
6
use Rawilk\LaravelModules\Support\Stub;
7
use Rawilk\LaravelModules\Traits\ModuleCommands;
8
9
class PolicyMakeCommand extends GeneratorCommand
10
{
11
    use ModuleCommands;
12
13
    /** @var string */
14
    protected $argumentName = 'name';
15
16
    /** @var string */
17
    protected $signature = 'module:make-policy
18
                            {name : The name of the policy class}
19
                            {module? : The name of the module to create the policy for}';
20
21
    /** @var string */
22
    protected $description = 'Create a new policy class for the specified module.';
23
24
    protected function getDefaultNamespace(): string
25
    {
26
        /** @var \Rawilk\LaravelModules\Contracts\Repository $module */
27
        $module = $this->laravel['modules'];
28
29
        return $module->config('paths.generator.policies.namespace') ?: $module->config('paths.generator.policies.path', 'Policies');
30
    }
31
32
    protected function getDestinationFilePath(): string
33
    {
34
        $path = $this->laravel['modules']->getModulePath($this->getModuleName());
35
36
        $policyPath = GenerateConfigReader::read('policies');
37
38
        return $path . $policyPath->getPath() . '/' . $this->getFileName() . '.php';
39
    }
40
41
    protected function getTemplateContents(): string
42
    {
43
        $module = $this->laravel['modules']->findOrFail($this->getModuleName());
44
45
        return (new Stub('/policy.stub', [
46
            'NAMESPACE' => $this->getClassNamespace($module),
47
            'CLASS'     => $this->getClass(),
48
        ]))->render();
49
    }
50
}
51