From 84c55b468ad83dbca0b706a97f82f556a05ea244 Mon Sep 17 00:00:00 2001 From: Vladimir Reznichenko Date: Sun, 1 Jul 2018 00:04:48 +0200 Subject: [PATCH] [minor] SCA (#16464) * Php Inspections (EA Ultimate): new findings * Php Inspections (EA Ultimate): dealing with older PHP versions compatibility --- framework/db/ActiveRelationTrait.php | 5 +---- framework/db/BaseActiveRecord.php | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/framework/db/ActiveRelationTrait.php b/framework/db/ActiveRelationTrait.php index 5c196daa0e..73df49ba66 100644 --- a/framework/db/ActiveRelationTrait.php +++ b/framework/db/ActiveRelationTrait.php @@ -504,10 +504,7 @@ trait ActiveRelationTrait // composite keys // ensure keys of $this->link are prefixed the same way as $attributes - $prefixedLink = array_combine( - $attributes, - array_values($this->link) - ); + $prefixedLink = array_combine($attributes, $this->link); foreach ($models as $model) { $v = []; foreach ($prefixedLink as $attribute => $link) { diff --git a/framework/db/BaseActiveRecord.php b/framework/db/BaseActiveRecord.php index df96904893..e19b0a8fbb 100644 --- a/framework/db/BaseActiveRecord.php +++ b/framework/db/BaseActiveRecord.php @@ -1572,9 +1572,9 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface throw new InvalidCallException('Unable to link models: the primary key of ' . get_class($primaryModel) . ' is null.'); } if (is_array($foreignModel->$fk)) { // relation via array valued attribute - $foreignModel->$fk = array_merge($foreignModel->$fk, [$value]); + $foreignModel->{$fk}[] = $value; } else { - $foreignModel->$fk = $value; + $foreignModel->{$fk} = $value; } } $foreignModel->save(false);