rmrevin /
yii2-comments
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Module.php |
||
| 4 | * @author Revin Roman |
||
| 5 | * @link https://rmrevin.ru |
||
| 6 | */ |
||
| 7 | |||
| 8 | namespace rmrevin\yii\module\Comments; |
||
| 9 | |||
| 10 | use rmrevin\yii\module\Comments\forms\CommentCreateForm; |
||
| 11 | use rmrevin\yii\module\Comments\models\Comment; |
||
| 12 | use rmrevin\yii\module\Comments\models\queries\CommentQuery; |
||
| 13 | use yii\helpers\ArrayHelper; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Class Module |
||
| 17 | * @package rmrevin\yii\module\Comments |
||
| 18 | */ |
||
| 19 | class Module extends \yii\base\Module |
||
| 20 | { |
||
| 21 | |||
| 22 | /** @var string module name */ |
||
| 23 | public static $moduleName = 'comments'; |
||
| 24 | |||
| 25 | /** @var string|null */ |
||
| 26 | public $userIdentityClass = null; |
||
| 27 | |||
| 28 | /** @var bool */ |
||
| 29 | public $useRbac = true; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Array that will store the models used in the package |
||
| 33 | * e.g. : |
||
| 34 | * [ |
||
| 35 | * 'Comment' => 'frontend/models/comments/CommentModel' |
||
| 36 | * ] |
||
| 37 | * |
||
| 38 | * The classes defined here will be merged with getDefaultModels() |
||
| 39 | * having he manually defined by the user preference. |
||
| 40 | * |
||
| 41 | * @var array |
||
| 42 | */ |
||
| 43 | public $modelMap = []; |
||
| 44 | |||
| 45 | public function init() |
||
| 46 | { |
||
| 47 | parent::init(); |
||
| 48 | |||
| 49 | if ($this->userIdentityClass === null) { |
||
| 50 | $this->userIdentityClass = \Yii::$app->getUser()->identityClass; |
||
|
0 ignored issues
–
show
|
|||
| 51 | } |
||
| 52 | |||
| 53 | // Merge the default model classes |
||
| 54 | // with the user defined ones. |
||
| 55 | $this->defineModelClasses(); |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @return static |
||
| 60 | */ |
||
| 61 | public static function instance() |
||
| 62 | { |
||
| 63 | return \Yii::$app->getModule(static::$moduleName); |
||
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Merges the default and user defined model classes |
||
| 68 | * Also let's the developer to set new ones with the |
||
| 69 | * parameter being those the ones with most preference. |
||
| 70 | * |
||
| 71 | * @param array $modelClasses |
||
| 72 | */ |
||
| 73 | public function defineModelClasses($modelClasses = []) |
||
| 74 | { |
||
| 75 | $this->modelMap = ArrayHelper::merge( |
||
| 76 | $this->getDefaultModels(), |
||
| 77 | $this->modelMap, |
||
| 78 | $modelClasses |
||
| 79 | ); |
||
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Get default model classes |
||
| 84 | */ |
||
| 85 | protected function getDefaultModels() |
||
| 86 | { |
||
| 87 | return [ |
||
| 88 | 'Comment' => Comment::className(), |
||
| 89 | 'CommentQuery' => CommentQuery::className(), |
||
| 90 | 'CommentCreateForm' => CommentCreateForm::className() |
||
| 91 | ]; |
||
| 92 | } |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Get defined className of model |
||
| 96 | * |
||
| 97 | * Returns an string or array compatible |
||
| 98 | * with the Yii::createObject method. |
||
| 99 | * |
||
| 100 | * @param string $name |
||
| 101 | * @param array $config // You should never send an array with a key defined as "class" since this will |
||
| 102 | * // overwrite the main className defined by the system. |
||
| 103 | * @return string|array |
||
| 104 | */ |
||
| 105 | public function model($name, $config = []) |
||
| 106 | { |
||
| 107 | $modelData = $this->modelMap[ucfirst($name)]; |
||
| 108 | |||
| 109 | if (!empty($config)) { |
||
| 110 | if (is_string($modelData)) { |
||
| 111 | $modelData = ['class' => $modelData]; |
||
| 112 | } |
||
| 113 | |||
| 114 | $modelData = ArrayHelper::merge( |
||
| 115 | $modelData, |
||
| 116 | $config |
||
| 117 | ); |
||
| 118 | } |
||
| 119 | |||
| 120 | return $modelData; |
||
| 121 | } |
||
| 122 | |||
| 123 | } |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: