Completed
Push — master ( bbcbbc...8c42c0 )
by Timo
07:53
created

ColumnRelation   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A _extractAggregate() 0 14 2
1
<?php
2
3
namespace hamburgscleanest\DataTables\Models\Column;
4
5
/**
6
 * Class Relation
7
 * @package hamburgscleanest\hamburgscleanest\DataTables\Models\Column
8
 */
9
class ColumnRelation {
10
11
    /** @var string */
12
    public $name;
13
14
    /** @var string */
15
    public $aggregate = 'first';
16
17
    /** @var string */
18
    public $attributeName;
19
20
    /**
21
     * Relation constructor.
22
     * @param string $columnName
23
     * @internal param string $name
24
     */
25 6
    public function __construct(string $columnName)
26
    {
27 6
        $this->attributeName = $columnName;
28 6
        $this->name = $this->_extractAggregate($columnName);
29 6
    }
30
31
    /**
32
     * @param string $name
33
     * @return string
34
     */
35 6
    private function _extractAggregate(string $name) : string
36
    {
37 6
        $replaced = 0;
38 6
        $extractedName = \preg_replace('/\((.*?)\)/', '#$1', $name, 1, $replaced);
39 6
        if ($replaced === 0)
40
        {
41 3
            return \str_replace('.', '_', \mb_strtolower($extractedName));
42
        }
43
44 3
        $parts = \explode('#', $extractedName);
45 3
        $this->aggregate = \mb_strtolower($parts[0]);
46
47 3
        return \str_replace('.', '_', \mb_strtolower($parts[1]));
48
    }
49
}