Skip to content

Commit e25b36c

Browse files
committed
Refactor
1 parent 489f0f5 commit e25b36c

File tree

1 file changed

+41
-46
lines changed

1 file changed

+41
-46
lines changed

src/lib/items/DbModel.php

Lines changed: 41 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -10,83 +10,78 @@
1010
use cebe\yii2openapi\lib\ValidationRulesBuilder;
1111
use Yii;
1212
use yii\base\BaseObject;
13+
use yii\base\InvalidConfigException;
1314
use yii\db\ColumnSchema;
1415
use yii\helpers\Inflector;
15-
use yii\helpers\StringHelper;
1616
use yii\helpers\VarDumper;
1717
use function array_filter;
1818
use function array_map;
1919
use function str_replace;
2020
use const PHP_EOL;
2121

2222
/**
23-
* @property-read string $tableAlias
24-
* @property-read array $uniqueColumnsList
25-
* @property-read array[]|array $attributesByType
26-
* @property-read array|\cebe\yii2openapi\lib\items\AttributeRelation[] $hasOneRelations
23+
* @property-read string $tableAlias
24+
* @property-read array $uniqueColumnsList
25+
* @property-read array[]|array $attributesByType
26+
* @property-read array|AttributeRelation[] $hasOneRelations
2727
*/
2828
class DbModel extends BaseObject
2929
{
30-
/**
31-
* @var string primary key attribute name
32-
*/
33-
public $pkName;
30+
// primary key attribute name
31+
public string $pkName;
3432

35-
/**
36-
* @var string model name.
37-
*/
38-
public $name;
33+
// model name
34+
public string $name;
3935

40-
/**
41-
* @var string table name. (without brackets and db prefix)
42-
*/
43-
public $tableName;
36+
// table name. (without brackets and db prefix)
37+
public string $tableName;
4438

45-
/**
46-
* @var string description from the schema.
47-
*/
48-
public $description;
39+
// description from the schema.
40+
public string $description;
4941

5042
/**
51-
* @var array|\cebe\yii2openapi\lib\items\Attribute[] model attributes.
43+
* @var array|Attribute[] model attributes.
5244
*/
53-
public $attributes = [];
45+
public array $attributes = [];
5446

5547
/**
56-
* @var array|\cebe\yii2openapi\lib\items\AttributeRelation[] database relations.
48+
* @var array|AttributeRelation[] database relations.
5749
*/
58-
public $relations = [];
50+
public array $relations = [];
5951

6052
/***
61-
* @var array|\cebe\yii2openapi\lib\items\NonDbRelation[] non-db relations
53+
* @var array|NonDbRelation[] non-db relations
6254
*/
63-
public $nonDbRelations = [];
55+
public array $nonDbRelations = [];
6456

6557
/**
66-
* @var array|\cebe\yii2openapi\lib\items\ManyToManyRelation[] many to many relations.
58+
* @var array|ManyToManyRelation[] many-to-many relations.
6759
*/
68-
public $many2many = [];
60+
public array $many2many = [];
6961

70-
public $junctionCols = [];
62+
public array $junctionCols = [];
7163

7264
/**
73-
* @var \cebe\yii2openapi\lib\items\DbIndex[]|array
65+
* @var DbIndex[]|array
7466
*/
75-
public $indexes = [];
67+
public array $indexes = [];
7668

77-
public $isNotDb = false;
69+
public bool $isNotDb = false;
7870

79-
public function getTableAlias():string
71+
public function getTableAlias(): string
8072
{
8173
return '{{%' . $this->tableName . '}}';
8274
}
8375

84-
public function getClassName():string
76+
public function getClassName(): string
8577
{
8678
return Inflector::id2camel($this->name, '_');
8779
}
8880

89-
public function getValidationRules():string
81+
/**
82+
* @throws InvalidConfigException
83+
*/
84+
public function getValidationRules(): string
9085
{
9186
$rules = Yii::createObject(ValidationRulesBuilder::class, [$this])->build();
9287
$rules = array_map('strval', $rules);
@@ -105,9 +100,9 @@ public function getValidationRules():string
105100
}
106101

107102
/**
108-
* @return \cebe\yii2openapi\lib\items\AttributeRelation[]|array
103+
* @return AttributeRelation[]|array
109104
*/
110-
public function getHasOneRelations():array
105+
public function getHasOneRelations(): array
111106
{
112107
return array_filter(
113108
$this->relations,
@@ -117,15 +112,15 @@ static function (AttributeRelation $relation) {
117112
);
118113
}
119114

120-
public function getPkAttribute():Attribute
115+
public function getPkAttribute(): Attribute
121116
{
122117
return $this->attributes[$this->pkName];
123118
}
124119

125120
/**
126121
* @return ColumnSchema[]
127122
*/
128-
public function attributesToColumnSchema():array
123+
public function attributesToColumnSchema(): array
129124
{
130125
return $this->isNotDb
131126
? []
@@ -142,9 +137,9 @@ static function ($acc, Attribute $attribute) {
142137
}
143138

144139
/**
145-
* @return array|\cebe\yii2openapi\lib\items\Attribute[]
140+
* @return array|Attribute[]
146141
*/
147-
public function getEnumAttributes():array
142+
public function getEnumAttributes(): array
148143
{
149144
return array_filter(
150145
$this->attributes,
@@ -155,19 +150,19 @@ static function (Attribute $attribute) {
155150
}
156151

157152
/**
158-
* @return array|\cebe\yii2openapi\lib\items\Attribute[]
153+
* @return array|Attribute[]
159154
*/
160-
public function virtualAttributes():array
155+
public function virtualAttributes(): array
161156
{
162157
return array_filter($this->attributes, static function (Attribute $attribute) {
163158
return $attribute->isVirtual;
164159
});
165160
}
166161

167162
/**
168-
* @return array|\cebe\yii2openapi\lib\items\Attribute[]
163+
* @return array|Attribute[]
169164
*/
170-
public function dbAttributes():array
165+
public function dbAttributes(): array
171166
{
172167
return array_filter($this->attributes, static function (Attribute $attribute) {
173168
return !$attribute->isVirtual;

0 commit comments

Comments
 (0)