SelectConverter::convert()   C
last analyzed

Complexity

Conditions 13
Paths 25

Size

Total Lines 36

Duplication

Lines 6
Ratio 16.67 %

Code Coverage

Tests 24
CRAP Score 13

Importance

Changes 0
Metric Value
dl 6
loc 36
ccs 24
cts 24
cp 1
rs 6.6166
c 0
b 0
f 0
cc 13
nc 25
nop 1
crap 13

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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