Completed
Push — master ( afc89b...10bad0 )
by Eugene
05:20
created

AtConnectionHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
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 AtConnectionHandler implements Handler
17
{
18
    private $atConnectionNumber;
19
    private $handler;
20
    private $connectionCount = 0;
21
22
    public function __construct(int $atConnectionNumber, Handler $handler)
23
    {
24
        $this->atConnectionNumber = $atConnectionNumber;
25
        $this->handler = $handler;
26
    }
27
28
    public function __invoke($conn, string $sid) : ?bool
29
    {
30
        ++$this->connectionCount;
31
32
        if ($this->connectionCount === $this->atConnectionNumber) {
33
            return ($this->handler)($conn, $sid);
34
        }
35
36
        return null;
37
    }
38
}
39