Passed
Push — analysis-XNGW1g ( 55039c )
by Kyle
07:59 queued 32s
created

RepositoryGenerator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Console\Commands\Generator;
4
5
class RepositoryGenerator extends BaseGenerator
6
{
7
    /**
8
     * The name and signature of the console command.
9
     *
10
     * @var string
11
     */
12
    protected $signature = 'make:repository {name}';
13
14
    /**
15
     * The console command description.
16
     *
17
     * @var string
18
     */
19
    protected $description = 'Create a repository 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 repository: $targetName");
31
        $this->generateInterface($targetName);
32
        $this->generateRepository($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($name, 'repository_interface',
45
            $this->getRepositoriesPath().ucwords($name).'RepositoryInterface.php');
46
    }
47
48
    /**
49
     * Generate repository file.
50
     *
51
     * @param $name
52
     */
53
    protected function generateRepository($name)
54
    {
55
        $this->proceedAndSaveFile($name, 'repository',
56
            $this->getRepositoriesPath().'/Eloquent/'.ucwords($name).'EloquentRepository.php');
57
    }
58
59
    /**
60
     * @param string $name
61
     *
62
     * @return bool
63
     */
64
    protected function bindInterface($name)
65
    {
66
        $className = ucwords($name);
67
68
        $bindService = $this->filesystem->get($this->getBindServiceProviderPath());
69
        $key = '//---MORE BINDING---//';
70
71
        $bind = '$this->app->singleton('.PHP_EOL.'            \\App\\Repositories\\'.$className.'RepositoryInterface::class,'.PHP_EOL.'            \\App\\Repositories\\Eloquent\\'.$className.'EloquentRepository::class'.PHP_EOL.'        );'.PHP_EOL.'        '.$key;
72
        $bindService = str_replace($key, $bind, $bindService);
73
        $this->filesystem->put($this->getBindServiceProviderPath(), $bindService);
74
75
        return true;
76
    }
77
}
78