77
88namespace cebe \yii2openapi \lib ;
99
10+ use cebe \openapi \exceptions \IOException ;
11+ use cebe \openapi \exceptions \TypeErrorException ;
12+ use cebe \openapi \exceptions \UnresolvableReferenceException ;
13+ use cebe \yii2openapi \lib \exceptions \InvalidDefinitionException ;
14+ use cebe \yii2openapi \lib \items \DbModel ;
1015use cebe \yii2openapi \lib \items \JunctionSchemas ;
1116use cebe \yii2openapi \lib \openapi \ComponentSchema ;
1217use Yii ;
1318use yii \base \Exception ;
19+ use yii \base \InvalidConfigException ;
1420use yii \helpers \StringHelper ;
1521use function count ;
1622
5561 */
5662class SchemaToDatabase
5763{
58- /**
59- * @var \cebe\yii2openapi\lib\Config
60- */
61- protected $ config ;
64+ protected Config $ config ;
6265
6366 public function __construct (Config $ config )
6467 {
6568 $ this ->config = $ config ;
6669 }
6770
6871 /**
69- * @return array|\cebe\yii2openapi\lib\items\ DbModel[]
70- * @throws \cebe\openapi\exceptions\ IOException
71- * @throws \cebe\openapi\exceptions\ TypeErrorException
72- * @throws \cebe\openapi\exceptions\ UnresolvableReferenceException
73- * @throws \cebe\yii2openapi\lib\exceptions\ InvalidDefinitionException
74- * @throws \yii\base\ Exception
75- * @throws \yii\base\ InvalidConfigException
72+ * @return array|DbModel[]
73+ * @throws IOException
74+ * @throws TypeErrorException
75+ * @throws UnresolvableReferenceException
76+ * @throws InvalidDefinitionException
77+ * @throws Exception
78+ * @throws InvalidConfigException
7679 */
77- public function prepareModels ():array
80+ public function prepareModels (): array
7881 {
7982 $ models = [];
8083 $ openApi = $ this ->config ->getOpenApi ();
@@ -88,11 +91,11 @@ public function prepareModels():array
8891 if ($ junctions ->isJunctionSchema ($ schemaName )) {
8992 $ schemaName = $ junctions ->trimPrefix ($ schemaName );
9093 }
91- /**@var \cebe\yii2openapi\lib\ AttributeResolver $resolver */
94+ /**@var AttributeResolver $resolver */
9295 $ resolver = Yii::createObject (AttributeResolver::class, [$ schemaName , $ schema , $ junctions , $ this ->config ]);
9396 $ models [$ schemaName ] = $ resolver ->resolve ();
9497 }
95- foreach ($ models as $ model ) {
98+ foreach ($ models as $ model ) {
9699 foreach ($ model ->many2many as $ relation ) {
97100 if (isset ($ models [$ relation ->viaModelName ])) {
98101 $ relation ->hasViaModel = true ;
@@ -108,14 +111,14 @@ public function prepareModels():array
108111 }
109112
110113 /**
111- * @return \cebe\yii2openapi\lib\items\ JunctionSchemas
112- * @throws \cebe\openapi\exceptions\ IOException
113- * @throws \cebe\openapi\exceptions\ TypeErrorException
114- * @throws \cebe\openapi\exceptions\ UnresolvableReferenceException
115- * @throws \yii\base\ Exception
116- * @throws \yii\base\ InvalidConfigException
114+ * @return JunctionSchemas
115+ * @throws IOException
116+ * @throws TypeErrorException
117+ * @throws UnresolvableReferenceException
118+ * @throws Exception
119+ * @throws InvalidConfigException|InvalidDefinitionException
117120 */
118- public function findJunctionSchemas ():JunctionSchemas
121+ public function findJunctionSchemas (): JunctionSchemas
119122 {
120123 $ junctions = [];
121124 $ openApi = $ this ->config ->getOpenApi ();
@@ -195,7 +198,7 @@ public function findJunctionSchemas():JunctionSchemas
195198 return Yii::createObject (JunctionSchemas::class, [$ junctions ]);
196199 }
197200
198- private function canGenerateModel (string $ schemaName , ComponentSchema $ schema ):bool
201+ private function canGenerateModel (string $ schemaName , ComponentSchema $ schema ): bool
199202 {
200203 // only generate tables for schemas of type object and those who have defined properties
201204 if ($ schema ->isObjectSchema () && !$ schema ->hasProperties ()) {
0 commit comments