2121use Crud \Traits \SerializeTrait ;
2222use Crud \Traits \ViewTrait ;
2323use Crud \Traits \ViewVarTrait ;
24+ use function Cake \Core \pluginSplit ;
25+ use function Cake \I18n \__ ;
2426
2527/**
2628 * Class RelationshipViewAction
@@ -47,7 +49,7 @@ class RelationshipsAction extends BaseAction
4749 *
4850 * @var array
4951 */
50- protected $ _defaultConfig = [
52+ protected array $ _defaultConfig = [
5153 'enabled ' => true ,
5254 'scope ' => 'entity ' ,
5355 'findMethod ' => 'all ' ,
@@ -150,7 +152,7 @@ public function checkAllowed(): void
150152 protected function _findRelations (Subject $ subject ): EntityInterface
151153 {
152154 $ relationName = $ this ->_request ()->getParam ('type ' );
153- $ table = $ this ->_table ();
155+ $ table = $ this ->_controller ()-> fetchTable ();
154156 $ association = $ table ->getAssociation ($ relationName );
155157 $ targetTable = $ association ->getTarget ();
156158
@@ -188,7 +190,7 @@ protected function _findRelations(Subject $subject): EntityInterface
188190 ->where (
189191 [
190192 $ table ->aliasField ($ primaryKey ) => $ foreignKeyParam ,
191- ]
193+ ],
192194 )
193195 ->contain ([
194196 $ relationName => [
@@ -202,7 +204,7 @@ protected function _findRelations(Subject $subject): EntityInterface
202204 'association ' => $ association ,
203205 'repository ' => $ table ,
204206 'query ' => $ primaryQuery ,
205- ]
207+ ],
206208 );
207209 $ this ->_trigger ('beforeFind ' , $ subject );
208210 $ entity = $ subject ->query ->first ();
@@ -239,7 +241,7 @@ protected function _get(): void
239241 *
240242 * @return void
241243 */
242- protected function _delete ()
244+ protected function _delete (): void
243245 {
244246 $ subject = $ this ->_subject ();
245247 $ request = $ this ->_request ();
@@ -272,7 +274,7 @@ protected function _delete()
272274 $ idsToDelete = (array )Hash::extract ($ data , '{n}.id ' );
273275 $ foreignRecords = $ entity ->$ property ;
274276 $ entity ->$ property = [];
275- foreach ($ foreignRecords as $ key => $ foreignRecord ) {
277+ foreach ($ foreignRecords as $ foreignRecord ) {
276278 if (!in_array ($ foreignRecord ->id , $ idsToDelete , false )) {
277279 $ entity ->{$ property }[] = $ foreignRecord ;
278280 }
@@ -284,7 +286,7 @@ protected function _delete()
284286 $ association ->setSaveStrategy ('replace ' );
285287 }
286288 $ saveMethod = $ this ->saveMethod ();
287- if ($ this ->_table ()->$ saveMethod ($ entity , $ this ->saveOptions ())) {
289+ if ($ this ->_controller ()-> fetchTable ()->$ saveMethod ($ entity , $ this ->saveOptions ())) {
288290 $ this ->_success ($ subject );
289291
290292 return ;
@@ -298,7 +300,7 @@ protected function _delete()
298300 *
299301 * @return void
300302 */
301- protected function _post ()
303+ protected function _post (): void
302304 {
303305 $ subject = $ this ->_subject ();
304306 $ request = $ this ->_request ();
@@ -333,7 +335,7 @@ protected function _post()
333335 $ this ->_trigger ('beforeSave ' , $ subject );
334336
335337 $ saveMethod = $ this ->saveMethod ();
336- if ($ this ->_table ()->$ saveMethod ($ entity , $ this ->saveOptions ())) {
338+ if ($ this ->_controller ()-> fetchTable ()->$ saveMethod ($ entity , $ this ->saveOptions ())) {
337339 $ this ->_success ($ subject );
338340
339341 return ;
@@ -347,7 +349,7 @@ protected function _post()
347349 *
348350 * @return void
349351 */
350- protected function _patch ()
352+ protected function _patch (): void
351353 {
352354 $ subject = $ this ->_subject ();
353355 $ request = $ this ->_request ();
@@ -363,7 +365,6 @@ protected function _patch()
363365
364366 if (in_array ($ association ->type (), [Association::MANY_TO_ONE , Association::ONE_TO_ONE ], true )) {
365367 //Set the relationship to the corresponding entity
366- /** @psalm-suppress TypeDoesNotContainNull */
367368 if (array_key_exists ('id ' , $ data )) {
368369 $ entity ->{$ property } = $ foreignTable ->get ($ data ['id ' ]);
369370 } elseif ($ data === null ) {
@@ -382,7 +383,7 @@ protected function _patch()
382383 $ association ->setSaveStrategy ('replace ' );
383384 }
384385 $ saveMethod = $ this ->saveMethod ();
385- if ($ this ->_table ()->$ saveMethod ($ entity , $ this ->saveOptions ())) {
386+ if ($ this ->_controller ()-> fetchTable ()->$ saveMethod ($ entity , $ this ->saveOptions ())) {
386387 $ this ->_success ($ subject );
387388
388389 return ;
@@ -442,21 +443,21 @@ protected function getForeignRecords(array $data, Association $association): arr
442443 ->where (
443444 [
444445 $ association ->aliasField ($ associationPrimaryKey ) . ' in ' => $ idsToAdd ,
445- ]
446+ ],
446447 )
447448 ->all ();
448449
449450 if (count ($ idsToAdd ) !== count ($ foreignRecords )) {
450451 $ foundIds = $ foreignRecords ->extract (
451452 static function ($ record ) {
452453 return $ record ->id ;
453- }
454+ },
454455 )
455456 ->toArray ();
456457 $ missingIds = array_diff ($ idsToAdd , $ foundIds );
457458
458459 throw new RecordNotFoundException (
459- __ ('Not all requested records could be found. Missing IDs are {0} ' , implode (', ' , $ missingIds ))
460+ __ ('Not all requested records could be found. Missing IDs are {0} ' , implode (', ' , $ missingIds )),
460461 );
461462 }
462463
0 commit comments