AuthController::guard()   A
last analyzed

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
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 1
cp 0
crap 2
rs 10
1
<?php
2
3
namespace Terranet\Administrator\Controllers;
4
5
use Illuminate\Support\Facades\URL;
6
use Illuminate\Support\Facades\Auth;
7
use Illuminate\Http\RedirectResponse;
8
use Illuminate\Support\Facades\View;
9
use Terranet\Administrator\Architect;
10
use Illuminate\Support\Facades\Redirect;
11
use Terranet\Administrator\Requests\LoginRequest;
12
use Illuminate\Contracts\View\View as ViewContract;
13
use App\Http\Controllers\Controller as BaseController;
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Controller was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
15
class AuthController extends BaseController
16
{
17
    /**
18
     * @param  LoginRequest  $request
19 2
     * @return RedirectResponse
20
     */
21 2
    public function postLogin(LoginRequest $request)
22
    {
23
        $config = app('scaffold.config');
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

23
        $config = /** @scrutinizer ignore-call */ app('scaffold.config');
Loading history...
24 2
25
        // basic login policy
26 2
        $credentials = $request->only(
27 2
            [
28
                $config->get('auth.identity', 'username'),
29
                $config->get('auth.credential', 'password'),
30
            ]
31
        );
32 2
33 2
        // extend auth policy by allowing custom login conditions
34
        if ($conditions = $config->get('auth.conditions', [])) {
35
            $credentials = array_merge($credentials, $conditions);
36 2
        }
37
38 2
        $remember = (int) $request->get('remember_me', 0);
39 1
40 1
        if ($this->guard()->attempt($credentials, $remember, true)) {
41
            if (\is_callable($url = $config->get('home_page'))) {
42
                $url = \call_user_func($url);
43 1
            }
44
45
            return Redirect::to(URL::to($url));
46 1
        }
47
48
        return Redirect::back()->withErrors([trans('administrator::errors.login_failed')]);
0 ignored issues
show
Bug introduced by
The function trans 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

48
        return Redirect::back()->withErrors([/** @scrutinizer ignore-call */ trans('administrator::errors.login_failed')]);
Loading history...
49
    }
50
51
    /**
52 1
     * @return ViewContract
53
     */
54 1
    public function getLogin(): ViewContract
55 1
    {
56
        return View::make(
57
            Architect::template()->auth('login')
0 ignored issues
show
Bug introduced by
It seems like Terranet\Administrator\A...mplate()->auth('login') can also be of type array; however, parameter $view of Illuminate\Support\Facades\View::make() 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

57
            /** @scrutinizer ignore-type */ Architect::template()->auth('login')
Loading history...
58
        );
59
    }
60
61
    /**
62 1
     * @return RedirectResponse
63
     */
64 1
    public function getLogout()
65
    {
66 1
        $this->guard()->logout();
67 1
68
        return Redirect::to(
69
            URL::route('scaffold.login')
70
        );
71
    }
72
73
    /**
74
     * @return mixed
75
     */
76
    protected function guard()
77
    {
78
        return Auth::guard('admin');
79
    }
80
}
81