Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ parameters:
# false positive
- '#Parameter \#1 \$value of static method PhpParser\\BuilderHelpers\:\:normalizeValue\(\) expects array\|bool\|float\|int\|PhpParser\\Node\\Expr\|string\|UnitEnum\|null, mixed given#'

-
path: src/Rector/Class_/UnifyModelDatesWithCastsRector.php
message: '#Parameter \#1 \$array of function array_keys expects array, mixed given#'

# rector co-variant
- '#Parameter \#1 \$node (.*?) of method RectorLaravel\\(.*?)\:\:(refactor|refactorWithScope)\(\) should be contravariant with parameter \$node \(PhpParser\\Node\) of method Rector\\Contract\\Rector\\RectorInterface\:\:refactor\(\)#'

Expand Down
19 changes: 18 additions & 1 deletion src/Rector/Class_/UnifyModelDatesWithCastsRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Webmozart\Assert\Assert;
use Webmozart\Assert\InvalidArgumentException;

/**
* @changelog https://github.com/laravel/framework/pull/32856
Expand Down Expand Up @@ -93,11 +94,18 @@ public function refactor(Node $node): ?Node
return null;
}

/** @var mixed[] $dates */
$dates = $this->valueResolver->getValue($datesPropertyProperty->default);
if (! is_array($dates)) {
return null;
}

try {
Assert::allString($dates);
} catch (InvalidArgumentException) {
return null;
}

if ($dates === []) {
return null;
}
Expand All @@ -115,10 +123,19 @@ public function refactor(Node $node): ?Node
return null;
}

/** @var array<string, mixed> $casts */
$casts = $this->valueResolver->getValue($castsPropertyProperty->default);
if (! is_array($casts)) {
return null;
}

// exclude attributes added in $casts
$missingDates = array_diff($dates, array_keys($casts));
Assert::allString($missingDates);
try {
Assert::allString($missingDates);
} catch (InvalidArgumentException) {
return null;
}

foreach ($missingDates as $missingDate) {
$castsPropertyProperty->default->items[] = new ArrayItem(
Expand Down
Loading