Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
1 / 1
Group
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
6 / 6
9
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 create
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __toString
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 empty
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 parse
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
 parseGruopOnSet
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace Projom\Storage\SQL\Component;
6
7use Projom\Storage\SQL\Component\ComponentInterface;
8use Projom\Storage\SQL\Util;
9
10class Group implements ComponentInterface
11{
12    private readonly string $groups;
13
14    public function __construct(array $fields)
15    {
16        $this->parse($fields);
17    }
18
19    public static function create(array $fields): Group
20    {
21        return new Group($fields);
22    }
23
24    public function __toString(): string
25    {
26        return $this->groups;
27    }
28
29    public function empty()
30    {
31        return empty($this->groups);
32    }
33
34    private function parse(array $groupOn): void
35    {
36        $parts = [];
37        foreach ($groupOn as $gruopOnSets)
38            foreach ($gruopOnSets as $groupOnSet)
39                $parts = Util::merge($parts, $this->parseGruopOnSet($groupOnSet));
40
41        $this->groups = Util::join($parts, ', ');
42    }
43
44    private function parseGruopOnSet(string $gruopOnSet): array
45    {
46        $parts = [];
47
48        $fields = Util::split($gruopOnSet, ',');
49        foreach ($fields as $field)
50            $parts[] = Util::splitAndQuoteThenJoin($field, '.');
51
52        return $parts;
53    }
54}