Skip to content

Commit 3aadcdc

Browse files
authored
Cleanup (#453)
1 parent da0ceae commit 3aadcdc

File tree

7 files changed

+13
-23
lines changed

7 files changed

+13
-23
lines changed

src/Event/AbstractEvent.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,9 @@ abstract class AbstractEvent implements StoppableEventInterface
2222
/**
2323
* @param ActiveRecordInterface $model The target model associated with this event.
2424
*/
25-
public function __construct(private readonly ActiveRecordInterface $model)
26-
{
27-
}
28-
29-
/**
30-
* @return ActiveRecordInterface The target model associated with this event.
31-
*/
32-
public function getModel(): ActiveRecordInterface
33-
{
34-
return $this->model;
25+
public function __construct(
26+
public readonly ActiveRecordInterface $model,
27+
) {
3528
}
3629

3730
/**

src/Event/AfterCreateQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ final class AfterCreateQuery extends AbstractEvent
1616
{
1717
public function __construct(
1818
ActiveRecordInterface $model,
19-
public ActiveQueryInterface &$query,
19+
public readonly ActiveQueryInterface $query,
2020
) {
2121
parent::__construct($model);
2222
}

src/Event/BeforeCreateQuery.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,4 @@
1313
*/
1414
final class BeforeCreateQuery extends AbstractEvent
1515
{
16-
public function __construct(
17-
ActiveRecordInterface $model,
18-
) {
19-
parent::__construct($model);
20-
}
2116
}

src/Event/Handler/DefaultValue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function getEventHandlers(): array
3535

3636
private function afterPopulate(AfterPopulate $event): void
3737
{
38-
$model = $event->getModel();
38+
$model = $event->model;
3939
$value = is_callable($this->value) ? ($this->value)($event) : $this->value;
4040

4141
foreach ($this->getPropertyNames() as $propertyName) {

src/Event/Handler/DefaultValueOnInsert.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function getEventHandlers(): array
3636

3737
private function beforeInsert(BeforeInsert $event): void
3838
{
39-
$model = $event->getModel();
39+
$model = $event->model;
4040
$value = is_callable($this->value) ? ($this->value)($event) : $this->value;
4141

4242
foreach ($this->getPropertyNames() as $propertyName) {
@@ -48,7 +48,7 @@ private function beforeInsert(BeforeInsert $event): void
4848

4949
private function beforeUpsert(BeforeUpsert $event): void
5050
{
51-
$model = $event->getModel();
51+
$model = $event->model;
5252
$value = is_callable($this->value) ? ($this->value)($event) : $this->value;
5353

5454
foreach ($this->getPropertyNames() as $propertyName) {

src/Event/Handler/SetValueOnUpdate.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function getEventHandlers(): array
3535

3636
private function beforeUpdate(BeforeUpdate $event): void
3737
{
38-
$model = $event->getModel();
38+
$model = $event->model;
3939
$value = is_callable($this->value) ? ($this->value)($event) : $this->value;
4040

4141
foreach ($this->getPropertyNames() as $propertyName) {
@@ -47,7 +47,7 @@ private function beforeUpdate(BeforeUpdate $event): void
4747

4848
private function beforeUpsert(BeforeUpsert $event): void
4949
{
50-
$model = $event->getModel();
50+
$model = $event->model;
5151
$value = is_callable($this->value) ? ($this->value)($event) : $this->value;
5252

5353
$updateProperties = match ($event->updateProperties) {

src/Event/Handler/SoftDelete.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Yiisoft\ActiveRecord\Event\BeforeDelete;
1111
use Yiisoft\Db\QueryBuilder\Condition\Equals;
1212

13+
use function is_callable;
14+
1315
/**
1416
* Attribute for implementing soft deletion in Active Record models. Instead of deleting records from the
1517
* database, it sets a value of the date and time for properties to indicate that the record has been logically deleted.
@@ -43,7 +45,7 @@ public function getEventHandlers(): array
4345

4446
private function afterCreateQuery(AfterCreateQuery $event): void
4547
{
46-
$model = $event->getModel();
48+
$model = $event->model;
4749
$tableName = $model->tableName();
4850

4951
foreach ($this->getPropertyNames() as $propertyName) {
@@ -55,7 +57,7 @@ private function afterCreateQuery(AfterCreateQuery $event): void
5557

5658
private function beforeDelete(BeforeDelete $event): void
5759
{
58-
$model = $event->getModel();
60+
$model = $event->model;
5961
$value = is_callable($this->value) ? ($this->value)($event) : $this->value;
6062

6163
$propertyValues = [];

0 commit comments

Comments
 (0)