FromConverter   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 1
dl 0
loc 34
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B convert() 0 31 9
1
<?php
2
3
namespace BigShark\SQLToBuilder\Converter;
4
5
class FromConverter extends Converter implements ConverterInterface
6
{
7 102
    public function convert($from)
8
    {
9 102
        $result = [];
10 102
        if ('table' === $from[0]['expr_type']) {
11 102
            $value = $this->getValueWithoutQuotes($from[0], 'table');
12 102
            if (isset($from[0]['alias']) && is_array($from[0]['alias'])) {
13 3
                $value .= ' AS '.$this->getValueWithoutQuotes($from[0]['alias'], 'name');
14
            }
15 102
            $result[] = $this->format('table', [$value]);
16
        }
17 102
        unset($from[0]);
18 102
        foreach ($from as $item) {
19 15
            if (in_array($item['join_type'], ['LEFT', 'RIGHT'], true)) {
20 15
                $table = $this->getValueWithoutQuotes($item, 'table');
21 15
                if (isset($item['alias']) && is_array($item['alias'])) {
22 6
                    $table .= ' AS '.$this->getValueWithoutQuotes($item['alias'], 'name');
23
                }
24 15
                if ('ON' === strtoupper($item['ref_type'])) {
25
                    $args = [
26 15
                        $table,
27 15
                        $this->getValueWithoutQuotes($item['ref_clause'][0], 'base_expr'),
28 15
                        $item['ref_clause'][1]['base_expr'],
29 15
                        $this->getValueWithoutQuotes($item['ref_clause'][2], 'base_expr'),
30
                    ];
31 15
                    $result[] = $this->format(strtolower($item['join_type']).'Join', $args);
32
                }
33
            }
34
        }
35
36 102
        return $result;
37
    }
38
}
39