Completed
Pull Request — master (#4630)
by Lukas
12:40
created
lib/private/Security/Bruteforce/Throttler.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 	private function getCutoff($expire) {
80 80
 		$d1 = new \DateTime();
81 81
 		$d2 = clone $d1;
82
-		$d2->sub(new \DateInterval('PT' . $expire . 'S'));
82
+		$d2->sub(new \DateInterval('PT'.$expire.'S'));
83 83
 		return $d2->diff($d1);
84 84
 	}
85 85
 
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 									$ip,
95 95
 									array $metadata = []) {
96 96
 		// No need to log if the bruteforce protection is disabled
97
-		if($this->config->getSystemValue('auth.bruteforce.protection.enabled', true) === false) {
97
+		if ($this->config->getSystemValue('auth.bruteforce.protection.enabled', true) === false) {
98 98
 			return;
99 99
 		}
100 100
 
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 		$values = [
103 103
 			'action' => $action,
104 104
 			'occurred' => $this->timeFactory->getTime(),
105
-			'ip' => (string)$ipAddress,
105
+			'ip' => (string) $ipAddress,
106 106
 			'subnet' => $ipAddress->getSubnet(),
107 107
 			'metadata' => json_encode($metadata),
108 108
 		];
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 
121 121
 		$qb = $this->db->getQueryBuilder();
122 122
 		$qb->insert('bruteforce_attempts');
123
-		foreach($values as $column => $value) {
123
+		foreach ($values as $column => $value) {
124 124
 			$qb->setValue($column, $qb->createNamedParameter($value));
125 125
 		}
126 126
 		$qb->execute();
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 	 * @return bool
134 134
 	 */
135 135
 	private function isIPWhitelisted($ip) {
136
-		if($this->config->getSystemValue('auth.bruteforce.protection.enabled', true) === false) {
136
+		if ($this->config->getSystemValue('auth.bruteforce.protection.enabled', true) === false) {
137 137
 			return true;
138 138
 		}
139 139
 
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 
159 159
 			$cx = explode('/', $cidr);
160 160
 			$addr = $cx[0];
161
-			$mask = (int)$cx[1];
161
+			$mask = (int) $cx[1];
162 162
 
163 163
 			// Do not compare ipv4 to ipv6
164 164
 			if (($type === 4 && !filter_var($addr, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) ||
@@ -169,9 +169,9 @@  discard block
 block discarded – undo
169 169
 			$addr = inet_pton($addr);
170 170
 
171 171
 			$valid = true;
172
-			for($i = 0; $i < $mask; $i++) {
173
-				$part = ord($addr[(int)($i/8)]);
174
-				$orig = ord($ip[(int)($i/8)]);
172
+			for ($i = 0; $i < $mask; $i++) {
173
+				$part = ord($addr[(int) ($i / 8)]);
174
+				$orig = ord($ip[(int) ($i / 8)]);
175 175
 
176 176
 				$part = $part & (15 << (1 - ($i % 2)));
177 177
 				$orig = $orig & (15 << (1 - ($i % 2)));
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 	 */
201 201
 	public function getDelay($ip, $action = '') {
202 202
 		$ipAddress = new IpAddress($ip);
203
-		if ($this->isIPWhitelisted((string)$ipAddress)) {
203
+		if ($this->isIPWhitelisted((string) $ipAddress)) {
204 204
 			return 0;
205 205
 		}
206 206
 
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 
227 227
 		$maxDelay = 30;
228 228
 		$firstDelay = 0.1;
229
-		if ($attempts > (8 * PHP_INT_SIZE - 1))  {
229
+		if ($attempts > (8 * PHP_INT_SIZE - 1)) {
230 230
 			// Don't ever overflow. Just assume the maxDelay time:s
231 231
 			$firstDelay = $maxDelay;
232 232
 		} else {
Please login to merge, or discard this patch.