Test Setup Failed
Push — master ( 246aa3...2d0e6f )
by Alexpts
01:50
created

BaseTransport::isConnected()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace PTS\Transport;
5
6
abstract class BaseTransport implements TransportInterface
7
{
8
    /** @var resource|null|false */
9
    protected $target;
10
    protected string $schema = '';
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
11
    protected WriterInterface $writer;
12
13
    public function __construct(WriterInterface $writer = null)
14
    {
15 16
        $this->writer = $writer ?? new Writer;
16
    }
17 16
18 16
    public function getWriter(): WriterInterface
19
    {
20 4
        return $this->writer;
21
    }
22 4
23
    public function write(string $buffer, int $length = null): int
24
    {
25
        return $this->writer->write($this->target, $buffer, $length);
26
    }
27
28
    public function isConnected(): bool
29
    {
30
        return is_resource($this->target) && !feof($this->target);
31 16
    }
32
33 16
    public function close(): void
34
    {
35
        $this->target && fclose($this->target);
36 12
        $this->target = null;
37
    }
38
}
39