Completed
Push — master ( b0b60e...78477d )
by Beniamin
02:33
created

ReferenceParser   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 1
dl 0
loc 28
ccs 12
cts 12
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A parseSQL() 0 12 3
1
<?php
2
3
/**
4
 * This file is part of Phuria SQL Builder package.
5
 *
6
 * Copyright (c) 2016 Beniamin Jonatan Šimko
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Phuria\QueryBuilder\Parser;
13
14
use Phuria\QueryBuilder\ReferenceManager;
15
use Phuria\QueryBuilder\Table\AbstractTable;
16
17
/**
18
 * @author Beniamin Jonatan Šimko <[email protected]>
19
 */
20
class ReferenceParser
21
{
22
    /**
23
     * @param                  $rawSQL
24
     * @param ReferenceManager $manager
25
     */
26 20
    public function __construct($rawSQL, ReferenceManager $manager)
27
    {
28 20
        $this->rawSQL = $rawSQL;
0 ignored issues
show
Bug introduced by
The property rawSQL does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
29 20
        $this->manager = $manager;
0 ignored issues
show
Bug introduced by
The property manager does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
30 20
    }
31
32
    /**
33
     * @return string
34
     */
35 20
    public function parseSQL()
36
    {
37 20
        $references = $this->manager->all();
38
39 20
        foreach ($references as &$value) {
40 12
            if ($value instanceof AbstractTable) {
41 12
                $value = $value->getAliasOrName();
42 12
            }
43 20
        }
44
45 20
        return str_replace(array_keys($references), array_values($references), $this->rawSQL);
46
    }
47
}