summaryrefslogtreecommitdiffstats
path: root/lib/private/Security
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2018-01-13 21:46:27 +0100
committerMorris Jobke <hey@morrisjobke.de>2018-01-14 21:15:44 +0100
commitbb2938a47dd86edae5e94bb9e0775250bb0a2aa9 (patch)
tree3245bf1de8da42dab4704e95d8abf94e3cfa2ae9 /lib/private/Security
parent60f38d37fe5ca505258510adc1e106da54426510 (diff)
downloadnextcloud-server-bb2938a47dd86edae5e94bb9e0775250bb0a2aa9.tar.gz
nextcloud-server-bb2938a47dd86edae5e94bb9e0775250bb0a2aa9.zip
Make IPAddress typed and strict
* Added scalar typehints * Added return statements * Added strict declaration Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/private/Security')
-rw-r--r--lib/private/Security/Normalizer/IpAddress.php16
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/private/Security/Normalizer/IpAddress.php b/lib/private/Security/Normalizer/IpAddress.php
index e9bb0be34cc..84c87054c76 100644
--- a/lib/private/Security/Normalizer/IpAddress.php
+++ b/lib/private/Security/Normalizer/IpAddress.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2017 Lukas Reschke <lukas@statuscode.ch>
*
@@ -36,7 +37,7 @@ class IpAddress {
/**
* @param string $ip IP to normalized
*/
- public function __construct($ip) {
+ public function __construct(string $ip) {
$this->ip = $ip;
}
@@ -47,13 +48,12 @@ class IpAddress {
* @param int $maskBits
* @return string
*/
- private function getIPv4Subnet($ip,
- $maskBits = 32) {
+ private function getIPv4Subnet(string $ip, int $maskBits = 32): string {
$binary = \inet_pton($ip);
for ($i = 32; $i > $maskBits; $i -= 8) {
$j = \intdiv($i, 8) - 1;
$k = (int) \min(8, $i - $maskBits);
- $mask = (0xff - ((pow(2, $k)) - 1));
+ $mask = (0xff - ((2 ** $k) - 1));
$int = \unpack('C', $binary[$j]);
$binary[$j] = \pack('C', $int[1] & $mask);
}
@@ -67,12 +67,12 @@ class IpAddress {
* @param int $maskBits
* @return string
*/
- private function getIPv6Subnet($ip, $maskBits = 48) {
+ private function getIPv6Subnet(string $ip, int $maskBits = 48): string {
$binary = \inet_pton($ip);
for ($i = 128; $i > $maskBits; $i -= 8) {
$j = \intdiv($i, 8) - 1;
$k = (int) \min(8, $i - $maskBits);
- $mask = (0xff - ((pow(2, $k)) - 1));
+ $mask = (0xff - ((2 ** $k) - 1));
$int = \unpack('C', $binary[$j]);
$binary[$j] = \pack('C', $int[1] & $mask);
}
@@ -84,7 +84,7 @@ class IpAddress {
*
* @return string
*/
- public function getSubnet() {
+ public function getSubnet(): string {
if (\preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $this->ip)) {
return $this->getIPv4Subnet(
$this->ip,
@@ -102,7 +102,7 @@ class IpAddress {
*
* @return string
*/
- public function __toString() {
+ public function __toString(): string {
return $this->ip;
}
}