TymonJwtInstaller::compileFileStub()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
namespace Lacasera\ApiJwtScaffold\Installers;
3
4
use Illuminate\Console\DetectsApplicationNamespace;
5
6
class TymonJwtInstaller extends InstallerContract
7
{
8
    use DetectsApplicationNamespace;
9
10
    /**
11
     * @var array
12
     */
13
    protected $commands = [
14
        'vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider"',
15
        'jwt:secret'
16
    ];
17
18
    /**
19
     * @var array
20
     */
21
    protected $filesToCopy = [
22
        'model/User.stub' => 'User.php',
23
        'controllers/AuthController.stub' => 'Http/Controllers/Auth/AuthController.php',
24
        'controllers/RegisterController.stub' => 'Http/Controllers/Auth/RegisterController.php'
25
    ];
26
27
    /**
28
     * copy compiled stubs to their correct locations
29
     */
30 View Code Duplication
    public function copyFiles()
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...
31
    {
32
        file_put_contents(
33
            config_path('auth.php'),
34
            $this->compileFileStub('config/auth.stub')
35
        );
36
37
        foreach ($this->filesToCopy as $stub => $file) {
38
            file_put_contents(
39
                app_path($file),
40
                $this->compileFileStub($stub)
41
            );
42
        }
43
    }
44
45
    /**
46
     * @param $file
47
     * @return mixed
48
     */
49
    protected function compileFileStub($file)
50
    {
51
        return str_replace(
52
            '{{namespace}}',
53
            $this->getAppNamespace(),
54
            file_get_contents(__DIR__."/stubs/tymon/$file")
55
        );
56
    }
57
58
    /**
59
     * scaffolds api authentication with tymon-jwt
60
     * @return bool
61
     */
62 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...
63
    {
64
        if (!class_exists('Tymon\JWTAuth\Claims\Subject')) {
65
            $this->installPackage('tymon/jwt-auth ^1.0.0-rc.3');
66
        }
67
68
        $this->runCommands($this->commands);
69
70
        $this->copyFiles();
71
72
        return true;
73
    }
74
}
75