Skip to content

Commit

Permalink
fix: fixes mixed types being stubbed as mixed|null
Browse files Browse the repository at this point in the history
  • Loading branch information
ju1ius committed Jan 10, 2024
1 parent 86427a1 commit a0aef67
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions mocks/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use ArrayAccess;
use Traversable;

function mixed_arg(mixed $arg): void {}
function nullable_arg(?string $arg): void {}
function variadic_arg(string ...$arg): void {}
function default_arg(string $arg = 'foo'): void {}
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/AstBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ private function buildType(ReflectionType $type): string
default => $this->resolveName($name),
},
};
if ($type->allowsNull() && $name !== 'null') {
if ($type->allowsNull() && !\in_array($name, ['mixed', 'null'])) {
return "{$name}|null";
}
return $name;
Expand Down
7 changes: 7 additions & 0 deletions tests/Generator/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use function Souplette\Chicot\Mocks\default_arg;
use function Souplette\Chicot\Mocks\dnf_arg;
use function Souplette\Chicot\Mocks\intersection_arg;
use function Souplette\Chicot\Mocks\mixed_arg;
use function Souplette\Chicot\Mocks\nullable_arg;
use function Souplette\Chicot\Mocks\union_arg;
use function Souplette\Chicot\Mocks\variadic_arg;
Expand All @@ -27,6 +28,12 @@ public function testFunctions(callable $fn, string $expected): void

public static function functionsProvider(): iterable
{
yield 'mixed arg' => [
mixed_arg(...),
<<<'PHP'
function mixed_arg(mixed $arg) : void {}
PHP,
];
yield 'nullable arg' => [
nullable_arg(...),
<<<'PHP'
Expand Down

0 comments on commit a0aef67

Please sign in to comment.