diff --git a/src/YConnectResourceOwner.php b/src/YConnectResourceOwner.php index 201dd9e..de0d4b1 100644 --- a/src/YConnectResourceOwner.php +++ b/src/YConnectResourceOwner.php @@ -26,27 +26,47 @@ public function __construct(array $response = []) $this->response = $response; } + public function __call($name, $arguments) + { + $get = substr($name,0, 3); + if ($get !== 'get') { + return null; + } + $parameter = function($name) { + return ltrim(strtolower(preg_replace('/[A-Z]/', '_\0', str_replace("get", "", $name))), '_'); + }; + return $this->getResource($parameter($name)); + } + public function getId() { - return $this->response['user_id'] ?: null; + return $this->getResource('user_id'); } public function getName() { - return $this->response['name'] ?: null; + return $this->getResource('name'); } public function getEmail() { - return $this->response['email'] ?: null; + return $this->getResource('email'); } - + public function getAddress() + { + return $this->getResource('address'); + } public function toArray() { return $this->response; } + protected function getResource($name) + { + return isset($this->response[$name]) ? $this->response[$name] : null; + } + } \ No newline at end of file diff --git a/test/src/YConnectResourceOwnerTest.php b/test/src/YConnectResourceOwnerTest.php new file mode 100644 index 0000000..2f51e4b --- /dev/null +++ b/test/src/YConnectResourceOwnerTest.php @@ -0,0 +1,33 @@ + 'polidog']); + $actual = $resource->getGivenName(); + $this->assertEquals('polidog', $actual); + } + + /** + * @test + */ + public function notExistUserId() + { + $resource = new YConnectResourceOwner([]); + $this->assertNull($resource->getId()); + } +} \ No newline at end of file