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

QueryHelper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 10
c 2
b 1
f 0
dl 0
loc 22
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A reference() 0 7 3
A joinCondition() 0 11 2
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