ExamplePubSubTestPageRequest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 1
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 38 1
1
<?php
2
namespace PHPDaemon\Examples;
3
4
use PHPDaemon\HTTPRequest\Generic;
5
6
class ExamplePubSubTestPageRequest extends Generic
7
{
8
9
/**
10
 * Called when request iterated.
11
 * @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...
12
 */
13
public function run()
14
{
15
$this->header('Content-Type: text/html');
16
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
17
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
18
<html xmlns="http://www.w3.org/1999/xhtml">
19
<head>
20
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
21
    <title>WebSocket test page</title>
22
</head>
23
<body>
24
<script>
25
    function create() {
26
        // Example
27
        ws = new WebSocket('ws://' + document.domain + ':8047/ExamplePubSub');
28
        ws.onopen = function () {
29
            document.getElementById('log').innerHTML += 'WebSocket opened <br/>';
30
        }
31
        ws.onmessage = function (e) {
32
            document.getElementById('log').innerHTML += 'WebSocket message: ' + e.data + ' <br/>';
33
        }
34
        ws.onclose = function () {
35
            document.getElementById('log').innerHTML += 'WebSocket closed <br/>';
36
        }
37
    }
38
    function subscribe() {
39
        ws.send('{"type":"subscribe","event":"usersNum"}');
40
    }
41
</script>
42
<button onclick="create();">Create WebSocket</button>
43
<button onclick="subscribe();">Send subscribe</button>
44
<button onclick="ws.close();">Close WebSocket</button>
45
<div id="log" style="width:300px; height: 300px; border: 1px solid #999999; overflow:auto;"></div>
46
</body>
47
</html>
48
<?php
49
50
}
51
}
52