MailMakeCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 17
c 1
b 0
f 0
dl 0
loc 44
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDestinationFilePath() 0 7 1
A getDefaultNamespace() 0 6 2
A getTemplateContents() 0 11 1
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 MailMakeCommand extends GeneratorCommand
10
{
11
    use ModuleCommands;
12
13
    /** @var string */
14
    protected $argumentName = 'name';
15
16
    /** @var string */
17
    protected $signature = 'module:make-mail
18
                            {name : The name of the mailable}
19
                            {module? : The name of the module to make the mailable for}
20
                            {--base_class= : Override the default base mail class (from config)}';
21
22
    /** @var string */
23
    protected $description = 'Create a new mailable class for the specified module.';
24
25
    protected function getDefaultNamespace(): string
26
    {
27
        /** @var \Rawilk\LaravelModules\Contracts\Repository $module */
28
        $module = $this->laravel['modules'];
29
30
        return $module->config('paths.generator.emails.namespace') ?: $module->config('paths.generator.emails.path', 'Mail');
31
    }
32
33
    protected function getDestinationFilePath(): string
34
    {
35
        $path = $this->laravel['modules']->getModulePath($this->getModuleName());
36
37
        $mailPath = GenerateConfigReader::read('emails');
38
39
        return $path . $mailPath->getPath() . '/' . $this->getFileName() . '.php';
40
    }
41
42
    protected function getTemplateContents(): string
43
    {
44
        /** @var \Rawilk\LaravelModules\Module $module */
45
        $module = $this->laravel['modules']->findOrFail($this->getModuleName());
46
47
        return (new Stub('/mail.stub', [
48
            'NAMESPACE'        => $this->getClassNamespace($module),
49
            'CLASS'            => $this->getClass(),
50
            'BASE_CLASS'       => $this->getBaseClass('mail'),
51
            'BASE_CLASS_SHORT' => $this->getBaseClass('mail', true),
52
        ]))->render();
53
    }
54
}
55