Code Duplication    Length = 24-24 lines in 2 locations

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

@@ 81-104 (lines=24) @@
78
     * @param string Key
79
     * @return string Result
80
     */
81
    protected function _computeKey($key)
82
    {
83
        $spaces = 0;
84
        $digits = '';
85
86
        for ($i = 0, $s = mb_orig_strlen($key); $i < $s; ++$i) {
87
            $c = mb_orig_substr($key, $i, 1);
88
89
            if ($c === "\x20") {
90
                ++$spaces;
91
            } elseif (ctype_digit($c)) {
92
                $digits .= $c;
93
            }
94
        }
95
96
        if ($spaces > 0) {
97
            $result = (float)floor($digits / $spaces);
98
        } else {
99
            $result = (float)$digits;
100
        }
101
102
        return pack('N', $result);
103
    }
104
105
    /**
106
     * Sends a frame.
107
     * @param  string $data Frame's data.

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

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