GtidCollection   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 35
ccs 15
cts 15
cp 1
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A makeCollectionFromString() 0 8 2
A getEncoded() 0 9 2
A getEncodedLength() 0 9 2
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
}