GtidCollection::getEncodedLength()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 2
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace MySQLReplication\Gtid;
5
6
use Doctrine\Common\Collections\ArrayCollection;
7
use MySQLReplication\BinaryDataReader\BinaryDataReader;
8
9
class GtidCollection extends ArrayCollection
10
{
11
    /**
12
     * @throws GtidException
13
     */
14 1
    public static function makeCollectionFromString(string $gtids): GtidCollection
15
    {
16 1
        $collection = new self();
17 1
        foreach (array_filter(explode(',', $gtids)) as $gtid) {
18 1
            $collection->add(new Gtid($gtid));
19
        }
20
21 1
        return $collection;
22
    }
23
24 1
    public function getEncodedLength(): int
25
    {
26 1
        $l = 8;
27
        /** @var Gtid $gtid */
28 1
        foreach ($this->toArray() as $gtid) {
29 1
            $l += $gtid->getEncodedLength();
30
        }
31
32 1
        return $l;
33
    }
34
35 1
    public function getEncoded(): string
36
    {
37 1
        $s = BinaryDataReader::pack64bit($this->count());
38
        /** @var Gtid $gtid */
39 1
        foreach ($this->toArray() as $gtid) {
40 1
            $s .= $gtid->getEncoded();
41
        }
42
43 1
        return $s;
44
    }
45
}