Issues (59)

src/Builders/Data.php (2 issues)

1
<?php
2
/**
3
 * Data stash
4
 * User: moyo
5
 * Date: 25/12/2017
6
 * Time: 2:54 PM
7
 */
8
9
namespace Carno\Database\SQL\Builders;
10
11
use Carno\Database\SQL\Builder;
12
13
trait Data
14
{
15
    /**
16
     * @var array
17
     */
18
    private $bDataE = [];
19
20
    /**
21
     * @var array
22
     */
23
    private $bDataM = [];
24
25
    /**
26
     * @return string
27
     */
28
    protected function gData() : string
29
    {
30
        $dMaps = [];
31
        array_walk($this->bDataM, function ($v, $k) use (&$dMaps) {
32
            $dMaps[] = sprintf('`%s` = ?%d', $k, $this->stash($v));
0 ignored issues
show
It seems like stash() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

32
            $dMaps[] = sprintf('`%s` = ?%d', $k, $this->/** @scrutinizer ignore-call */ stash($v));
Loading history...
33
        });
34
35
        return sprintf('SET %s', implode(',', array_merge($this->bDataE, $dMaps)));
36
    }
37
38
    /**
39
     * @param array ...$maps
40
     * @return Builder
41
     */
42
    public function data(...$maps) : Builder
43
    {
44
        foreach ($maps as $map) {
45
            if (is_string($map)) {
46
                // data(expr2)
47
                $this->bDataE[] = $map;
48
            } else {
49
                // data([key => val])
50
                foreach ($map as $mk => $mv) {
51
                    $this->bDataM[$mk] =
52
                        is_scalar($mv)
53
                            ? $mv
54
                            : json_encode($mv, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)
55
                    ;
56
                }
57
            }
58
        }
59
60
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type Carno\Database\SQL\Builders\Data which includes types incompatible with the type-hinted return Carno\Database\SQL\Builder.
Loading history...
61
    }
62
}
63