WhereTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A setWhere() 0 14 2
1
<?php
2
/**
3
 * Spiral, Core Components
4
 *
5
 * @author Wolfy-J
6
 */
7
8
namespace Spiral\ORM\Entities\Loaders\Traits;
9
10
use Spiral\Database\Builders\SelectQuery;
11
use Spiral\ORM\Helpers\AliasDecorator;
12
13
/**
14
 * Provides ability to clarify Query where conditions in JOIN or WHERE statement, based on provided
15
 * values.
16
 */
17
trait WhereTrait
18
{
19
    /**
20
     * @param SelectQuery $query
21
     * @param string      $table Table name to be automatically inserted into where conditions at
22
     *                            place of {@}.
23
     * @param string      $target Query target section (accepts: where, having, onWhere, on)
24
     * @param array       $where Where conditions in a form or short array form.
25
     */
26
    private function setWhere(
27
        SelectQuery $query,
28
        string $table,
29
        string $target,
30
        array $where = null
31
    ) {
32
        if (empty($where)) {
33
            //No conditions, nothing to do
34
            return;
35
        }
36
37
        $decorator = new AliasDecorator($query, $target, $table);
38
        $decorator->where($where);
39
    }
40
}