Completed
Push — master ( 0d804a...a9861c )
by ARCANEDEV
04:25
created

PackagesServiceProvider::config()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php namespace Arcanesoft\Auth\Providers;
2
3
use Arcanedev\Gravatar\GravatarServiceProvider;
4
use Arcanedev\LaravelAuth\LaravelAuthServiceProvider;
5
use Arcanedev\LaravelAuth\Services\SocialAuthenticator;
6
use Arcanedev\Support\ServiceProvider;
7
use Illuminate\Support\Arr;
8
9
/**
10
 * Class     PackagesServiceProvider
11
 *
12
 * @package  Arcanesoft\Auth\Providers
13
 * @author   ARCANEDEV <[email protected]>
14
 */
15
class PackagesServiceProvider extends ServiceProvider
16
{
17
    /* ------------------------------------------------------------------------------------------------
18
     |  Main Functions
19
     | ------------------------------------------------------------------------------------------------
20
     */
21
    /**
22
     * Register the service provider.
23
     */
24 12
    public function register()
25
    {
26 12
        $this->registerGravatarPackage();
27 12
        $this->registerLaravelAuthPackage();
28 12
    }
29
30
    /* ------------------------------------------------------------------------------------------------
31
     |  Register Packages
32
     | ------------------------------------------------------------------------------------------------
33
     */
34
    /**
35
     * Register the gravatar package.
36
     */
37 12
    private function registerGravatarPackage()
38
    {
39 12
        $this->registerProvider(GravatarServiceProvider::class);
40 12
    }
41
42
    /**
43
     * Register the laravel auth package.
44
     */
45 12
    private function registerLaravelAuthPackage()
46
    {
47 12
        $this->registerProvider(LaravelAuthServiceProvider::class);
48
49 12
        $this->configLaravelAuthPackage();
50 12
        $this->rebindModels();
51 12
        $this->registerDependencies();
0 ignored issues
show
Unused Code introduced by
The call to the method Arcanesoft\Auth\Provider...:registerDependencies() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
52 12
    }
53
54
    /* ------------------------------------------------------------------------------------------------
55
     |  Config Packages
56
     | ------------------------------------------------------------------------------------------------
57
     */
58
    /**
59
     * Config the laravel auth package (override).
60
     */
61 12
    private function configLaravelAuthPackage()
62
    {
63
        /** @var  \Illuminate\Contracts\Config\Repository  $config */
64 12
        $config = $this->config();
65 12
        $config->set('laravel-auth', Arr::except($config->get('arcanesoft.auth'), ['route', 'hasher']));
66
67 12
        if (SocialAuthenticator::isEnabled()) {
68
            $this->registerProvider(\Laravel\Socialite\SocialiteServiceProvider::class);
69
        }
70 12
    }
71
72
    /**
73
     * Rebind the auth models.
74
     */
75 12
    private function rebindModels()
76
    {
77 12
        $config   = $this->config();
78
        $bindings = [
79
            [
80 12
                'abstract' => \Arcanesoft\Contracts\Auth\Models\User::class,
81 12
                'concrete' => $config->get('arcanesoft.auth.users.model'),
82 12
            ],[
83 12
                'abstract' => \Arcanesoft\Contracts\Auth\Models\Role::class,
84 12
                'concrete' => $config->get('arcanesoft.auth.roles.model'),
85 12
            ],[
86 12
                'abstract' => \Arcanesoft\Contracts\Auth\Models\Permission::class,
87 12
                'concrete' => $config->get('arcanesoft.auth.permissions.model'),
88 12
            ],[
89 12
                'abstract' => \Arcanesoft\Contracts\Auth\Models\PermissionsGroup::class,
90 12
                'concrete' => $config->get('arcanesoft.auth.permissions-groups.model'),
91 12
            ],
92 12
        ];
93
94 12
        foreach ($bindings as $binding) {
95 12
            $this->bind($binding['abstract'], $binding['concrete']);
96 12
        }
97 12
    }
98
99
    /**
100
     * Register the package dependencies.
101
     */
102 12
    private function registerDependencies()
103
    {
104
        //
105 12
    }
106
}
107