Completed
Push — master ( d1c2f9...9b6402 )
by Nielsen
04:49 queued 50s
created

SQLConverter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
c 0
b 0
f 0
ccs 7
cts 7
cp 1
rs 9.6666
cc 1
eloc 6
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Softbox\Persistence\Core\SQL\Builder;
4
5
use Softbox\Persistence\Core\Buildable;
6
use Softbox\Persistence\Core\Condition;
7
use Softbox\Persistence\Core\Converter;
8
use Softbox\Persistence\Core\Filter;
9
use Softbox\Persistence\Core\InsertBase;
10
use Softbox\Persistence\Core\SQL\Command\SQLSelect;
11
12
/**
13
 * Class used to identify and delegate the building of SQL correct.
14
 */
15
class SQLConverter implements Converter
16
{
17
    /**
18
     * Builders of the SQL command.
19
     *
20
     * @var Converter[]
21
     */
22
    private $converters = [];
23
24
    /**
25
     * SQLConverter constructor.
26
     */
27 7
    public function __construct()
28
    {
29 7
        $this->converters = [
0 ignored issues
show
Documentation Bug introduced by
It seems like array(\Softbox\Persisten...InsertConverter($this)) of type array<string|integer,obj...er\SQLInsertConverter>> is incompatible with the declared type array<integer,object<Sof...stence\Core\Converter>> of property $converters.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
30 7
            Filter::class     => new SQLWhereConverter($this),
31 7
            Condition::class  => new SQLConditionConverter($this),
32 7
            SQLSelect::class  => new SQLSelectConverter($this),
33 7
            InsertBase::class => new SQLInsertConverter($this),
34
        ];
35 7
    }
36
37
    /**
38
     * Build the SQL command for the given value.
39
     *
40
     * @param mixed $value the value that will be converted
41
     *
42
     * @return string correspondent SQL to the given value
43
     */
44 5
    public function convert($value)
45
    {
46 5
        if ($value === null) {
47
            return "NULL";
48
        }
49
50 5
        if ($value instanceof Buildable) {
51 5
            $className = get_class($value);
52 5
            if (isset($this->converters[$className])) {
53 5
                return $this->converters[$className]->convert($value);
54
            }
55
        }
56
57 3
        return strval($value);
58
    }
59
}
60