diff --git a/src/ClientTrait.php b/src/ClientTrait.php index 5bf1043ac46e..e2f9e63b5256 100644 --- a/src/ClientTrait.php +++ b/src/ClientTrait.php @@ -62,8 +62,6 @@ private function getConnectionType(array $config) 'composer require google/proto-client-php' ); } - - return $transport; } return $transport; diff --git a/src/GrpcTrait.php b/src/GrpcTrait.php index 4b780434a160..19e47f5f9f5b 100644 --- a/src/GrpcTrait.php +++ b/src/GrpcTrait.php @@ -60,14 +60,20 @@ public function send(callable $request, array $args) /** * Pluck a value out of an array. * - * @param string $name + * @param string $key * @param array $args * @return string */ - public function pluck($name, array &$args) + public function pluck($key, array &$args) { - $value = $args[$name]; - unset($args[$name]); + if (!isset($args[$key])) { + throw new \InvalidArgumentException( + "Key $key does not exist in the provided array." + ); + } + + $value = $args[$key]; + unset($args[$key]); return $value; } } diff --git a/tests/GrpcTraitTest.php b/tests/GrpcTraitTest.php index a87951ab4356..35593229cfe0 100644 --- a/tests/GrpcTraitTest.php +++ b/tests/GrpcTraitTest.php @@ -69,4 +69,13 @@ public function testPluck() $this->assertEquals($value, $actualValue); $this->assertEquals([], $array); } + + /** + * @expectedException \InvalidArgumentException + */ + public function testPluckThrowsExceptionWithInvalidKey() + { + $array = []; + $actualValue = $this->implementation->pluck('not_here', $array); + } }