Issues (197)

src/Commands/ProviderMakeCommand.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Salah3id\Domains\Commands;
4
5
use Illuminate\Support\Str;
6
use Salah3id\Domains\Domain;
7
use Salah3id\Domains\Support\Config\GenerateConfigReader;
8
use Salah3id\Domains\Support\Stub;
9
use Salah3id\Domains\Traits\DomainCommandTrait;
10
use Symfony\Component\Console\Input\InputArgument;
11
use Symfony\Component\Console\Input\InputOption;
12
13
class ProviderMakeCommand extends GeneratorCommand
14
{
15
    use DomainCommandTrait;
16
17
    /**
18
     * The name of argument name.
19
     *
20
     * @var string
21
     */
22
    protected $argumentName = 'name';
23
24
    /**
25
     * The console command name.
26
     *
27
     * @var string
28
     */
29
    protected $name = 'domain:make-provider';
30
31
    /**
32
     * The console command description.
33
     *
34
     * @var string
35
     */
36
    protected $description = 'Create a new service provider class for the specified domain.';
37
38
    public function getDefaultNamespace(): string
39
    {
40
        $domain = $this->laravel['domains'];
41
42
        return $domain->config('paths.generator.provider.namespace') ?: $domain->config('paths.generator.provider.path', 'Providers');
43
    }
44
45
    /**
46
     * Get the console command arguments.
47
     *
48
     * @return array
49
     */
50
    protected function getArguments()
51
    {
52
        return [
53
            ['name', InputArgument::REQUIRED, 'The service provider name.'],
54
            ['domain', InputArgument::OPTIONAL, 'The name of domain will be used.'],
55
        ];
56
    }
57
58
    /**
59
     * Get the console command options.
60
     *
61
     * @return array
62
     */
63
    protected function getOptions()
64
    {
65
        return [
66
            ['master', null, InputOption::VALUE_NONE, 'Indicates the master service provider', null],
67
        ];
68
    }
69
70
    /**
71
     * @return mixed
72
     */
73
    protected function getTemplateContents()
74
    {
75
        $stub = $this->option('master') ? 'scaffold/provider' : 'provider';
76
77
        /** @var Domain $domain */
78
        $domain = $this->laravel['domains']->findOrFail($this->getDomainName());
79
80
        return (new Stub('/' . $stub . '.stub', [
81
            'NAMESPACE'         => $this->getClassNamespace($domain),
82
            'CLASS'             => $this->getClass(),
83
            'LOWER_NAME'        => $domain->getLowerName(),
84
            'DOMAIN'            => $this->getDomainName(),
85
            'NAME'              => $this->getFileName(),
86
            'STUDLY_NAME'       => $domain->getStudlyName(),
87
            'DOMAIN_NAMESPACE'  => $this->laravel['domains']->config('namespace'),
88
            'PATH_VIEWS'        => GenerateConfigReader::read('views')->getPath(),
89
            'PATH_LANG'         => GenerateConfigReader::read('lang')->getPath(),
90
            'PATH_CONFIG'       => GenerateConfigReader::read('config')->getPath(),
91
            'MIGRATIONS_PATH'   => GenerateConfigReader::read('migration')->getPath(),
92
            'FACTORIES_PATH'    => GenerateConfigReader::read('factory')->getPath(),
93
        ]))->render();
94
    }
95
96
    /**
97
     * @return mixed
98
     */
99
    protected function getDestinationFilePath()
100
    {
101
        $path = $this->laravel['domains']->getDomainPath($this->getDomainName());
102
103
        $generatorPath = GenerateConfigReader::read('provider');
104
105
        return $path . $generatorPath->getPath() . '/' . $this->getFileName() . '.php';
106
    }
107
108
    /**
109
     * @return string
110
     */
111
    private function getFileName()
112
    {
113
        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

113
        return Str::studly(/** @scrutinizer ignore-type */ $this->argument('name'));
Loading history...
114
    }
115
}
116