PasswordsManager   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 15
c 2
b 0
f 0
dl 0
loc 52
ccs 0
cts 17
cp 0
rs 10
wmc 9

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 12 6
A isAdminArea() 0 7 2
A __construct() 0 3 1
1
<?php
2
3
namespace Terranet\Administrator\Providers\Handlers;
4
5
use Illuminate\Contracts\Config\Repository;
6
use Illuminate\Routing\Events\RouteMatched;
7
use Illuminate\Support\Arr;
8
use Terranet\Administrator\Traits\SessionGuardHelper;
9
10
class PasswordsManager
11
{
12
    use SessionGuardHelper;
13
14
    /**
15
     * @var Repository
16
     */
17
    private $config;
18
19
    /**
20
     * PasswordsManager constructor.
21
     *
22
     * @param Repository $config
23
     */
24
    public function __construct(Repository $config)
25
    {
26
        $this->config = $config;
27
    }
28
29
    public function handle()
30
    {
31
        app('router')->matched(function (RouteMatched $event) {
0 ignored issues
show
Bug introduced by
The function app was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

31
        /** @scrutinizer ignore-call */ 
32
        app('router')->matched(function (RouteMatched $event) {
Loading history...
32
            if (!$this->isAdminArea($event)) {
33
                return false;
34
            }
35
36
            if ($manage = $this->config->get('administrator.manage_passwords')) {
0 ignored issues
show
Unused Code introduced by
The assignment to $manage is dead and can be removed.
Loading history...
37
                if ($model = $this->fetchModel($this->config)) {
38
                    $model::saving(function ($user) {
39
                        if (!empty($user->password) && $user->isDirty('password')) {
40
                            $user->password = bcrypt($user->password);
0 ignored issues
show
Bug introduced by
The function bcrypt was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
                            $user->password = /** @scrutinizer ignore-call */ bcrypt($user->password);
Loading history...
41
                        }
42
                    });
43
                }
44
            }
45
        });
46
    }
47
48
    /**
49
     * Check if running under admin area.
50
     *
51
     * @param RouteMatched $event
52
     *
53
     * @return bool
54
     */
55
    protected function isAdminArea(RouteMatched $event)
56
    {
57
        if ($action = $event->route->getAction()) {
58
            return config('administrator.prefix') === Arr::get($action, 'prefix');
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

58
            return /** @scrutinizer ignore-call */ config('administrator.prefix') === Arr::get($action, 'prefix');
Loading history...
59
        }
60
61
        return false;
62
    }
63
}
64