Converter   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 0
dl 0
loc 57
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getValueWithoutQuotes() 0 14 3
A getValueWithoutInvertedCommas() 0 8 3
A format() 0 9 2
1
<?php
2
3
namespace BigShark\SQLToBuilder\Converter;
4
5
abstract class Converter
6
{
7
    /**
8
     * Get item value without quotes.
9
     *
10
     * @param array  $item Item
11
     * @param string $key  Value key
12
     *
13
     * @return mixed
14
     */
15 171
    protected function getValueWithoutQuotes($item, $key = 'base_expr')
16
    {
17 171
        $value = $item[$key];
18
19 171
        if (isset($item['no_quotes']['parts'][0])) {
20 120
            if (isset($item['no_quotes']['delim'])) {
21 105
                $value = implode($item['no_quotes']['delim'], $item['no_quotes']['parts']);
22
            } else {
23 15
                $value = $item['no_quotes']['parts'][0];
24
            }
25
        }
26
27 171
        return $value;
28
    }
29
30
    /**
31
     * Get item value without quotes.
32
     *
33
     * @param string $value Value
34
     *
35
     * @return mixed
36
     */
37 78
    protected function getValueWithoutInvertedCommas($value)
38
    {
39 78
        if (substr($value, 0, 1) === '\'' && substr($value, -1, 1) === '\'') {
40 21
            $value = substr($value, 1, -1);
41
        }
42
43 78
        return $value;
44
    }
45
46
    /**
47
     * @param $name
48
     * @param $args
49
     *
50
     * @return array
51
     */
52 174
    protected function format($name, array $args = null)
53
    {
54 174
        $result = ['name' => $name];
55 174
        if ($args !== null) {
56 174
            $result['args'] = $args;
57
        }
58
59 174
        return $result;
60
    }
61
}
62