N2Daemon::startup()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Normally nsqd daemon API
4
 * User: moyo
5
 * Date: 2018/7/6
6
 * Time: 12:03 PM
7
 */
8
9
namespace Carno\NSQ\Chips;
10
11
use function Carno\Coroutine\all;
12
use Carno\NSQ\Connector\Linker;
13
use Carno\Promise\Promise;
14
use Carno\Promise\Promised;
15
16
trait N2Daemon
17
{
18
    /**
19
     * @var Promised
20
     */
21
    private $exited = null;
22
23
    /**
24
     * @see startup
25
     * @deprecated
26
     * @return Promised
27
     */
28
    public function daemon() : Promised
29
    {
30
        return $this->startup();
31
    }
32
33
    /**
34
     * @return Promised
35
     */
36
    private function exited() : Promised
37
    {
38
        return $this->exited ?? $this->exited = Promise::deferred();
39
    }
40
41
    /**
42
     * @return Promised
43
     */
44
    public function startup() : Promised
45
    {
46
        return all($this->background(), $this->exited());
0 ignored issues
show
Bug introduced by
It seems like background() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
        return all($this->/** @scrutinizer ignore-call */ background(), $this->exited());
Loading history...
47
    }
48
49
    /**
50
     * @return Promised
51
     */
52
    public function shutdown() : Promised
53
    {
54
        $waits = [];
55
56
        $this->linkers(function (Linker $linker) use (&$waits) {
0 ignored issues
show
Bug introduced by
It seems like linkers() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
        $this->/** @scrutinizer ignore-call */ 
57
               linkers(function (Linker $linker) use (&$waits) {
Loading history...
57
            array_push($waits, $linker->disconnect());
58
        });
59
60
        return all(...$waits)->sync($this->exited());
61
    }
62
}
63