Skip to content

Commit

Permalink
Fix phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvanassche committed Aug 23, 2022
1 parent a48d62e commit b39af45
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
10 changes: 10 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ parameters:
count: 1
path: src/Attributes/Validation/ValidationAttribute.php

-
message: "#^Call to an undefined method DateTimeInterface\\:\\:setTimezone\\(\\)\\.$#"
count: 1
path: src/Casts/DateTimeInterfaceCast.php

-
message: "#^Method Spatie\\\\LaravelData\\\\Data\\:\\:from\\(\\) should return static\\(Spatie\\\\LaravelData\\\\Data\\) but returns Spatie\\\\LaravelData\\\\Contracts\\\\BaseData\\.$#"
count: 1
Expand Down Expand Up @@ -129,3 +134,8 @@ parameters:
message: "#^Match arm comparison between true and false is always false\\.$#"
count: 1
path: src/Support/Validation/RulesMapper.php

-
message: "#^Call to an undefined method DateTimeInterface\\:\\:setTimezone\\(\\)\\.$#"
count: 1
path: src/Transformers/DateTimeInterfaceTransformer.php
2 changes: 1 addition & 1 deletion src/Casts/DateTimeInterfaceCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function cast(DataProperty $property, mixed $value, array $context): Date
throw CannotCastDate::create($formats->toArray(), $type, $value);
}

if ($this->setTimeZone && ($datetime instanceof DateTime || $datetime instanceof DateTimeImmutable)) {
if ($this->setTimeZone) {
return $datetime->setTimezone(new DateTimeZone($this->setTimeZone));
}

Expand Down
3 changes: 1 addition & 2 deletions src/Transformers/DateTimeInterfaceTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public function transform(DataProperty $property, mixed $value): string
[$format] = Arr::wrap($this->format ?? config('data.date_format'));

/** @var \DateTimeInterface $value */

if ($this->setTimeZone && ($value instanceof DateTime || $value instanceof DateTimeImmutable)) {
if ($this->setTimeZone) {
$value = (clone $value)->setTimezone(new DateTimeZone($this->setTimeZone));
}

Expand Down

0 comments on commit b39af45

Please sign in to comment.