Passed
Push — master ( 05a102...8d2f81 )
by IRFA
03:53 queued 11s
created

Testing::testConfig()   D

Complexity

Conditions 11
Paths 385

Size

Total Lines 73
Code Lines 50

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 11
eloc 50
c 0
b 0
f 0
nc 385
nop 0
dl 0
loc 73
rs 4.1708

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php 
2
namespace Irfa\Lockout\Func;
3
4
use Irfa\Lockout\Func\Core;
5
use Illuminate\Console\Command;
6
use View;
7
use File;
8
9
class Testing extends Core {
10
11
    public function testConfig(){
12
        $ret=[];
13
        $ret['err'] = 0;
14
        if(!empty(config('irfa.lockout'))){
15
            if(is_numeric(config('irfa.lockout.login_attemps'))){
16
                $ret['login_attemps'] = '<fg=green>OK';
17
            } else{
18
19
                $ret['err'] +=1;
20
                $ret['login_attemps'] ='<fg=yellow>Must be a number';
21
            }
22
23
            if(is_bool(config('irfa.lockout.logging'))){
24
               $ret['logging'] = '<fg=green>OK';
25
            } else{
26
27
                $ret['err'] +=1;
28
                $ret['logging'] = '<fg=yellow>Must be a Boolean'; 
29
            }
30
31
            if(is_string(config('irfa.lockout.input_name'))){
32
                $ret['input_name'] = '<fg=green>OK';
33
            } else{
34
35
                $ret['err'] +=1;
36
                $ret['input_name'] = '<fg=yellow>Must be a String'; 
37
            }
38
            if(is_writable(config('irfa.lockout.lockout_file_path'))){
39
                $ret['lockout_file_path'] = '<fg=green>OK';
40
            } else{
41
                $ret['lockout_file_path'] = '<fg=yellow>Write Permission Denied in '.config('irfa.lockout.lockout_file_path'); 
42
            }
43
44
             if(!empty(config('irfa.lockout.redirect_url'))){
45
                $ret['redirect_url'] = '<fg=green>OK';
46
            } else{
47
48
                $ret['err'] +=1;
49
                $ret['redirect_url'] = '<fg=yellow>Must be provided'; 
50
            }
51
            if(is_array(config('irfa.lockout.protected_action_path'))){
52
                $ret['protected_action_path'] = '<fg=green>OK';
53
            } else{
54
55
                $ret['err'] +=1;
56
                $ret['protected_action_path'] = '<fg=yellow>Must be array'; 
57
            }
58
59
            if(is_array(config('irfa.lockout.protected_middleware_group'))){
60
                if(!empty(config('irfa.lockout.protected_middleware_group'))){
61
                    $ret['protected_middleware_group'] = '<fg=green>OK';
62
                } else{
63
                     $ret['err'] +=1;
64
                     $ret['protected_middleware_group'] = '<fg=yellow>Must be provided'; 
65
                }
66
            } else{
67
68
                $ret['err'] +=1;
69
                $ret['protected_middleware_group'] = '<fg=yellow>Must be array'; 
70
            }
71
            if(is_string(config('irfa.lockout.message_name'))){
72
                $ret['message_name'] = '<fg=green>OK';
73
            } else{
74
75
                $ret['err'] +=1;
76
                $ret['message_name'] = '<fg=yellow>Must be a String'; 
77
            }
78
        } else{
79
            $ret['err'] +=1;
80
            $ret['file'] = "<fg=yellow> Could't find config file. Try to run <fg=cyan>php artisan vendor:publish --tag=lockout-account"; 
81
        }
82
83
        return $ret;
84
    }
85
	public function testWriteEventFailedLogin($username){
86
87
    	$this->eventFailedLogin($username);
88
89
		$input = $username;
90
		$dir = config('irfa.lockout.lockout_file_path');
91
		$path = $dir.md5($input);
92
93
    	if(File::exists($path))
94
        {
95
        	return true;
96
        } 
97
    		return false;
98
    }
99
    public function testWritable($username){
100
		$input = $username;
101
		$dir = config('irfa.lockout.lockout_file_path');
102
		$path = $dir.md5($input);
103
104
    	if(is_writable($path))
105
        {
106
        	return true;
107
        } 
108
    		return false;
109
    }
110
111
    public function testManualLocking($username){
112
        $input = $username;
113
        $dir = config('irfa.lockout.lockout_file_path');
114
        $path = $dir.md5($input);
0 ignored issues
show
Unused Code introduced by
The assignment to $path is dead and can be removed.
Loading history...
115
116
        if($this->lock_account($username))
117
        {
118
            return true;
119
        } 
120
            return false;
121
    }
122
123
    public function testUnlocking($username){
124
        $input = $username;
125
        $dir = config('irfa.lockout.lockout_file_path');
126
        $path = $dir.md5($input);
0 ignored issues
show
Unused Code introduced by
The assignment to $path is dead and can be removed.
Loading history...
127
        $unlock =  $this->test_unlock_account($username);
128
        if($unlock)
129
        {
130
            return true;
131
        } 
132
            return false;
133
    }
134
    public function testLockLogin($username){
135
        $input = $username;
136
        $dir = config('irfa.lockout.lockout_file_path');
137
        $path = $dir.md5($input);
0 ignored issues
show
Unused Code introduced by
The assignment to $path is dead and can be removed.
Loading history...
138
        $unlock =  $this->lockLogin($username);
139
        if($unlock)
140
        {
141
            return true;
142
        } 
143
            return false;
144
    }
145
}
146