Issues (6)

src/APIs/AbstractWatcher.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * Abstract watcher
4
 * User: moyo
5
 * Date: 13/10/2017
6
 * Time: 6:21 PM
7
 */
8
9
namespace Carno\Consul\APIs;
10
11
use Carno\Consul\Chips\SVersions;
12
use Carno\HTTP\Standard\Response;
13
use Carno\Promise\Promise;
14
use Carno\Promise\Promised;
15
16
abstract class AbstractWatcher extends AbstractGate
17
{
18
    // service version index
19
    protected const INDEX_HEADER_KEY = 'X-Consul-Index';
20
21
    /**
22
     * 10m
23
     * @var int
24
     */
25
    protected $timeout = 600000;
26
27
    /**
28
     * wait time for http long polling
29
     * @var string
30
     */
31
    protected $blockingWait = '5m';
32
33
    /**
34
     * rand wait time for empty results (milliseconds) [min,max]
35
     * @var int[]
36
     */
37
    protected $emptyWait = [1000, 2000];
38
39
    /**
40
     * @var Promised
41
     */
42
    private $canceller = null;
43
44
    /**
45
     * @param int $index
46
     */
47
    protected function setVIndex(int $index) : void
48
    {
49
        $this->setQuery('wait', $this->blockingWait);
50
        $index && $this->setQuery('index', $index);
51
    }
52
53
    /**
54
     * @param SVersions $versions
55
     * @param Response $response
56
     */
57
    protected function assignVIndex($versions, Response $response) : void
58
    {
59
        $versions->setVersion($response->getHeaderLine(self::INDEX_HEADER_KEY));
0 ignored issues
show
$response->getHeaderLine(self::INDEX_HEADER_KEY) of type string is incompatible with the type integer expected by parameter $index of Carno\Consul\Chips\SVersions::setVersion(). ( Ignorable by Annotation )

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

59
        $versions->setVersion(/** @scrutinizer ignore-type */ $response->getHeaderLine(self::INDEX_HEADER_KEY));
Loading history...
60
    }
61
62
    /**
63
     * @param Promised $superior
64
     * @return static
65
     */
66
    public function setCanceller(Promised $superior) : self
67
    {
68
        $superior->then(function () {
69
            $this->canceller && $this->canceller->pended() && $this->canceller->resolve();
70
        });
71
        return $this;
72
    }
73
74
    /**
75
     * @return Promised
76
     */
77
    protected function getCanceller() : Promised
78
    {
79
        return $this->canceller = Promise::deferred();
80
    }
81
}
82