LaravelPassportInstaller   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 73
Duplicated Lines 36.99 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 27
loc 73
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A copyFiles() 14 14 2
A compileFileStub() 0 8 1
A scaffold() 12 12 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace Lacasera\ApiJwtScaffold\Installers;
3
4
use Illuminate\Console\DetectsApplicationNamespace;
5
6
class LaravelPassportInstaller extends InstallerContract
7
{
8
    use DetectsApplicationNamespace;
9
10
    /**
11
     * @var array
12
     */
13
    protected $filesToCopy = [
14
        'model/User.stub' => 'User.php',
15
        'providers/AuthServiceProvider.stub' => 'Providers/AuthServiceProvider.php',
16
        'controllers/AuthController.stub' => 'Http/Controllers/Auth/AuthController.php',
17
        'controllers/RegisterController.stub' => 'Http/Controllers/Auth/RegisterController.php'
18
    ];
19
20
    /**
21
     * @var array
22
     */
23
    protected $commands = [
24
        'migrate',
25
        'passport:install',
26
        'passport:keys',
27
        'passport:client --personal'
28
    ];
29
30
    /**
31
     * copy files from stubs/passport to their appropriate locations
32
     */
33 View Code Duplication
    public function copyFiles(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
    {
35
        file_put_contents(
36
            config_path('auth.php'),
37
            $this->compileFileStub('config/auth.stub')
38
        );
39
40
        foreach ($this->filesToCopy as $stub => $file) {
41
            file_put_contents(
42
                app_path($file),
43
                $this->compileFileStub($stub)
44
            );
45
        }
46
    }
47
48
49
    /**
50
     * @param $file
51
     * @return mixed
52
     */
53
    protected function compileFileStub($file)
54
    {
55
        return str_replace(
56
            '{{namespace}}',
57
            $this->getAppNamespace(),
58
            file_get_contents(__DIR__."/stubs/laravel-passport/$file")
59
        );
60
    }
61
62
    /**
63
     * scaffolds api authentication with laravel passport
64
     * @return bool
65
     */
66 View Code Duplication
    public function scaffold()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
67
    {
68
        if (!class_exists("Laravel\Passport\Client")) {
69
            $this->installPackage('laravel/passport');
70
        }
71
72
        $this->runCommands($this->commands);
73
74
        $this->copyFiles();
75
76
        return true;
77
    }
78
}
79