Completed
Branch develop (c2aa4c)
by Anton
05:17
created

AliasTrait::mountAlias()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 18
rs 9.2
cc 4
eloc 9
nc 5
nop 2
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
namespace Spiral\ORM\Entities\Traits;
10
11
/**
12
 * Replaces {@} with valid table alias in array where.
13
 */
14
trait AliasTrait
15
{
16
    /**
17
     * Replace {@} in where statement with valid alias.
18
     *
19
     * @param string $alias
20
     * @param array  $where
21
     * @return array
22
     */
23
    protected function mountAlias($alias, array $where)
24
    {
25
        $result = [];
26
27
        foreach ($where as $key => $value) {
28
            if (strpos($key, '{@}') !== false) {
29
                $key = str_replace('{@}', $alias, $key);
30
            }
31
32
            if (is_array($value)) {
33
                $value = $this->mountAlias($alias, $where);
34
            }
35
36
            $result[$key] = $value;
37
        }
38
39
        return $result;
40
    }
41
}