Skip to content

Commit f96257d

Browse files
committed
ModelClassDescription
1 parent 444bfae commit f96257d

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/generator/default/dbmodel.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111
<?= '<?php' ?>
1212

1313

14+
/**
15+
* This file is generated by Gii, do not change manually!
16+
*/
17+
1418
namespace <?= $namespace ?>;
1519

1620
/**
17-
*<?= empty($model->description) ? '' : str_replace("\n", "\n * ", ' ' . trim($model->description)) ?>
21+
*<?= $model->getModelClassDescription() ?>
1822

1923
*
2024
<?php foreach ($model->dbAttributes() as $attribute): ?>
@@ -48,7 +52,7 @@ abstract class <?= $model->getClassName() ?> extends \yii\db\ActiveRecord
4852
<?php if($scenarios = $model->getScenarios()):
4953
foreach($scenarios as $scenario): ?>
5054
/**
51-
* <?=$scenario['description']?>
55+
* <?= $scenario['description'] ?>
5256

5357
*/
5458
public const <?= $scenario['const'] ?> = '<?= $scenario['name'] ?>';

src/lib/items/DbModel.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,25 @@ private function getScenariosByOpenapiSchema(): array
234234
return $scenarios;
235235
}
236236

237+
public function getModelClassDescription_()
238+
{
239+
return !empty($this->description) ?
240+
str_replace("\n", "\n *", ' ' . trim($this->description))
241+
: ' This is the model class for table "'.$this->tableName.'".';
242+
}
243+
244+
/** @noinspection PhpParamsInspection */
245+
public function getModelClassDescription()
246+
{
247+
if (empty($this->description)) {
248+
return ' This is the model class for table "'.$this->tableName.'".';
249+
}
250+
251+
$descriptionArr = explode("\n", $this->description);
252+
$descriptionArr = array_map('trim', $descriptionArr);
253+
$descriptionArr = array_map(function($item) {
254+
return $item !== '' ? ' ' . $item : $item;
255+
}, $descriptionArr);
256+
return implode("\n *", $descriptionArr);
257+
}
237258
}

0 commit comments

Comments
 (0)