Completed
Branch develop (f7dc53)
by Anton
05:49
created

AliasTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 28
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A mountAlias() 0 18 4
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
}