Passed
Pull Request — master (#63)
by Eugene
05:16
created

SleepHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 14 3
A __construct() 0 4 1
1
<?php
2
3
/**
4
 * This file is part of the Tarantool Client package.
5
 *
6
 * (c) Eugene Leonovich <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Tarantool\Client\Tests\Integration\FakeServer\Handler;
15
16
class SleepHandler implements Handler
17
{
18
    private $seconds;
19
    private $once;
20
    private $disabled = false;
21
22
    public function __construct(int $seconds, bool $once = false)
23
    {
24
        $this->seconds = $seconds;
25
        $this->once = $once;
26
    }
27
28
    public function __invoke($conn, string $sid) : ?bool
29
    {
30
        if ($this->disabled) {
31
            return null;
32
        }
33
34
        printf("$sid:   Sleep %d sec.\n", $this->seconds);
35
        sleep($this->seconds);
36
37
        if ($this->once) {
38
            $this->disabled = true;
39
        }
40
41
        return null;
42
    }
43
}
44