IpCheckerController::__construct()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 1 Features 2
Metric Value
cc 4
eloc 8
c 4
b 1
f 2
nc 2
nop 0
dl 0
loc 13
rs 10
1
<?php
2
3
namespace HayriCan\IpChecker\Http\Controllers;
4
5
/**
6
 * Laravel IP Checker
7
 *
8
 * @author    Hayri Can BARÇIN <hayricanbarcin (#) gmail (.) com>
9
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
10
 * @link      https://github.com/HayriCan/laravel-ip-checker
11
 */
12
13
use HayriCan\IpChecker\Contracts\IpCheckerInterface;
14
use App\Http\Controllers\Controller;
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...
15
use Illuminate\Http\Request;
0 ignored issues
show
Bug introduced by
The type Illuminate\Http\Request 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...
16
use Illuminate\Support\Facades\Auth;
17
use Illuminate\Support\Facades\Validator;
0 ignored issues
show
Bug introduced by
The type Illuminate\Support\Facades\Validator 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...
18
19
class IpCheckerController extends Controller
20
{
21
    /**
22
     * Create a new controller instance.
23
     *
24
     * @return void
25
     */
26
    public function __construct()
27
    {
28
        $this->middleware(['web']);
29
        if (config('ipchecker.settings.auth')) {
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

29
        if (/** @scrutinizer ignore-call */ config('ipchecker.settings.auth')) {
Loading history...
30
            $this->middleware(['web','auth']);
31
            $this->middleware(function ($request, $next) {
32
                if (!empty(config('ipchecker.settings.admin_id'))){
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

32
                if (!empty(/** @scrutinizer ignore-call */ config('ipchecker.settings.admin_id'))){
Loading history...
33
                    if (!in_array(Auth::id(),config('ipchecker.settings.admin_id'))){
34
                        return abort(404);
35
                    }
36
                }
37
38
                return $next($request);
39
            });
40
        }
41
    }
42
43
    /**
44
     * Show the application dashboard.
45
     *
46
     * @param IpCheckerInterface $ipchecker
47
     * @return \Illuminate\Contracts\Support\Renderable
0 ignored issues
show
Bug introduced by
The type Illuminate\Contracts\Support\Renderable 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...
48
     */
49
    public function index(IpCheckerInterface $ipchecker)
50
    {
51
        $iplist = $ipchecker->getIpList();
52
53
        if(count($iplist)>0){
54
            $iplist = $iplist->sortByDesc('created_at');
55
        }
56
57
        return view('ipchecker::index',compact('iplist'));
0 ignored issues
show
Bug introduced by
The function view 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

57
        return /** @scrutinizer ignore-call */ view('ipchecker::index',compact('iplist'));
Loading history...
58
    }
59
60
    /**
61
     * @param Request $request
62
     * @param IpCheckerInterface $ipchecker
63
     * @return \Illuminate\Http\RedirectResponse
0 ignored issues
show
Bug introduced by
The type Illuminate\Http\RedirectResponse 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...
64
     */
65
    public function add(Request $request,IpCheckerInterface $ipchecker)
66
    {
67
        $request_data = $request->all();
68
        $request_validation = array(
69
            'group'=>'required|string',
70
            'definition'=>'required|string',
71
            'ip'=>'required|ip',
72
        );
73
        $validator = Validator::make($request_data, $request_validation);
74
        if ($validator->fails()) {
75
            return redirect()->back()->withErrors($validator->errors());
0 ignored issues
show
Bug introduced by
The function redirect 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

75
            return /** @scrutinizer ignore-call */ redirect()->back()->withErrors($validator->errors());
Loading history...
76
        }
77
78
        if (!in_array($request->input('ip'),$ipchecker->getIpArray())){
79
            $ipchecker->saveIp(array(
80
                'group'=>$request->input('group'),
81
                'definition'=>$request->input('definition'),
82
                'ip'=>$request->input('ip'),
83
            ));
84
85
            return redirect()->back()->with('success',trans('ipchecker::messages.ip_success'));
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

85
            return redirect()->back()->with('success',/** @scrutinizer ignore-call */ trans('ipchecker::messages.ip_success'));
Loading history...
86
        }
87
88
        return redirect()->back()->with('error',trans('ipchecker::messages.ip_error'));
89
    }
90
91
    /**
92
     * @param Request $request
93
     * @param IpCheckerInterface $ipchecker
94
     * @return \Illuminate\Http\RedirectResponse
95
     */
96
    public function delete(Request $request,IpCheckerInterface $ipchecker)
97
    {
98
        $ipchecker->deleteIp($request->input('ipAddress'));
99
100
        return redirect()->back()->with('info',trans('ipchecker::messages.ip_delete'));
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

100
        return redirect()->back()->with('info',/** @scrutinizer ignore-call */ trans('ipchecker::messages.ip_delete'));
Loading history...
Bug introduced by
The function redirect 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

100
        return /** @scrutinizer ignore-call */ redirect()->back()->with('info',trans('ipchecker::messages.ip_delete'));
Loading history...
101
    }
102
}
103