BindingsMapper::toCache()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 3
nc 3
nop 1
1
<?php
2
3
namespace Socialblue\LaravelQueryAdviser\DataListener\Services;
4
5
use Illuminate\Database\Query\Expression;
6
use Illuminate\Support\Facades\DB;
7
8
class BindingsMapper
9
{
10
    const EXPRESSION = "{EXPRESSION:} ";
11
12
    public function toCache(array $bindings): array
13
    {
14
        foreach ($bindings as &$binding) {
15
            if ($binding instanceof Expression) {
16
                $binding = self::EXPRESSION . $binding->getValue();
17
            }
18
        }
19
        return $bindings;
20
    }
21
22
    public function fromCache(array $bindings): array
23
    {
24
        foreach ($bindings as &$binding) {
25
            if (str_starts_with($binding, self::EXPRESSION)) {
26
                $binding = DB::raw(substr($binding, 14));
27
            }
28
        }
29
        return $bindings;
30
    }
31
}
32