SelectConverter   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 39
Duplicated Lines 15.38 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 13
lcom 0
cbo 2
dl 6
loc 39
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C convert() 6 36 13

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
use BigShark\SQLToBuilder\Generator;
6
7
class SelectConverter extends Converter implements ConverterInterface
8
{
9 114
    public function convert($select)
10
    {
11 114
        if (count($select) == 1) {
12 105
            $value = $this->getValueWithoutQuotes($select[0]);
13 105
            if ('*' === $value) {
14 81
                return [];
15
            }
16 24
            unset($value);
17
        }
18
19 33
        $s = [];
20 33
        foreach ($select as $item) {
21 33
            if ('colref' === $item['expr_type']) {
22 24
                $value = $this->getValueWithoutQuotes($item);
23 24 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...
24 9
                    $value .= ' AS '.$this->getValueWithoutQuotes($item['alias'], 'name');
25
                }
26 24
                $s[] = $value;
27 9
            } elseif ('aggregate_function' === $item['expr_type'] || 'function' === $item['expr_type']) {
28 6
                $function = strtoupper($item['base_expr']);
29 6
                $value = $function.'('.implode(', ', array_column($item['sub_tree'], 'base_expr')).')';
30 6 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...
31 3
                    $value .= ' AS '.$item['alias']['name'];
32
                }
33
34 6
                $generator = new Generator('DB');
35 6
                $generator->addFunction('raw', [$value]);
36
37 15
                $s[] = $generator;
38
            }
39
        }
40 33
        if (is_array($s) && count($s)) {
41 30
            return [$this->format('select', $s)];
42
        }
43 3
        throw new \Exception('Not valid select');
44
    }
45
}
46