Completed
Push — master ( 0966f5...99aabd )
by Maxim
16:43
created

FromConverter::convert()   D

Complexity

Conditions 9
Paths 18

Size

Total Lines 31
Code Lines 21

Duplication

Lines 3
Ratio 9.68 %

Code Coverage

Tests 27
CRAP Score 9

Importance

Changes 9
Bugs 2 Features 5
Metric Value
c 9
b 2
f 5
dl 3
loc 31
ccs 27
cts 27
cp 1
rs 4.909
cc 9
eloc 21
nc 18
nop 1
crap 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 2
            }
15 102
            $result[] = $this->format('table', [$value]);
16 68
        }
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 View Code Duplication
                if (isset($item['alias']) && is_array($item['alias'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
22 6
                    $table .= ' AS '.$this->getValueWithoutQuotes($item['alias'], 'name');
23 4
                }
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 10
                    ];
31 15
                    $result[] = $this->format(strtolower($item['join_type']).'Join', $args);
32 10
                }
33 10
            }
34 68
        }
35
36 102
        return $result;
37
    }
38
}
39