ParametersReplacingVisitor   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
eloc 20
dl 0
loc 50
c 0
b 0
f 0
ccs 24
cts 24
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A visitMultiCompare() 0 4 1
A visitSingleCompare() 0 5 1
A replaceParameters() 0 18 3
1
<?php
2
3
namespace Xsolve\SalesforceClient\QueryBuilder\Visitor\Parameters;
4
5
use Xsolve\SalesforceClient\QueryBuilder\Expr\Compare\AbstractMultiCompare;
6
use Xsolve\SalesforceClient\QueryBuilder\Expr\Compare\AbstractSingleCompare;
7
use Xsolve\SalesforceClient\QueryBuilder\Visitor\VisitorInterface;
8
9
class ParametersReplacingVisitor implements VisitorInterface
10
{
11
    /**
12
     * @var array
13
     */
14
    private $parameters;
15
16
    /**
17
     * @var ReplacingStrategyCollection
18
     */
19
    private $replacingStrategies;
20
21 21
    public function __construct(array $parameters)
22
    {
23 21
        $this->parameters = $parameters;
24 21
        $this->replacingStrategies = new ReplacingStrategyCollection();
25 21
    }
26
27 16
    public function visitSingleCompare(AbstractSingleCompare $compare)
28
    {
29 16
        $compare->update([
30 16
            'left' => $this->replaceParameters($compare->getLeft()),
31 16
            'right' => $this->replaceParameters($compare->getRight()),
32
        ]);
33 16
    }
34
35 6
    public function visitMultiCompare(AbstractMultiCompare $multiCompare)
36
    {
37 6
        $replacedValues = array_map([$this, 'replaceParameters'], $multiCompare->getValues());
38 6
        $multiCompare->update($replacedValues);
39 6
    }
40
41 21
    protected function replaceParameters(string $subject): string
42
    {
43 21
        foreach ($this->parameters as $name => $value) {
44 21
            $type = null;
45
46 21
            if (is_array($value)) {
47 1
                $type = $value['type'];
48 1
                $value = $value['value'];
49
            }
50
51 21
            $subject = preg_replace(
52 21
                sprintf('/(\{%s\})/', preg_quote($name, '/')),
53 21
                $this->replacingStrategies[$type]->replace($value),
0 ignored issues
show
Bug introduced by
The method replace() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
                $this->replacingStrategies[$type]->/** @scrutinizer ignore-call */ 
54
                                                   replace($value),

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
54 21
                $subject
55
            );
56
        }
57
58 21
        return $subject;
59
    }
60
}
61