Converter::format()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 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