Code Duplication    Length = 11-12 lines in 2 locations

lib/private/Security/Normalizer/IpAddress.php 2 locations

@@ 48-59 (lines=12) @@
45
	 * @param int $maskBits
46
	 * @return string
47
	 */
48
	private function getIPv4Subnet($ip,
49
								   $maskBits = 32) {
50
		$binary = \inet_pton($ip);
51
		for ($i = 32; $i > $maskBits; $i -= 8) {
52
			$j = \intdiv($i, 8) - 1;
53
			$k = (int) \min(8, $i - $maskBits);
54
			$mask = (0xff - ((pow(2, $k)) - 1));
55
			$int = \unpack('C', $binary[$j]);
56
			$binary[$j] = \pack('C', $int[1] & $mask);
57
		}
58
		return \inet_ntop($binary).'/'.$maskBits;
59
	}
60
61
	/**
62
	 * Return the given subnet for an IPv6 address and mask bits
@@ 68-78 (lines=11) @@
65
	 * @param int $maskBits
66
	 * @return string
67
	 */
68
	private function getIPv6Subnet($ip, $maskBits = 48) {
69
		$binary = \inet_pton($ip);
70
		for ($i = 128; $i > $maskBits; $i -= 8) {
71
			$j = \intdiv($i, 8) - 1;
72
			$k = (int) \min(8, $i - $maskBits);
73
			$mask = (0xff - ((pow(2, $k)) - 1));
74
			$int = \unpack('C', $binary[$j]);
75
			$binary[$j] = \pack('C', $int[1] & $mask);
76
		}
77
		return \inet_ntop($binary).'/'.$maskBits;
78
	}
79
80
	/**
81
	 * Gets either the /32 (IPv4) or the /128 (IPv6) subnet of an IP address