Skip to content

Commit 067eed2

Browse files
authored
Rename dirtyValues() to newValues() and markPropertyDirty() to markPropertyChanged() (#399)
1 parent 65a85f8 commit 067eed2

8 files changed

+32
-32
lines changed

src/AbstractActiveRecord.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public function oldValue(string $propertyName): mixed
153153
*
154154
* @return array The changed property values (name-value pairs).
155155
*/
156-
public function dirtyValues(array|null $propertyNames = null): array
156+
public function newValues(array|null $propertyNames = null): array
157157
{
158158
$values = $this->propertyValues($propertyNames);
159159

@@ -489,14 +489,14 @@ public function link(string $relationName, ActiveRecordInterface $arClass, array
489489
}
490490

491491
/**
492-
* Marks a property dirty.
492+
* Marks a property as changed.
493493
*
494494
* This method may be called to force updating a record when calling {@see update()}, even if there is no change
495495
* being made to the record.
496496
*
497497
* @param string $name The property name.
498498
*/
499-
public function markPropertyDirty(string $name): void
499+
public function markPropertyChanged(string $name): void
500500
{
501501
if ($this->oldValues !== null && $name !== '') {
502502
unset($this->oldValues[$name]);
@@ -717,7 +717,7 @@ public function updateProperties(array $properties): int
717717
}
718718
}
719719

720-
$values = $this->dirtyValues($names);
720+
$values = $this->newValues($names);
721721

722722
if (empty($values) || $this->getIsNewRecord()) {
723723
return 0;
@@ -1144,7 +1144,7 @@ protected function refreshInternal(array|ActiveRecordInterface|null $record = nu
11441144
*/
11451145
protected function updateInternal(array|null $propertyNames = null): int
11461146
{
1147-
$values = $this->dirtyValues($propertyNames);
1147+
$values = $this->newValues($propertyNames);
11481148

11491149
if (empty($values)) {
11501150
return 0;

src/ActiveRecord.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ protected function propertyValuesInternal(): array
243243

244244
protected function insertInternal(array $propertyNames = null): bool
245245
{
246-
$values = $this->dirtyValues($propertyNames);
246+
$values = $this->newValues($propertyNames);
247247
$primaryKeys = $this->db()->createCommand()->insertWithReturningPks($this->getTableName(), $values);
248248

249249
if ($primaryKeys === false) {

src/ActiveRecordInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public function hasProperty(string $name): bool;
221221
/**
222222
* Inserts a row into the associated database table using the property values of this record.
223223
*
224-
* Only the {@see dirtyValues() changed property values} will be inserted into a database.
224+
* Only the {@see newValues() changed property values} will be inserted into a database.
225225
*
226226
* If the table's primary key is auto incremental and is `null` during insertion, it will be populated with the
227227
* actual value after insertion.
@@ -392,7 +392,7 @@ public function set(string $propertyName, mixed $value): void;
392392
/**
393393
* Saves the changes to this active record into the associated database table.
394394
*
395-
* Only the {@see dirtyValues() changed property values} will be saved into a database.
395+
* Only the {@see newValues() changed property values} will be saved into a database.
396396
*
397397
* For example, to update a customer record:
398398
*

tests/ActiveQueryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2476,7 +2476,7 @@ public function testUpdate(): void
24762476
$this->assertInstanceOf(Customer::class, $customer);
24772477
$this->assertEquals('user2', $customer->get('name'));
24782478
$this->assertFalse($customer->getIsNewRecord());
2479-
$this->assertEmpty($customer->dirtyValues());
2479+
$this->assertEmpty($customer->newValues());
24802480

24812481
$customer->set('name', 'user2x');
24822482
$customer->save();

tests/ActiveRecordTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -803,14 +803,14 @@ public function testGetDirtyValuesOnNewRecord(): void
803803
'bool_status' => false,
804804
'profile_id' => null,
805805
],
806-
$customer->dirtyValues()
806+
$customer->newValues()
807807
);
808808

809809
$customer->set('name', 'Adam');
810810
$customer->set('email', '[email protected]');
811811
$customer->set('address', null);
812812

813-
$this->assertEquals([], $customer->dirtyValues([]));
813+
$this->assertEquals([], $customer->newValues([]));
814814

815815
$this->assertEquals(
816816
[
@@ -821,23 +821,23 @@ public function testGetDirtyValuesOnNewRecord(): void
821821
'bool_status' => false,
822822
'profile_id' => null,
823823
],
824-
$customer->dirtyValues()
824+
$customer->newValues()
825825
);
826826
$this->assertEquals(
827827
[
828828
'email' => '[email protected]',
829829
'address' => null,
830830
'status' => 0,
831831
],
832-
$customer->dirtyValues(['id', 'email', 'address', 'status', 'unknown']),
832+
$customer->newValues(['id', 'email', 'address', 'status', 'unknown']),
833833
);
834834

835835
$this->assertTrue($customer->save());
836-
$this->assertSame([], $customer->dirtyValues());
836+
$this->assertSame([], $customer->newValues());
837837

838838
$customer->set('address', '');
839839

840-
$this->assertSame(['address' => ''], $customer->dirtyValues());
840+
$this->assertSame(['address' => ''], $customer->newValues());
841841
}
842842

843843
public function testGetDirtyValuesAfterFind(): void
@@ -847,19 +847,19 @@ public function testGetDirtyValuesAfterFind(): void
847847
$customerQuery = new ActiveQuery(Customer::class);
848848
$customer = $customerQuery->findOne(1);
849849

850-
$this->assertSame([], $customer->dirtyValues());
850+
$this->assertSame([], $customer->newValues());
851851

852852
$customer->set('name', 'Adam');
853853
$customer->set('email', '[email protected]');
854854
$customer->set('address', null);
855855

856856
$this->assertEquals(
857857
['name' => 'Adam', 'email' => '[email protected]', 'address' => null],
858-
$customer->dirtyValues(),
858+
$customer->newValues(),
859859
);
860860
$this->assertEquals(
861861
['email' => '[email protected]', 'address' => null],
862-
$customer->dirtyValues(['id', 'email', 'address', 'status', 'unknown']),
862+
$customer->newValues(['id', 'email', 'address', 'status', 'unknown']),
863863
);
864864
}
865865

tests/Driver/Pgsql/ActiveRecordTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ public function testArrayValues($properties): void
391391

392392
/** Testing update */
393393
foreach ($properties as $property => $expected) {
394-
$type->markPropertyDirty($property);
394+
$type->markPropertyChanged($property);
395395
}
396396

397397
$this->assertSame(1, $type->update(), 'The record got updated');

tests/Driver/Pgsql/MagicActiveRecordTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ public function testArrayValues($properties): void
322322

323323
/** Testing update */
324324
foreach ($properties as $property => $expected) {
325-
$type->markPropertyDirty($property);
325+
$type->markPropertyChanged($property);
326326
}
327327

328328
$this->assertSame(1, $type->update(), 'The record got updated');

tests/MagicActiveRecordTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -778,27 +778,27 @@ public function testGetDirtyValuesOnNewRecord(): void
778778

779779
$customer = new Customer();
780780

781-
$this->assertSame([], $customer->dirtyValues());
781+
$this->assertSame([], $customer->newValues());
782782

783783
$customer->set('name', 'Adam');
784784
$customer->set('email', '[email protected]');
785785
$customer->set('address', null);
786786

787787
$this->assertEquals(
788788
['name' => 'Adam', 'email' => '[email protected]', 'address' => null],
789-
$customer->dirtyValues()
789+
$customer->newValues()
790790
);
791791
$this->assertEquals(
792792
['email' => '[email protected]', 'address' => null],
793-
$customer->dirtyValues(['id', 'email', 'address', 'status', 'unknown']),
793+
$customer->newValues(['id', 'email', 'address', 'status', 'unknown']),
794794
);
795795

796796
$this->assertTrue($customer->save());
797-
$this->assertSame([], $customer->dirtyValues());
797+
$this->assertSame([], $customer->newValues());
798798

799799
$customer->set('address', '');
800800

801-
$this->assertSame(['address' => ''], $customer->dirtyValues());
801+
$this->assertSame(['address' => ''], $customer->newValues());
802802
}
803803

804804
public function testGetDirtyValuesAfterFind(): void
@@ -808,19 +808,19 @@ public function testGetDirtyValuesAfterFind(): void
808808
$customerQuery = new ActiveQuery(Customer::class);
809809
$customer = $customerQuery->findOne(1);
810810

811-
$this->assertSame([], $customer->dirtyValues());
811+
$this->assertSame([], $customer->newValues());
812812

813813
$customer->set('name', 'Adam');
814814
$customer->set('email', '[email protected]');
815815
$customer->set('address', null);
816816

817817
$this->assertEquals(
818818
['name' => 'Adam', 'email' => '[email protected]', 'address' => null],
819-
$customer->dirtyValues(),
819+
$customer->newValues(),
820820
);
821821
$this->assertEquals(
822822
['email' => '[email protected]', 'address' => null],
823-
$customer->dirtyValues(['id', 'email', 'address', 'status', 'unknown']),
823+
$customer->newValues(['id', 'email', 'address', 'status', 'unknown']),
824824
);
825825
}
826826

@@ -832,12 +832,12 @@ public function testGetDirtyValuesWithProperties(): void
832832
$this->assertSame([
833833
'name' => null,
834834
'address' => null,
835-
], $customer->dirtyValues());
835+
], $customer->newValues());
836836

837837
$customerQuery = new ActiveQuery(CustomerWithProperties::class);
838838
$customer = $customerQuery->findOne(1);
839839

840-
$this->assertSame([], $customer->dirtyValues());
840+
$this->assertSame([], $customer->newValues());
841841

842842
$customer->setEmail('[email protected]');
843843
$customer->setName('Adam');
@@ -846,11 +846,11 @@ public function testGetDirtyValuesWithProperties(): void
846846

847847
$this->assertEquals(
848848
['email' => '[email protected]', 'name' => 'Adam', 'address' => null, 'status' => null],
849-
$customer->dirtyValues(),
849+
$customer->newValues(),
850850
);
851851
$this->assertEquals(
852852
['email' => '[email protected]', 'address' => null],
853-
$customer->dirtyValues(['id', 'email', 'address', 'unknown']),
853+
$customer->newValues(['id', 'email', 'address', 'unknown']),
854854
);
855855
}
856856

0 commit comments

Comments
 (0)