Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid instantation of class with type mixed during mapping #60

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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: 3 additions & 1 deletion lib/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ public function dispatch($msg)
// Fallback for php 7.0, which is still supported (and doesn't have nullable).
$class = (string)$paramType;
}
$value = $this->mapper->map($value, new $class());
if ($class !== 'mixed') {
$value = $this->mapper->map($value, new $class());
}
}
} else if (is_array($value) && isset($docBlock)) {
// Get the array type from the DocBlock
Expand Down
8 changes: 8 additions & 0 deletions tests/DispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ public function testCallMethodWithMissingArgument()
$this->assertEquals($this->calls, [new MethodCall('someMethodWithDifferentlyTypedArgs', [0 => null, 1 => 0])]);
}

/*public function testCallMethodWithMixedParam()
{
$result = $this->dispatcher->dispatch((string)new Request(1, 'someMethodWithMixedTypeParam', ['arg' => new Argument('whatever')]));
$this->assertEquals('Hello World', $result);
$this->assertIsObject($this->calls[0]->args[0]);
$this->assertEquals($this->calls, [new MethodCall('someMethodWithMixedTypeParam', [0 => $this->calls[0]->args[0]])]);
}*/

public function testCallMethodWithUnionTypeParamTag()
{
$result = $this->dispatcher->dispatch((string)new Request(1, 'someMethodWithUnionTypeParamTag', ['arg' => [new Argument('whatever')]]));
Expand Down
6 changes: 6 additions & 0 deletions tests/Target.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ public function someMethodWithUnionTypeParamTag($arg)
return 'Hello World';
}

/*public function someMethodWithMixedTypeParam(mixed $arg)
{
$this->calls[] = new MethodCall('someMethodWithMixedTypeParam', func_get_args());
return 'Hello World';
}*/

public function someMethodWithDifferentlyTypedArgs(string $arg1 = null, int $arg2 = null)
{
$this->calls[] = new MethodCall('someMethodWithDifferentlyTypedArgs', func_get_args());
Expand Down