Completed
Push — development ( b0c738...8cbb83 )
by Kyle
03:47
created

ServicesGenerator::generateService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Console\Commands\Generator;
4
5
class ServicesGenerator extends BaseGenerator
6
{
7
    /**
8
     * The name and signature of the console command.
9
     *
10
     * @var string
11
     */
12
    protected $signature = 'make:services {name}';
13
14
    /**
15
     * The console command description.
16
     *
17
     * @var string
18
     */
19
    protected $description = 'Create a services set';
20
21
    /**
22
     * Execute the console command.
23
     *
24
     * @return mixed
25
     */
26
    public function handle()
27
    {
28
        $targetName = $this->getTargetName();
29
30
        $this->info("Create services: $targetName");
31
        $this->generateInterface($targetName);
32
        $this->generateServices($targetName);
33
34
        $this->bindInterface($targetName);
0 ignored issues
show
Bug introduced by
It seems like $targetName can also be of type string[]; however, parameter $name of App\Console\Commands\Gen...erator::bindInterface() 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

34
        $this->bindInterface(/** @scrutinizer ignore-type */ $targetName);
Loading history...
35
    }
36
37
    /**
38
     * Generate interface file.
39
     *
40
     * @param $name
41
     */
42
    protected function generateInterface($name)
43
    {
44
        $this->proceedAndSaveFile(
45
            $name,
46
            'services_interface',
47
            $this->getServicesPath().ucwords($name).'ServicesInterface.php'
48
        );
49
    }
50
51
    /**
52
     * Generate repository file.
53
     *
54
     * @param $name
55
     */
56
    protected function generateServices($name)
57
    {
58
        $this->proceedAndSaveFile(
59
            $name,
60
            'services',
61
            $this->getServicesPath().'/Production/'.ucwords($name).'Services.php'
62
        );
63
    }
64
65
    /**
66
     * @param string $name
67
     *
68
     * @return bool
69
     */
70
    protected function bindInterface($name)
71
    {
72
        $className = ucwords($name);
73
74
        $bindService = $this->filesystem->get($this->getBindServiceProviderPath());
75
        $key = '//---MORE BINDING---//';
76
77
        $bind = '$this->app->singleton(        
78
            \\App\\Services\\'.$className.'ServicesInterface::class,           
79
            \\App\\Services\\Production\\'.$className.'Services::class
80
        );'. PHP_EOL .'
81
        '.$key;
82
        $bindService = str_replace($key, $bind, $bindService);
83
        $this->filesystem->put($this->getBindServiceProviderPath(), $bindService);
84
85
        return true;
86
    }
87
}
88