Completed
Branch feature/pre-split (b482c4)
by Anton
03:51
created

WhereTrait::setWhere()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 4
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * components
4
 *
5
 * @author    Wolfy-J
6
 */
7
namespace Spiral\ORM\Entities\Loaders\Traits;
8
9
use Spiral\Database\Builders\SelectQuery;
10
use Spiral\ORM\Helpers\WhereDecorator;
11
12
/**
13
 * Provides ability to clarify Query where conditions in JOIN or WHERE statement, based on provided
14
 * values.
15
 */
16
trait WhereTrait
17
{
18
    /**
19
     * @param SelectQuery $query
20
     * @param string      $table  Table name to be automatically inserted into where conditions at
21
     *                            place of {@}.
22
     * @param string      $target Query target section (accepts: where, having, onWhere, on)
23
     * @param array       $where  Where conditions in a form or short array form.
24
     */
25
    public function setWhere(SelectQuery $query, string $table, string $target, array $where = null)
26
    {
27
        if (empty($where)) {
28
            //No conditions, nothing to do
29
            return;
30
        }
31
32
        $decorator = new WhereDecorator($query, $target, $table);
33
        $decorator->where($where);
34
    }
35
}