Skip to content

Commit

Permalink
Added return types, removed unused Yii from model.php, replaced imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Erkinbek committed Feb 10, 2024
1 parent c7f7533 commit 758c76f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
21 changes: 11 additions & 10 deletions src/generators/crud/default/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use <?= ltrim($generator->baseControllerClass, '\\') ?>;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\web\Response;

/**
* <?= $controllerClass ?> implements the CRUD actions for <?= $modelClass ?> model.
Expand All @@ -47,7 +48,7 @@ class <?= $controllerClass ?> extends <?= StringHelper::basename($generator->bas
/**
* @inheritDoc
*/
public function behaviors()
public function behaviors() : array
{
return array_merge(
parent::behaviors(),
Expand All @@ -67,7 +68,7 @@ public function behaviors()
*
* @return string
*/
public function actionIndex()
public function actionIndex() : string
{
<?php if (!empty($generator->searchModelClass)): ?>
$searchModel = new <?= isset($searchModelAlias) ? $searchModelAlias : $searchModelClass ?>();
Expand Down Expand Up @@ -106,7 +107,7 @@ public function actionIndex()
* @return string
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView(<?= $actionParams ?>)
public function actionView(<?= $actionParams ?>) : string
{
return $this->render('view', [
'model' => $this->findModel(<?= $actionParams ?>),
Expand All @@ -116,9 +117,9 @@ public function actionView(<?= $actionParams ?>)
/**
* Creates a new <?= $modelClass ?> model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return string|\yii\web\Response
* @return string|Response
*/
public function actionCreate()
public function actionCreate() : string|Response
{
$model = new <?= $modelClass ?>();

Expand All @@ -139,10 +140,10 @@ public function actionCreate()
* Updates an existing <?= $modelClass ?> model.
* If update is successful, the browser will be redirected to the 'view' page.
* <?= implode("\n * ", $actionParamComments) . "\n" ?>
* @return string|\yii\web\Response
* @return string|Response
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate(<?= $actionParams ?>)
public function actionUpdate(<?= $actionParams ?>) : string|Response
{
$model = $this->findModel(<?= $actionParams ?>);

Expand All @@ -159,10 +160,10 @@ public function actionUpdate(<?= $actionParams ?>)
* Deletes an existing <?= $modelClass ?> model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* <?= implode("\n * ", $actionParamComments) . "\n" ?>
* @return \yii\web\Response
* @return Response
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete(<?= $actionParams ?>)
public function actionDelete(<?= $actionParams ?>) : Response
{
$this->findModel(<?= $actionParams ?>)->delete();

Expand All @@ -176,7 +177,7 @@ public function actionDelete(<?= $actionParams ?>)
* @return <?= $modelClass ?> the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel(<?= $actionParams ?>)
protected function findModel(<?= $actionParams ?>) : <?= $modelClass ?>
{
<?php
$condition = [];
Expand Down
23 changes: 11 additions & 12 deletions src/generators/model/default/model.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@

namespace <?= $generator->ns ?>;

use Yii;

use \yii\db\Connection;
/**
* This is the model class for table "<?= $generator->generateTableName($tableName) ?>".
*
Expand Down Expand Up @@ -54,16 +53,16 @@ class <?= $className ?> extends <?= '\\' . ltrim($generator->baseClass, '\\') .
/**
* {@inheritdoc}
*/
public static function tableName()
public static function tableName() : string
{
return '<?= $generator->generateTableName($tableName) ?>';
}
<?php if ($generator->db !== 'db'): ?>

/**
* @return \yii\db\Connection the database connection used by this AR class.
* @return Connection the database connection used by this AR class.
*/
public static function getDb()
public static function getDb() : Connection
{
return Yii::$app->get('<?= $generator->db ?>');
}
Expand All @@ -72,15 +71,15 @@ public static function getDb()
/**
* {@inheritdoc}
*/
public function rules()
public function rules() : array
{
return [<?= empty($rules) ? '' : ("\n " . implode(",\n ", $rules) . ",\n ") ?>];
}

/**
* {@inheritdoc}
*/
public function attributeLabels()
public function attributeLabels() : array
{
return [
<?php foreach ($labels as $name => $label): ?>
Expand All @@ -95,7 +94,7 @@ public function attributeLabels()
*
* @return <?= $relationsClassHints[$name] . "\n" ?>
*/
public function get<?= $name ?>()
public function get<?= $name ?>() : <?= $relationsClassHints[$name] ?>
{
<?= $relation[0] . "\n" ?>
}
Expand All @@ -109,7 +108,7 @@ public function get<?= $name ?>()
* {@inheritdoc}
* @return <?= $queryClassFullName ?> the active query used by this AR class.
*/
public static function find()
public static function find() : <?= $queryClassFullName ?>
{
return new <?= $queryClassFullName ?>(get_called_class());
}
Expand All @@ -122,7 +121,7 @@ public static function find()
* column <?= $columnName ?> ENUM value labels
* @return string[]
*/
public static function <?= $columnData['funcOptsName'] ?>()
public static function <?= $columnData['funcOptsName'] ?>() : array
{
return [
<?php foreach ($columnData['values'] as $k => $value): ?>
Expand All @@ -142,7 +141,7 @@ public static function <?= $columnData['funcOptsName'] ?>()
/**
* @return string
*/
public function <?= $columnData['displayFunctionPrefix'] ?>()
public function <?= $columnData['displayFunctionPrefix'] ?>() : string
{
return self::<?= $columnData['funcOptsName'] ?>()[$this-><?=$columnName?>];
}
Expand All @@ -151,7 +150,7 @@ public function <?= $columnData['displayFunctionPrefix'] ?>()
/**
* @return bool
*/
public function <?= $columnData['isFunctionPrefix'] . $enumValue['functionSuffix'] ?>()
public function <?= $columnData['isFunctionPrefix'] . $enumValue['functionSuffix'] ?>() : bool
{
return $this-><?= $columnName ?> === self::<?= $enumValue['constName'] ?>;
}
Expand Down
2 changes: 1 addition & 1 deletion src/generators/module/default/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DefaultController extends Controller
* Renders the index view for the module
* @return string
*/
public function actionIndex()
public function actionIndex() : string
{
return $this->render('index');
}
Expand Down

0 comments on commit 758c76f

Please sign in to comment.