Skip to content

Commit b2bf84d

Browse files
committed
refactor: replace $data with $row
1 parent f4d17d2 commit b2bf84d

2 files changed

Lines changed: 58 additions & 58 deletions

File tree

system/BaseModel.php

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -478,13 +478,13 @@ abstract protected function doOnlyDeleted();
478478
* Compiles a replace and runs the query.
479479
* This method works only with dbCalls.
480480
*
481-
* @param array|null $data Data
482-
* @phpstan-param row_array|null $data
481+
* @param array|null $row Row data
482+
* @phpstan-param row_array|null $row
483483
* @param bool $returnSQL Set to true to return Query String
484484
*
485485
* @return BaseResult|false|Query|string
486486
*/
487-
abstract protected function doReplace(?array $data = null, bool $returnSQL = false);
487+
abstract protected function doReplace(?array $row = null, bool $returnSQL = false);
488488

489489
/**
490490
* Grabs the last error(s) that occurred from the Database connection.
@@ -741,27 +741,27 @@ public function getInsertID()
741741
* Inserts data into the database. If an object is provided,
742742
* it will attempt to convert it to an array.
743743
*
744-
* @param array|object|null $data Data
745-
* @phpstan-param row_array|object|null $data
744+
* @param array|object|null $row Row data
745+
* @phpstan-param row_array|object|null $row
746746
* @param bool $returnID Whether insert ID should be returned or not.
747747
*
748748
* @return bool|int|string insert ID or true on success. false on failure.
749749
* @phpstan-return ($returnID is true ? int|string|false : bool)
750750
*
751751
* @throws ReflectionException
752752
*/
753-
public function insert($data = null, bool $returnID = true)
753+
public function insert($row = null, bool $returnID = true)
754754
{
755755
$this->insertID = 0;
756756

757757
// Set $cleanValidationRules to false temporary.
758758
$cleanValidationRules = $this->cleanValidationRules;
759759
$this->cleanValidationRules = false;
760760

761-
$data = $this->transformDataToArray($data, 'insert');
761+
$row = $this->transformDataToArray($row, 'insert');
762762

763763
// Validate data before saving.
764-
if (! $this->skipValidation && ! $this->validate($data)) {
764+
if (! $this->skipValidation && ! $this->validate($row)) {
765765
// Restore $cleanValidationRules
766766
$this->cleanValidationRules = $cleanValidationRules;
767767

@@ -773,20 +773,20 @@ public function insert($data = null, bool $returnID = true)
773773

774774
// Must be called first, so we don't
775775
// strip out created_at values.
776-
$data = $this->doProtectFieldsForInsert($data);
776+
$row = $this->doProtectFieldsForInsert($row);
777777

778778
// doProtectFields() can further remove elements from
779779
// $data so we need to check for empty dataset again
780-
if (! $this->allowEmptyInserts && empty($data)) {
780+
if (! $this->allowEmptyInserts && empty($row)) {
781781
throw DataException::forEmptyDataset('insert');
782782
}
783783

784784
// Set created_at and updated_at with same time
785785
$date = $this->setDate();
786-
$data = $this->setCreatedField($data, $date);
787-
$data = $this->setUpdatedField($data, $date);
786+
$row = $this->setCreatedField($row, $date);
787+
$row = $this->setUpdatedField($row, $date);
788788

789-
$eventData = ['data' => $data];
789+
$eventData = ['data' => $row];
790790

791791
if ($this->tempAllowCallbacks) {
792792
$eventData = $this->trigger('beforeInsert', $eventData);
@@ -931,12 +931,12 @@ public function insertBatch(?array $set = null, ?bool $escape = null, int $batch
931931
* it will attempt to convert it into an array.
932932
*
933933
* @param array|int|string|null $id
934-
* @param array|object|null $data
935-
* @phpstan-param row_array|object|null $data
934+
* @param array|object|null $row Row data
935+
* @phpstan-param row_array|object|null $row
936936
*
937937
* @throws ReflectionException
938938
*/
939-
public function update($id = null, $data = null): bool
939+
public function update($id = null, $row = null): bool
940940
{
941941
if (is_bool($id)) {
942942
throw new InvalidArgumentException('update(): argument #1 ($id) should not be boolean.');
@@ -946,28 +946,28 @@ public function update($id = null, $data = null): bool
946946
$id = [$id];
947947
}
948948

949-
$data = $this->transformDataToArray($data, 'update');
949+
$row = $this->transformDataToArray($row, 'update');
950950

951951
// Validate data before saving.
952-
if (! $this->skipValidation && ! $this->validate($data)) {
952+
if (! $this->skipValidation && ! $this->validate($row)) {
953953
return false;
954954
}
955955

956956
// Must be called first, so we don't
957957
// strip out updated_at values.
958-
$data = $this->doProtectFields($data);
958+
$row = $this->doProtectFields($row);
959959

960960
// doProtectFields() can further remove elements from
961961
// $data, so we need to check for empty dataset again
962-
if (empty($data)) {
962+
if (empty($row)) {
963963
throw DataException::forEmptyDataset('update');
964964
}
965965

966-
$data = $this->setUpdatedField($data, $this->setDate());
966+
$row = $this->setUpdatedField($row, $this->setDate());
967967

968968
$eventData = [
969969
'id' => $id,
970-
'data' => $data,
970+
'data' => $row,
971971
];
972972

973973
if ($this->tempAllowCallbacks) {
@@ -1166,22 +1166,22 @@ public function onlyDeleted()
11661166
/**
11671167
* Compiles a replace and runs the query.
11681168
*
1169-
* @param array|null $data Data
1170-
* @phpstan-param row_array|null $data
1169+
* @param array|null $row Row data
1170+
* @phpstan-param row_array|null $row
11711171
* @param bool $returnSQL Set to true to return Query String
11721172
*
11731173
* @return BaseResult|false|Query|string
11741174
*/
1175-
public function replace(?array $data = null, bool $returnSQL = false)
1175+
public function replace(?array $row = null, bool $returnSQL = false)
11761176
{
11771177
// Validate data before saving.
1178-
if (($data !== null) && ! $this->skipValidation && ! $this->validate($data)) {
1178+
if (($row !== null) && ! $this->skipValidation && ! $this->validate($row)) {
11791179
return false;
11801180
}
11811181

1182-
$data = $this->setUpdatedField((array) $data, $this->setDate());
1182+
$row = $this->setUpdatedField((array) $row, $this->setDate());
11831183

1184-
return $this->doReplace($data, $returnSQL);
1184+
return $this->doReplace($row, $returnSQL);
11851185
}
11861186

11871187
/**
@@ -1749,48 +1749,48 @@ protected function objectToRawArray($object, bool $onlyChanged = true, bool $rec
17491749
/**
17501750
* Transform data to array.
17511751
*
1752-
* @param array|object|null $data Data
1753-
* @phpstan-param row_array|object|null $data
1752+
* @param array|object|null $row Row data
1753+
* @phpstan-param row_array|object|null $row
17541754
* @param string $type Type of data (insert|update)
17551755
*
17561756
* @throws DataException
17571757
* @throws InvalidArgumentException
17581758
* @throws ReflectionException
17591759
*/
1760-
protected function transformDataToArray($data, string $type): array
1760+
protected function transformDataToArray($row, string $type): array
17611761
{
17621762
if (! in_array($type, ['insert', 'update'], true)) {
17631763
throw new InvalidArgumentException(sprintf('Invalid type "%s" used upon transforming data to array.', $type));
17641764
}
17651765

1766-
if (! $this->allowEmptyInserts && empty($data)) {
1766+
if (! $this->allowEmptyInserts && empty($row)) {
17671767
throw DataException::forEmptyDataset($type);
17681768
}
17691769

17701770
// If $data is using a custom class with public or protected
17711771
// properties representing the collection elements, we need to grab
17721772
// them as an array.
1773-
if (is_object($data) && ! $data instanceof stdClass) {
1773+
if (is_object($row) && ! $row instanceof stdClass) {
17741774
// If it validates with entire rules, all fields are needed.
17751775
$onlyChanged = ($this->skipValidation === false && $this->cleanValidationRules === false)
17761776
? false : ($type === 'update');
17771777

1778-
$data = $this->objectToArray($data, $onlyChanged, true);
1778+
$row = $this->objectToArray($row, $onlyChanged, true);
17791779
}
17801780

17811781
// If it's still a stdClass, go ahead and convert to
17821782
// an array so doProtectFields and other model methods
17831783
// don't have to do special checks.
1784-
if (is_object($data)) {
1785-
$data = (array) $data;
1784+
if (is_object($row)) {
1785+
$row = (array) $row;
17861786
}
17871787

17881788
// If it's still empty here, means $data is no change or is empty object
1789-
if (! $this->allowEmptyInserts && empty($data)) {
1789+
if (! $this->allowEmptyInserts && empty($row)) {
17901790
throw DataException::forEmptyDataset($type);
17911791
}
17921792

1793-
return $data;
1793+
return $row;
17941794
}
17951795

17961796
/**

system/Model.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -481,15 +481,15 @@ protected function doOnlyDeleted()
481481
* Compiles a replace into string and runs the query
482482
* This method works only with dbCalls.
483483
*
484-
* @param array|null $data Data
485-
* @phpstan-param row_array|null $data
484+
* @param array|null $row Data
485+
* @phpstan-param row_array|null $row
486486
* @param bool $returnSQL Set to true to return Query String
487487
*
488488
* @return BaseResult|false|Query|string
489489
*/
490-
protected function doReplace(?array $data = null, bool $returnSQL = false)
490+
protected function doReplace(?array $row = null, bool $returnSQL = false)
491491
{
492-
return $this->builder()->testMode($returnSQL)->replace($data);
492+
return $this->builder()->testMode($returnSQL)->replace($row);
493493
}
494494

495495
/**
@@ -713,30 +713,30 @@ protected function shouldUpdate($data): bool
713713
* Inserts data into the database. If an object is provided,
714714
* it will attempt to convert it to an array.
715715
*
716-
* @param array|object|null $data
717-
* @phpstan-param row_array|object|null $data
716+
* @param array|object|null $row
717+
* @phpstan-param row_array|object|null $row
718718
* @param bool $returnID Whether insert ID should be returned or not.
719719
*
720720
* @return bool|int|string
721721
* @phpstan-return ($returnID is true ? int|string|false : bool)
722722
*
723723
* @throws ReflectionException
724724
*/
725-
public function insert($data = null, bool $returnID = true)
725+
public function insert($row = null, bool $returnID = true)
726726
{
727727
if (! empty($this->tempData['data'])) {
728-
if (empty($data)) {
729-
$data = $this->tempData['data'];
728+
if (empty($row)) {
729+
$row = $this->tempData['data'];
730730
} else {
731-
$data = $this->transformDataToArray($data, 'insert');
732-
$data = array_merge($this->tempData['data'], $data);
731+
$row = $this->transformDataToArray($row, 'insert');
732+
$row = array_merge($this->tempData['data'], $row);
733733
}
734734
}
735735

736736
$this->escape = $this->tempData['escape'] ?? [];
737737
$this->tempData = [];
738738

739-
return parent::insert($data, $returnID);
739+
return parent::insert($row, $returnID);
740740
}
741741

742742
/**
@@ -779,26 +779,26 @@ protected function doProtectFieldsForInsert(array $data): array
779779
* it will attempt to convert it into an array.
780780
*
781781
* @param array|int|string|null $id
782-
* @param array|object|null $data
783-
* @phpstan-param row_array|object|null $data
782+
* @param array|object|null $row
783+
* @phpstan-param row_array|object|null $row
784784
*
785785
* @throws ReflectionException
786786
*/
787-
public function update($id = null, $data = null): bool
787+
public function update($id = null, $row = null): bool
788788
{
789789
if (! empty($this->tempData['data'])) {
790-
if (empty($data)) {
791-
$data = $this->tempData['data'];
790+
if (empty($row)) {
791+
$row = $this->tempData['data'];
792792
} else {
793-
$data = $this->transformDataToArray($data, 'update');
794-
$data = array_merge($this->tempData['data'], $data);
793+
$row = $this->transformDataToArray($row, 'update');
794+
$row = array_merge($this->tempData['data'], $row);
795795
}
796796
}
797797

798798
$this->escape = $this->tempData['escape'] ?? [];
799799
$this->tempData = [];
800800

801-
return parent::update($id, $data);
801+
return parent::update($id, $row);
802802
}
803803

804804
/**

0 commit comments

Comments
 (0)