@@ -139,7 +139,8 @@ public function annotate(string $path): bool {
139139 $ entityClassName = $ table ->getEntityClass ();
140140 $ entityName = substr ($ entityClassName , strrpos ($ entityClassName , '\\' ) + 1 );
141141
142- $ resTable = $ this ->table ($ path , $ entityName , $ associations , $ behaviors );
142+ $ parentClass = (string )get_parent_class ($ table );
143+ $ resTable = $ this ->table ($ path , $ entityName , $ associations , $ behaviors , $ parentClass );
143144 $ resEntity = $ this ->entity ($ entityClassName , $ entityName , $ schema , $ tableAssociations );
144145
145146 return $ resTable || $ resEntity ;
@@ -150,17 +151,17 @@ public function annotate(string $path): bool {
150151 * @param string $entityName
151152 * @param array<string, mixed> $associations
152153 * @param array<string> $behaviors
153- *
154+ * @param string $parentClass
154155 * @return bool
155156 */
156- protected function table (string $ path , string $ entityName , array $ associations , array $ behaviors ): bool {
157+ protected function table (string $ path , string $ entityName , array $ associations , array $ behaviors, string $ parentClass ): bool {
157158 $ content = file_get_contents ($ path );
158159 if ($ content === false ) {
159160 throw new RuntimeException ('Cannot read file ' );
160161 }
161162
162163 $ behaviors += $ this ->parseLoadedBehaviors ($ content );
163- $ annotations = $ this ->buildAnnotations ($ associations , $ entityName , $ behaviors );
164+ $ annotations = $ this ->buildAnnotations ($ associations , $ entityName , $ behaviors, $ parentClass );
164165
165166 return $ this ->annotateContent ($ path , $ content , $ annotations );
166167 }
@@ -169,12 +170,10 @@ protected function table(string $path, string $entityName, array $associations,
169170 * @param array<string, mixed> $associations
170171 * @param string $entity
171172 * @param array<string> $behaviors
172- *
173- * @throws \RuntimeException
174- *
173+ * @param string $parentClass
175174 * @return array<\IdeHelper\Annotation\AbstractAnnotation>
176175 */
177- protected function buildAnnotations (array $ associations , string $ entity , array $ behaviors ): array {
176+ protected function buildAnnotations (array $ associations , string $ entity , array $ behaviors, string $ parentClass ): array {
178177 $ namespace = $ this ->getConfig (static ::CONFIG_NAMESPACE );
179178 $ annotations = [];
180179 foreach ($ associations as $ type => $ assocs ) {
@@ -244,7 +243,7 @@ protected function buildAnnotations(array $associations, string $entity, array $
244243 }
245244
246245 $ result = $ this ->addBehaviorMixins ($ result , $ behaviors );
247- $ result = $ this ->addBehaviorExtends ($ result , $ behaviors );
246+ $ result = $ this ->addBehaviorExtends ($ result , $ behaviors, $ parentClass );
248247
249248 return $ result ;
250249 }
@@ -469,9 +468,10 @@ protected function addBehaviorMixins(array $result, array $behaviors): array {
469468 /**
470469 * @param array<\IdeHelper\Annotation\AbstractAnnotation> $result
471470 * @param array<string> $behaviors
471+ * @param string $parentClass
472472 * @return array<\IdeHelper\Annotation\AbstractAnnotation>
473473 */
474- protected function addBehaviorExtends (array $ result , array $ behaviors ): array {
474+ protected function addBehaviorExtends (array $ result , array $ behaviors, string $ parentClass ): array {
475475 if (!in_array (static ::BEHAVIOR_EXTENDS , $ this ->_config [static ::TABLE_BEHAVIORS ], true )) {
476476 return $ result ;
477477 }
@@ -497,7 +497,10 @@ protected function addBehaviorExtends(array $result, array $behaviors): array {
497497
498498 $ list = implode (', ' , $ list );
499499
500- $ result [] = AnnotationFactory::createOrFail (ExtendsAnnotation::TAG , '\\Cake \\ORM \\Table<array{ ' . $ list . '}> ' );
500+ if (!$ parentClass ) {
501+ $ parentClass = '\\Cake \\ORM \\Table ' ;
502+ }
503+ $ result [] = AnnotationFactory::createOrFail (ExtendsAnnotation::TAG , '\\' . $ parentClass . '<array{ ' . $ list . '}> ' );
501504
502505 return $ result ;
503506 }
0 commit comments