QueryBuilderDumpServiceProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 26
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B register() 0 23 4
1
<?php
2
3
namespace Morrislaptop\QueryBuilderDump;
4
5
use Illuminate\Database\Query\Builder;
6
use Illuminate\Support\ServiceProvider;
7
8
class QueryBuilderDumpServiceProvider extends ServiceProvider
9
{
10
    public function register()
11
    {
12
        $raw = function ($sql, $bindings) {
13
            $flat = array_flatten($bindings);
14
            foreach ($flat as $binding) {
15
                $binded = $binding instanceof \DateTime ? $binding->format('Y-m-d H:i:s') : $binding;
16
                $binded = is_numeric($binded) ? $binded : "'{$binded}'";
17
                $sql = preg_replace('/\?/', $binded, $sql, 1);
18
            }
19
20
            return $sql;
21
        };
22
23
        Builder::macro('dump', function ($dumper = 'dump') use ($raw) {
24
            $dumper([
25
                'bindings' => $this->bindings,
0 ignored issues
show
Bug introduced by
The property bindings 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...
26
                'sql' => $this->toSql(),
0 ignored issues
show
Bug introduced by
The method toSql() does not seem to exist on object<Morrislaptop\Quer...derDumpServiceProvider>.

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...
27
                'raw' => $raw($this->toSql(), $this->bindings),
0 ignored issues
show
Bug introduced by
The method toSql() does not seem to exist on object<Morrislaptop\Quer...derDumpServiceProvider>.

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...
28
            ]);
29
30
            return $this;
31
        });
32
    }
33
}
34