Conditions | 2 |
Paths | 2 |
Total Lines | 119 |
Code Lines | 78 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
43 | public function provideWriteJsConnectTests() { |
||
44 | |||
45 | $clientID = 'clientID'; |
||
46 | $timestamp = time(); |
||
47 | $secret = 'secret'; |
||
48 | $ip = '127.0.0.1'; |
||
49 | $secure = 'sha256'; |
||
50 | $nonce = 'nonceToken'; |
||
51 | $sig = jsHash($ip.$nonce.$timestamp.$secret, $secure); |
||
52 | $version = '2'; |
||
53 | |||
54 | $userData = array( |
||
55 | 'name' => 'John PHP', |
||
56 | 'email' => '[email protected]', |
||
57 | 'unique_id' => '123', |
||
58 | ); |
||
59 | |||
60 | $fnGenerateTestData = function() use (&$userData, &$clientID, &$timestamp, &$secret, &$ip, &$secure, &$nonce, &$sig, &$version) { |
||
61 | $request = array( |
||
62 | 'client_id' => $clientID, |
||
63 | 'ip' => $ip, |
||
64 | 'nonce' => $nonce, |
||
65 | 'sig' => $sig, |
||
66 | 'timestamp' => $timestamp, |
||
67 | 'v' => $version, |
||
68 | ); |
||
69 | |||
70 | $expectedResult = array( |
||
71 | 'sig' => signJsConnect( |
||
72 | $userData + ['ip' => $ip, 'nonce' => $nonce], |
||
73 | $clientID, |
||
74 | $secret, |
||
75 | $secure |
||
76 | ) |
||
77 | ) + $request + $userData; |
||
78 | unset($expectedResult['timestamp']); |
||
79 | ksort($expectedResult); |
||
80 | |||
81 | return [ |
||
82 | 'userData' => $userData, |
||
83 | 'request' => $request, |
||
84 | 'clientID' => $clientID, |
||
85 | 'secret' => $secret, |
||
86 | 'secure' => $secure, |
||
87 | 'expectedResult' => $expectedResult, |
||
88 | ]; |
||
89 | }; |
||
90 | |||
91 | $fnGenerateAlteratedData = function(&$var, $value, $expectedResult) use ($fnGenerateTestData) { |
||
92 | $tmpVar = $var; |
||
93 | $var = $value; |
||
94 | $data = $fnGenerateTestData(); |
||
95 | $var = $tmpVar; |
||
96 | $data['expectedResult'] = $expectedResult; |
||
97 | return $data; |
||
98 | }; |
||
99 | |||
100 | $data = []; |
||
101 | // Default |
||
102 | $data['default'] = $fnGenerateTestData(); |
||
103 | |||
104 | // Wrong version |
||
105 | $data['wrongVersion'] = $fnGenerateAlteratedData( |
||
106 | $version, 1, array('error' => 'invalid_request', 'message' => "Unsupported version 1.") |
||
107 | ); |
||
108 | |||
109 | // Missings |
||
110 | $missings = array('v', 'client_id', 'sig', 'nonce', 'ip'); |
||
111 | foreach ($missings as $missing) { |
||
112 | $tmp = $fnGenerateTestData(); |
||
113 | unset($tmp['request'][$missing]); |
||
114 | $tmp['expectedResult'] = array('error' => 'invalid_request', 'message' => "Missing the $missing parameter."); |
||
115 | $data["missing[$missing]"] = $tmp; |
||
116 | } |
||
117 | |||
118 | // Missing timestamp |
||
119 | $tmp = $fnGenerateTestData(); |
||
120 | unset($tmp['request']['timestamp']); |
||
121 | $tmp['expectedResult'] = array('error' => 'invalid_request', 'message' => 'The timestamp parameter is missing or invalid.'); |
||
122 | $data['missing[timestamp]'] = $tmp; |
||
123 | |||
124 | // Non numeric timestamp |
||
125 | $data['invalidTimestamp'] = $fnGenerateAlteratedData( |
||
126 | $timestamp, 'notatimestamp', array('error' => 'invalid_request', 'message' => 'The timestamp parameter is missing or invalid.') |
||
127 | ); |
||
128 | |||
129 | // Timed Out timestamp |
||
130 | $data['timedOutTimestamp'] = $fnGenerateAlteratedData( |
||
131 | $timestamp, ($timestamp - (JS_TIMEOUT + 1)), array('error' => 'invalid_request', 'message' => 'The timestamp is invalid.') |
||
132 | ); |
||
133 | |||
134 | // Bad client_id |
||
135 | $tmp = $fnGenerateTestData(); |
||
136 | $tmp['request']['client_id'] = 'wrong'.$clientID; |
||
137 | $tmp['expectedResult'] = array('error' => 'invalid_client', 'message' => "Unknown client {$tmp['request']['client_id']}."); |
||
138 | $data['wrongClientID'] = $tmp; |
||
139 | |||
140 | // No sig, no timestamp sent with user logged |
||
141 | $tmp = $fnGenerateTestData(); |
||
142 | unset($tmp['request']['sig'], $tmp['request']['timestamp']); |
||
143 | $tmp['expectedResult'] = array('name' => 'John PHP', 'photourl' => null, 'signedin' => true); |
||
144 | $data['noSigNoTimestamp'] = $tmp; |
||
145 | |||
146 | // No sig, no timestamp sent with user not logged |
||
147 | $tmp = $fnGenerateTestData(); |
||
148 | $tmp['userData'] = []; |
||
149 | unset($tmp['request']['sig'], $tmp['request']['timestamp']); |
||
150 | $tmp['expectedResult'] = array('name' => '', 'photourl' => ''); |
||
151 | $data['noSigNoTimestamp'] = $tmp; |
||
152 | |||
153 | // Bad signature |
||
154 | $data['badSignature'] = $fnGenerateAlteratedData( |
||
155 | $ip, '255.255.255.255', array('error' => 'access_denied', 'message' => 'Signature invalid.') |
||
156 | ); |
||
157 | |||
158 | // Secure disabled |
||
159 | $data['timedOutTimestamp'] = $fnGenerateAlteratedData($secure, null, $userData); |
||
160 | |||
161 | return $data; |
||
162 | } |
||
164 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths