Completed
Push — master ( a7b476...58257b )
by Adrian
01:51
created

QueryHelper::joinCondition()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
c 0
b 0
f 0
nc 2
nop 4
dl 0
loc 11
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace Sirius\Orm\Helpers;
5
6
class QueryHelper
7
{
8
    public static function reference($table, $tableAlias)
9
    {
10
        if (! $tableAlias || $table == $tableAlias) {
11
            return $table;
12
        }
13
14
        return "{$table} as {$tableAlias}";
15
    }
16
17
    public static function joinCondition($firsTable, $firstColumns, $secondTable, $secondColumns)
18
    {
19
        $firstColumns = (array) $firstColumns;
20
        $secondColumns = (array) $secondColumns;
21
22
        $parts = [];
23
        foreach ($firstColumns as $k => $col) {
24
            $parts[] = "{$firsTable}.{$col} = {$secondTable}.{$secondColumns[$k]}";
25
        }
26
27
        return implode(' AND ', $parts);
28
    }
29
}
30