Code Duplication    Length = 24-24 lines in 2 locations

PHPDaemon/Servers/WebSocket/Protocols/V0.php 1 location

@@ 74-97 (lines=24) @@
71
	 * @param string Key
72
	 * @return string Result
73
	 */
74
	protected function _computeKey($key) {
75
		$spaces = 0;
76
		$digits = '';
77
78
		for ($i = 0, $s = strlen($key); $i < $s; ++$i) {
79
			$c = binarySubstr($key, $i, 1);
80
81
			if ($c === "\x20") {
82
				++$spaces;
83
			}
84
			elseif (ctype_digit($c)) {
85
				$digits .= $c;
86
			}
87
		}
88
89
		if ($spaces > 0) {
90
			$result = (float)floor($digits / $spaces);
91
		}
92
		else {
93
			$result = (float)$digits;
94
		}
95
96
		return pack('N', $result);
97
	}
98
99
	/**
100
	 * Sends a frame.

PHPDaemon/Servers/WebSocket/Protocols/VE.php 1 location

@@ 47-70 (lines=24) @@
44
	 * @param string Key
45
	 * @return string Result
46
	 */
47
	protected function _computeKey($key) {
48
		$spaces = 0;
49
		$digits = '';
50
51
		for ($i = 0, $s = strlen($key); $i < $s; ++$i) {
52
			$c = binarySubstr($key, $i, 1);
53
54
			if ($c === "\x20") {
55
				++$spaces;
56
			}
57
			elseif (ctype_digit($c)) {
58
				$digits .= $c;
59
			}
60
		}
61
62
		if ($spaces > 0) {
63
			$result = (float)floor($digits / $spaces);
64
		}
65
		else {
66
			$result = (float)$digits;
67
		}
68
69
		return pack('N', $result);
70
	}
71
72
	/**
73
	 * Sends a frame.