Passed
Push — master ( eba8a3...48441f )
by Alexander
40s
created

ShoRecordTrait::fieldName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Horat1us\Yii\Traits;
4
5
use yii\db\ActiveRecord;
6
7
/**
8
 * Trait for extension Active Records
9
 * @package common\models
10
 *
11
 * @mixin ActiveRecord
12
 */
13
trait ShoRecordTrait
14
{
15
    /**
16
     * @param string $field
17
     * @param string|null $tableAlias
18
     * @return string
19
     */
20 2
    public static function fieldName(string $field, string $tableAlias = null) :string
21
    {
22 2
        $tableAlias = $tableAlias ?? static::tableName();
23
24 2
        $tableAlias = preg_replace('/[^\w]/', '', $tableAlias);
25
26 2
        return "\"$tableAlias\".\"$field\"";
27
    }
28
}