Skip to content

Commit

Permalink
fix: default to non-constant types for config values
Browse files Browse the repository at this point in the history
  • Loading branch information
calebdw committed Aug 5, 2024
1 parent 7df707a commit d9e5110
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Support/ConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function ($key) use ($repository): Type {
return TypeCombinator::union($configType, $defaultType);
}

private function getTypeFromValue(mixed $value, bool $constant = true): Type
private function getTypeFromValue(mixed $value, bool $constant = false): Type
{
// Not using `$scope->getTypeFromValue()` as we don't
// want array values to be constant types given
Expand All @@ -149,8 +149,8 @@ private function getTypeFromValue(mixed $value, bool $constant = true): Type

foreach ($value as $k => $v) {
$arrayBuilder->setOffsetValueType(
$this->getTypeFromValue($k),
$this->getTypeFromValue($v, constant: false),
$this->getTypeFromValue($k, constant: true),
$this->getTypeFromValue($v),
);
}

Expand Down
1 change: 1 addition & 0 deletions tests/Type/data/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ function test(?int $value = 0): void
assertType('Illuminate\Config\Repository', config());
assertType('null', config(['auth.defaults' => 'bar']));
assertType('array{guard: string, passwords: string}|null', config('auth.defaults'));
assertType('string|null', config('auth.defaults.guard'));
assertType("'bar'|array{guard: string, passwords: string}", config('auth.defaults', 'bar'));
$var = 'auth.defaults';
assertType('array{guard: string, passwords: string}|null', config($var));
Expand Down

0 comments on commit d9e5110

Please sign in to comment.