Test Failed
Push — master ( 29d761...e93c95 )
by Alexpts
01:54
created

Writer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 29
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A write() 0 18 3
1
<?php
2
3
namespace PTS\Transport;
4
5
class Writer
6
{
7
8
    /**
9
     * @param resource $target
10
     * @param string $buffer
11
     * @param int|null $length - записать число байт в сокет
12
     *
13
     * @return false|int число записанных байт или false
14
     */
15
    public function write($target, string $buffer, int $length = null): int
16
    {
17
        $length = $length ?? mb_strlen($buffer, '8bit');
18
19
        $written = 0;
20
        while ($written < $length) {
21
            $chunk = mb_substr($buffer, $written, $length, '8bit');
22
            $byteCount = fwrite($target, $chunk, $length);
23
24
            if (!$byteCount) {
25
                break;
26
            }
27
28
            $written += $byteCount;
29
        }
30
31
        return $written;
32
    }
33
}
34