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

FromConverter   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 34
Duplicated Lines 8.82 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 9
Bugs 2 Features 5
Metric Value
wmc 9
c 9
b 2
f 5
lcom 0
cbo 1
dl 3
loc 34
ccs 27
cts 27
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
D convert() 3 31 9

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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