Completed
Push — master ( 5b8bc2...b011b0 )
by Tõnis
02:00
created

DActiveRecord::hasOne()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace dameter\abstracts;
4
5
6
use yii\db\ActiveRecord;
7
8
class DActiveRecord extends ActiveRecord
9
{
10
    /** in case we would need to customize stuff */
11
12
    /**
13
     * @return string
14
     */
15
    public static function primaryKey()
16
    {
17
        return static::tableName() . "_id";
0 ignored issues
show
Bug Best Practice introduced by
The expression return static::tableName() . '_id' returns the type string which is incompatible with the return type mandated by yii\db\ActiveRecordInterface::primaryKey() of string[].

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
18
    }
19
20
21
    /** {@inheritdoc} */
22
    public function hasMany($class, $link = null)
23
    {
24
        if (empty($link)) {
25
            /** @var DActiveRecord $class */
26
            $link = [$class::primaryKey() => $class::primaryKey()];
27
        }
28
        return parent::hasMany($class, $link);
29
    }
30
31
    /** {@inheritdoc} */
32
    public function hasOne($class, $link = null)
33
    {
34
        if (empty($link)) {
35
            /** @var DActiveRecord $class */
36
            $link = [$class::primaryKey() => $class::primaryKey()];
37
        }
38
        return parent::hasOne($class, $link);
39
    }
40
}