AtConnectionHandler::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 9
rs 10
c 1
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