Replacement   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 13
c 2
b 0
f 0
dl 0
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A replaceValues() 0 12 2
A getSyntaxReplace() 0 8 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * Author: Adrian Dumitru
5
 * Date: 4/30/2017 4:47 PM
6
 */
7
8
namespace Qpdb\QueryBuilder\Traits;
9
10
11
use Qpdb\QueryBuilder\DB\DbConnect;
0 ignored issues
show
Bug introduced by
The type Qpdb\QueryBuilder\DB\DbConnect was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Qpdb\QueryBuilder\Dependencies\QueryHelper;
13
use Qpdb\QueryBuilder\Dependencies\QueryStructure;
14
use Qpdb\QueryBuilder\Statements\QueryStatementInterface;
15
16
/**
17
 * Trait Replacement
18
 * @package Qpdb\QueryBuilder\Traits
19
 * @property QueryStructure $queryStructure
20
 */
21
trait Replacement
22
{
23
24
	/**
25
	 * @param $syntax
26
	 * @param int|bool $withReplacement
27
	 * @return mixed|string
28
	 */
29
	private function getSyntaxReplace( $syntax, $withReplacement = QueryStatementInterface::REPLACEMENT_NONE )
30
	{
31
		$syntax = QueryHelper::clearMultipleSpaces( $syntax );
32
33
		if ( !$withReplacement )
34
			return $syntax;
35
36
		return $this->replaceValues( $syntax );
37
	}
38
39
	/**
40
	 * @param string $syntax
41
	 * @return string
42
	 */
43
	private function replaceValues( $syntax )
44
	{
45
		$bindParams = $this->queryStructure->getElement( QueryStructure::BIND_PARAMS );
46
		$search = array();
47
		$replace = array();
48
		foreach ( $bindParams as $key => $value ) {
49
			$search[] = ':' . $key;
50
			$replace[] = DbConnect::getInstance()->quote( $value );
51
		}
52
		$syntax = str_ireplace( $search, $replace, $syntax );
53
54
		return $syntax;
55
56
	}
57
58
}