Passed
Pull Request — master (#9)
by Alexander
02:30
created

ShoRecordTrait   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 0
dl 0
loc 16
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A fieldName() 0 8 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
}