Skip to content

Commit

Permalink
Attribute::make instead of construct
Browse files Browse the repository at this point in the history
  • Loading branch information
antonkomarev committed Mar 9, 2024
1 parent 8e0e4bd commit ed67faa
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Reactant/Models/Reactant.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ final class Reactant extends Model implements

public function id(): Attribute
{
return new Attribute(
return Attribute::make(
get: fn (string | null $value) => $value,
set: fn (string | null $value) => $value,
);
Expand Down
4 changes: 2 additions & 2 deletions src/Reactant/ReactionCounter/Models/ReactionCounter.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ final class ReactionCounter extends Model implements

public function count(): Attribute
{
return new Attribute(
return Attribute::make(
get: fn (int | null $value) => $value ?? self::COUNT_DEFAULT,
set: fn (int | null $value) => $value ?? self::COUNT_DEFAULT,
);
}

public function weight(): Attribute
{
return new Attribute(
return Attribute::make(
get: fn (float | null $value) => $value ?? self::WEIGHT_DEFAULT,
set: fn (float | null $value) => $value ?? self::WEIGHT_DEFAULT,
);
Expand Down
4 changes: 2 additions & 2 deletions src/Reactant/ReactionTotal/Models/ReactionTotal.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ final class ReactionTotal extends Model implements

public function count(): Attribute
{
return new Attribute(
return Attribute::make(
get: fn (int | null $value) => $value ?? self::COUNT_DEFAULT,
set: fn (int | null $value) => $value ?? self::COUNT_DEFAULT,
);
}

public function weight(): Attribute
{
return new Attribute(
return Attribute::make(
get: fn (float | null $value) => $value ?? self::WEIGHT_DEFAULT,
set: fn (float | null $value) => $value ?? self::WEIGHT_DEFAULT,
);
Expand Down
2 changes: 1 addition & 1 deletion src/Reacter/Models/Reacter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ final class Reacter extends Model implements

public function id(): Attribute
{
return new Attribute(
return Attribute::make(
get: fn (string | null $value) => $value,
set: fn (string | null $value) => $value,
);
Expand Down
4 changes: 2 additions & 2 deletions src/Reaction/Models/Reaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ final class Reaction extends Model implements

public function id(): Attribute
{
return new Attribute(
return Attribute::make(
get: fn (string | null $value) => $value,
set: fn (string | null $value) => $value,
);
}

public function rate(): Attribute
{
return new Attribute(
return Attribute::make(
get: fn (float | null $value) => $value ?? self::RATE_DEFAULT,
set: function (float | null $value) {
if ($value !== null && ($value < self::RATE_MIN || $value > self::RATE_MAX)) {
Expand Down
4 changes: 2 additions & 2 deletions src/ReactionType/Models/ReactionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ final class ReactionType extends Model implements

public function id(): Attribute
{
return new Attribute(
return Attribute::make(
get: fn (string | null $value) => $value,
set: fn (string | null $value) => $value,
);
}

public function mass(): Attribute
{
return new Attribute(
return Attribute::make(
get: fn (int | null $value) => $value ?? self::MASS_DEFAULT,
set: fn (int | null $value) => $value ?? self::MASS_DEFAULT,
);
Expand Down

0 comments on commit ed67faa

Please sign in to comment.