Issues (6)

src/WithLanguageSettingsModel.php (1 issue)

1
<?php
2
3
namespace dameter\abstracts;
4
5
use dameter\abstracts\interfaces\Translatable;
6
use dameter\abstracts\models\BaseLanguageSetting;
7
use dameter\abstracts\models\Language;
8
9
/**
10
 * Class WithLanguageSettingsModel
11
 * @property BaseLanguageSetting[] $languageSettings
12
 *
13
 * @package dameter\abstracts
14
 * @author Tõnis Ormisson <[email protected]>
15
 */
16
class WithLanguageSettingsModel extends WithSurveyModel implements Translatable
17
{
18
19
    /** @var string */
20
    public static $settingsClass;
21
22
    /** @var Language */
23
    public $language;
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function init()
29
    {
30
        parent::init();
31
        if (empty($this->language)) {
32
            $this->language = $this->survey->language;
33
        }
34
    }
35
36
    /**
37
     * @return \yii\db\ActiveQuery
38
     */
39
    public function getLanguageSettings() {
40
        return $this->hasMany(self::$settingsClass);
41
    }
42
43
    /**
44
     * @return \yii\db\ActiveQuery
45
     * @throws \yii\base\NotSupportedException
46
     */
47
    public function getTexts()
48
    {
49
        $query = $this->hasMany(static::$settingsClass, ['parent_id' => static::primaryKeySingle()]);
50
        return $query->andWhere(['language_id' => $this->language->primaryKey])->indexBy(Language::primaryKeySingle());
0 ignored issues
show
Bug Best Practice introduced by
The expression return $query->andWhere(...ge::primaryKeySingle()) returns the type yii\db\ActiveQuery which is incompatible with the return type mandated by dameter\abstracts\interf...ranslatable::getTexts() of dameter\abstracts\models\BaseLanguageSetting[].

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...
51
    }
52
53
}