SetTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A set() 0 21 1
A buildSetQueryPart() 0 5 2
1
<?php declare(strict_types=1);
2
3
namespace Janisbiz\LightOrm\Dms\MySQL\QueryBuilder\Traits;
4
5
use Janisbiz\LightOrm\Dms\MySQL\Enum\ConditionEnum;
6
7
trait SetTrait
8
{
9
    /**
10
     * @var array
11
     */
12
    protected $set = [];
13
14
    /**
15
     * @param string $column
16
     * @param null|int|string $value
17
     *
18
     * @return $this
19
     */
20
    public function set(string $column, $value)
21
    {
22
        $columnNormalised = \sprintf(
23
            '%s_Update',
24
            \implode(
25
                '_',
26
                \array_map(
27
                    function ($columnPart) {
28
                        return \mb_convert_case($columnPart, MB_CASE_TITLE);
29
                    },
30
                    \explode('.', $column)
31
                )
32
            )
33
        );
34
35
        $this->set[$column] = \sprintf('%s = :%s', $column, $columnNormalised);
36
        $this->bind([
0 ignored issues
show
Bug introduced by
It seems like bind() 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

36
        $this->/** @scrutinizer ignore-call */ 
37
               bind([
Loading history...
37
            $columnNormalised => $value,
38
        ]);
39
40
        return $this;
41
    }
42
43
    /**
44
     * @return null|string
45
     */
46
    protected function buildSetQueryPart(): ?string
47
    {
48
        return empty($this->set)
49
            ? null
50
            : \sprintf('%s %s', ConditionEnum::SET, \implode(', ', \array_unique($this->set)))
51
        ;
52
    }
53
}
54