Skip to content

Commit

Permalink
Merge pull request #211 from koriym/nullable-mixed
Browse files Browse the repository at this point in the history
Fixed to not make mixed nullable
  • Loading branch information
koriym committed May 13, 2024
2 parents da2abe9 + c1ba333 commit 284cec0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/TypeString.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __invoke(?ReflectionType $type): string
if ($type instanceof ReflectionNamedType) {
$typeStr = self::getFqnType($type);
// Check for Nullable in single types
if ($type->allowsNull() && $type->getName() !== 'null') {
if ($typeStr !== 'mixed' && $type->allowsNull() && $type->getName() !== 'null') {
$typeStr = $this->nullableStr . $typeStr;
}

Expand Down
8 changes: 8 additions & 0 deletions tests/CompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,12 @@ public function testNewInstanceWithAnonymousClass(): void
$this->assertInstanceOf(FakeAnonymousClass::class, $mock);
$this->assertInstanceOf(WeavedInterface::class, $mock);
}

/** @requires PHP 8.0 */
public function testMethodWithMixedArgument(): void
{
$mock = $this->compiler->newInstance(FakeMixedParamClass::class, [], $this->bind);
$this->assertInstanceOf(FakeMixedParamClass::class, $mock);
$this->assertInstanceOf(WeavedInterface::class, $mock);
}
}
12 changes: 12 additions & 0 deletions tests/Fake/FakeMixedParamClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Ray\Aop;

class FakeMixedParamClass
{
public function returnSame(mixed $param): void
{
}
}

0 comments on commit 284cec0

Please sign in to comment.