ExampleAsyncProcessRequest::run()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
nc 2
nop 0
1
<?php
2
namespace PHPDaemon\Examples;
3
4
use PHPDaemon\HTTPRequest\Generic;
5
6
class ExampleAsyncProcessRequest extends Generic
7
{
8
9
    public $proc;
10
11
    /**
12
     * Constructor.
13
     * @return void
14
     */
15
    public function init()
16
    {
17
        $this->header('Content-Type: text/plain');
18
19
        $this->proc = new \PHPDaemon\Core\ShellCommand();
20
        $this->proc->onReadData(function ($stream, $data) {
0 ignored issues
show
Documentation Bug introduced by
The method onReadData does not exist on object<PHPDaemon\Core\ShellCommand>? 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...
21
            echo $data;
22
        });
23
        $this->proc->onEOF(function ($stream) {
0 ignored issues
show
Unused Code introduced by
The parameter $stream is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
24
            $this->wakeup();
25
        });
26
        $this->proc->nice(256);
27
        $this->proc->execute('/bin/ls -l /tmp');
28
    }
29
30
    public function onAbort()
31
    {
32
        if ($this->proc) {
33
            $this->proc->close();
34
        }
35
    }
36
37
    public function onFinish()
38
    {
39
        $this->proc = null;
40
    }
41
42
    /**
43
     * Called when request iterated.
44
     * @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...
45
     */
46
    public function run()
47
    {
48
        if (!$this->proc->eof()) {
49
            $this->sleep(1);
50
        }
51
    }
52
}
53