Issues (197)

src/Commands/NotificationMakeCommand.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Salah3id\Domains\Commands;
4
5
use Illuminate\Support\Str;
6
use Salah3id\Domains\Support\Config\GenerateConfigReader;
7
use Salah3id\Domains\Support\Stub;
8
use Salah3id\Domains\Traits\DomainCommandTrait;
9
use Symfony\Component\Console\Input\InputArgument;
10
11
final class NotificationMakeCommand extends GeneratorCommand
12
{
13
    use DomainCommandTrait;
14
15
    /**
16
     * The console command name.
17
     *
18
     * @var string
19
     */
20
    protected $name = 'domain:make-notification';
21
22
    protected $argumentName = 'name';
23
24
    /**
25
     * The console command description.
26
     *
27
     * @var string
28
     */
29
    protected $description = 'Create a new notification class for the specified domain.';
30
31
    public function getDefaultNamespace(): string
32
    {
33
        $domain = $this->laravel['domains'];
34
35
        return $domain->config('paths.generator.notifications.namespace') ?: $domain->config('paths.generator.notifications.path', 'Notifications');
36
    }
37
38
    /**
39
     * Get template contents.
40
     *
41
     * @return string
42
     */
43
    protected function getTemplateContents()
44
    {
45
        $domain = $this->laravel['domains']->findOrFail($this->getDomainName());
46
47
        return (new Stub('/notification.stub', [
48
            'NAMESPACE' => $this->getClassNamespace($domain),
49
            'CLASS'     => $this->getClass(),
50
        ]))->render();
51
    }
52
53
    /**
54
     * Get the destination file path.
55
     *
56
     * @return string
57
     */
58
    protected function getDestinationFilePath()
59
    {
60
        $path = $this->laravel['domains']->getDomainPath($this->getDomainName());
61
62
        $notificationPath = GenerateConfigReader::read('notifications');
63
64
        return $path . $notificationPath->getPath() . '/' . $this->getFileName() . '.php';
65
    }
66
67
    /**
68
     * @return string
69
     */
70
    private function getFileName()
71
    {
72
        return Str::studly($this->argument('name'));
0 ignored issues
show
It seems like $this->argument('name') can also be of type array; 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

72
        return Str::studly(/** @scrutinizer ignore-type */ $this->argument('name'));
Loading history...
73
    }
74
75
    /**
76
     * Get the console command arguments.
77
     *
78
     * @return array
79
     */
80
    protected function getArguments()
81
    {
82
        return [
83
            ['name', InputArgument::REQUIRED, 'The name of the notification class.'],
84
            ['domain', InputArgument::OPTIONAL, 'The name of domain will be used.'],
85
        ];
86
    }
87
}
88