SimpleRequest::run()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 46

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 46
rs 9.1781
c 0
b 0
f 0
nc 1
nop 0
1
<?php
2
namespace PHPDaemon\SockJS\Examples;
3
4
use PHPDaemon\HTTPRequest\Generic;
5
6
class SimpleRequest extends Generic
7
{
8
    /**
9
     * Called when request iterated.
10
     * @return integer Status.
0 ignored issues
show
Documentation introduced by
Should the return type not be integer|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
11
     */
12
    public function run()
13
    {
14
        $this->header('Content-Type: text/html');
15
        ?>
16
        <!DOCTYPE html>
17
        <html>
18
        <head>
19
            <title>SockJS test page</title>
20
            <script src="//cdn.jsdelivr.net/sockjs/0.3.4/sockjs.min.js"></script>
21
        </head>
22
        <body>
23
        <script>
24
            var sock, logElem;
25
26
            function addLog(msg) {
27
                logElem.innerHTML = msg + '<br />' + logElem.innerHTML;
28
            }
29
30
            function create() {
31
                logElem = document.getElementById('log');
32
                sock = new SockJS('http://' + document.domain + ':8068/sockjs/');
33
                sock.onopen = function () {
34
                    addLog('SockJS opened');
35
                }
36
                sock.onmessage = function (e) {
37
                    addLog('<<< : ' + e.data);
38
                }
39
                sock.onclose = function () {
40
                    addLog('closed');
41
                }
42
            }
43
44
            function send(data) {
45
                sock && sock.send(data);
46
                addLog('>>> : ' + data);
47
            }
48
        </script>
49
50
        <button onclick="create();">Create SockJS</button>
51
        <button onclick="send('ping');">Send ping</button>
52
        <button onclick="sock && sock.close();">Close SockJS</button>
53
        <div id="log" style="width:300px; height: 300px; border: 1px solid #999999; overflow:auto;"></div>
54
        </body>
55
        </html>
56
        <?php
57
    }
58
}
59