XhrSend   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 28 6
1
<?php
2
namespace PHPDaemon\SockJS\Methods;
3
4
/**
5
 * @package    Libraries
6
 * @subpackage SockJS
7
 * @author     Vasily Zorin <[email protected]>
8
 */
9
class XhrSend extends Generic
10
{
11
    protected $contentType = 'text/plain';
12
    protected $allowedMethods = 'POST';
13
14
    /**
15
     * Called when request iterated
16
     * @return void
17
     */
18
    public function run()
19
    {
20
        if ($this->stage++ > 0) {
21
            $this->header('500 Too Busy');
22
            return;
23
        }
24
        if ($this->attrs->raw === '') {
25
            $this->header('500 Internal Server Error');
26
            echo 'Payload expected.';
27
            return;
28
        }
29
        if (!json_decode($this->attrs->raw, true)) {
30
            $this->header('500 Internal Server Error');
31
            echo 'Broken JSON encoding.';
32
            return;
33
        }
34
        $this->appInstance->publish('c2s:' . $this->sessId, $this->attrs->raw, function ($redis) {
0 ignored issues
show
Documentation Bug introduced by
The method publish does not exist on object<PHPDaemon\Core\AppInstance>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
35
            if (!$this->headers_sent) {
36
                if ($redis->result === 0) {
37
                    $this->header('404 Not Found');
38
                } else {
39
                    $this->header('204 No Content');
40
                }
41
            }
42
            $this->finish();
43
        });
44
        $this->sleep(10);
45
    }
46
}
47