Optimized code.

This commit is contained in:
李铭昕 2019-09-27 13:21:13 +08:00
parent 61c25b4a69
commit 209993efd4
4 changed files with 11 additions and 2 deletions

View File

@ -76,6 +76,7 @@ Now:
## Fixed
- [#448](https://github.com/hyperf-cloud/hyperf/pull/448) Fixed TCP Server does not works when HTTP Server or WebSocket Server exists.
- [#623](https://github.com/hyperf-cloud/hyperf/pull/623) Fixed `null` is replaced by default value.
# v1.0.16 - TBD

View File

@ -43,10 +43,10 @@ trait ProxyTrait
];
$reflectMethod = ReflectionManager::reflectMethod($className, $method);
$reflectParameters = $reflectMethod->getParameters();
foreach ($reflectParameters as $key => $reflectionParameter) {
$leftCount = count($args);
foreach ($reflectParameters as $key => $reflectionParameter) {
$arg = $reflectionParameter->isVariadic() ? $args : array_shift($args);
if (! isset($arg) && $leftCount === 0) {
if (! isset($arg) && $leftCount-- <= 0) {
$arg = $reflectionParameter->getDefaultValue();
}
$map['keys'][$reflectionParameter->getName()] = $arg;

View File

@ -33,5 +33,8 @@ class ProxyTraitTest extends TestCase
$this->assertEquals(['id' => null, 'str' => ''], $obj->get2(null)['keys']);
$this->assertEquals(['id', 'str'], $obj->get2(null)['order']);
$this->assertEquals(['id' => 1, 'str' => '', 'num' => 1.0], $obj->get3()['keys']);
$this->assertEquals(['id', 'str', 'num'], $obj->get3()['order']);
}
}

View File

@ -27,4 +27,9 @@ class ProxyTraitObject
{
return $this->getParamsMap(static::class, 'get2', func_get_args());
}
public function get3(?int $id = 1, string $str = '', float $num = 1.0)
{
return $this->getParamsMap(static::class, 'get3', func_get_args());
}
}