Skip to content

Commit 36d3a0e

Browse files
committed
AttributeAnnotation
1 parent f96257d commit 36d3a0e

File tree

3 files changed

+27
-21
lines changed

3 files changed

+27
-21
lines changed

src/generator/default/dbmodel.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
*
2424
<?php foreach ($model->dbAttributes() as $attribute): ?>
25-
* @property <?= $attribute->getFormattedDescription() ?>
25+
* @property <?= $attribute->getAttributeAnnotation() ?>
2626

2727
<?php endforeach; ?>
2828
*

src/lib/items/Attribute.php

+20-4
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,27 @@ public function getMinLength():?int
295295
return $this->limits['minLength'];
296296
}
297297

298-
public function getFormattedDescription():string
298+
public function getAttributeAnnotation():string
299299
{
300-
$comment = $this->columnName.' '.$this->description;
301-
$type = $this->phpType;
302-
return $type.' $'.str_replace("\n", "\n * ", rtrim($comment));
300+
$annotation = $this->phpType . ' $' . $this->columnName;
301+
if (!empty($this->description)) {
302+
$annotation .= self::getFormattedDescription($this->description);
303+
}
304+
return $annotation;
305+
}
306+
307+
/**
308+
* @param $description
309+
* @return string
310+
* @noinspection PhpParamsInspection
311+
*/
312+
public static function getFormattedDescription($description)
313+
{
314+
$descriptionArr = explode("\n", trim($description));
315+
$descriptionArr = array_map(function($item) {
316+
return $item !== '' ? ' ' . $item : $item;
317+
}, $descriptionArr);
318+
return implode("\n *", $descriptionArr);
303319
}
304320

305321
public function toColumnSchema():ColumnSchema

src/lib/items/DbModel.php

+6-16
Original file line numberDiff line numberDiff line change
@@ -234,25 +234,15 @@ 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()
237+
/**
238+
* @return string
239+
*/
240+
public function getModelClassDescription(): string
246241
{
247242
if (empty($this->description)) {
248243
return ' This is the model class for table "'.$this->tableName.'".';
249244
}
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);
245+
return Attribute::getFormattedDescription($this->description);
257246
}
247+
258248
}

0 commit comments

Comments
 (0)