File tree Expand file tree Collapse file tree 4 files changed +36
-21
lines changed Expand file tree Collapse file tree 4 files changed +36
-21
lines changed Original file line number Diff line number Diff line change 2222
2323 *
2424<?php foreach ($ model ->dbAttributes () as $ attribute ): ?>
25- * @property <?= $ attribute ->getFormattedDescription () ?>
25+ * @property <?= $ attribute ->getPropertyAnnotation () ?>
2626
2727<?php endforeach ; ?>
2828 *
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace cebe \yii2openapi \lib \helpers ;
4+
5+ class FormatHelper
6+ {
7+ /**
8+ * @param $description
9+ * @return string
10+ */
11+ public static function getFormattedDescription ($ description ): string
12+ {
13+ $ descriptionArr = explode ("\n" , trim ($ description ));
14+ $ descriptionArr = array_map (function ($ item ) {
15+ return $ item !== '' ? ' ' . $ item : $ item ;
16+ }, $ descriptionArr );
17+ return implode ("\n * " , $ descriptionArr );
18+ }
19+ }
Original file line number Diff line number Diff line change 77
88namespace cebe \yii2openapi \lib \items ;
99
10+ use cebe \yii2openapi \lib \helpers \FormatHelper ;
1011use yii \helpers \VarDumper ;
1112use \Yii ;
1213use cebe \yii2openapi \lib \openapi \PropertySchema ;
@@ -295,11 +296,16 @@ public function getMinLength():?int
295296 return $ this ->limits ['minLength ' ];
296297 }
297298
298- public function getFormattedDescription ():string
299+ /**
300+ * @return string
301+ */
302+ public function getPropertyAnnotation (): string
299303 {
300- $ comment = $ this ->columnName .' ' .$ this ->description ;
301- $ type = $ this ->phpType ;
302- return $ type .' $ ' .str_replace ("\n" , "\n * " , rtrim ($ comment ));
304+ $ annotation = $ this ->phpType . ' $ ' . $ this ->columnName ;
305+ if (!empty ($ this ->description )) {
306+ $ annotation .= FormatHelper::getFormattedDescription ($ this ->description );
307+ }
308+ return $ annotation ;
303309 }
304310
305311 public function toColumnSchema ():ColumnSchema
Original file line number Diff line number Diff line change 77
88namespace cebe \yii2openapi \lib \items ;
99
10+ use cebe \yii2openapi \lib \helpers \FormatHelper ;
1011use cebe \yii2openapi \lib \ValidationRulesBuilder ;
1112use Yii ;
1213use yii \base \BaseObject ;
@@ -234,25 +235,14 @@ private function getScenariosByOpenapiSchema(): array
234235 return $ scenarios ;
235236 }
236237
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 ()
238+ /**
239+ * @return string
240+ */
241+ public function getModelClassDescription (): string
246242 {
247243 if (empty ($ this ->description )) {
248244 return ' This is the model class for table " ' .$ this ->tableName .'". ' ;
249245 }
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 );
246+ return FormatHelper::getFormattedDescription ($ this ->description );
257247 }
258248}
You can’t perform that action at this time.
0 commit comments