From 3152ea7741aa64377e9ce83861c1e09412009c1c Mon Sep 17 00:00:00 2001 From: polidog Date: Tue, 6 Dec 2016 01:36:14 +0900 Subject: [PATCH] =?UTF-8?q?ResourceOwner=E3=81=A7=E3=82=88=E3=82=8A?= =?UTF-8?q?=E5=A4=9A=E3=81=8F=E3=81=AE=E6=83=85=E5=A0=B1=E3=82=92=E5=8F=96?= =?UTF-8?q?=E3=82=8C=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/YConnectResourceOwner.php | 28 ++++++++++++++++++---- test/src/YConnectResourceOwnerTest.php | 33 ++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 test/src/YConnectResourceOwnerTest.php 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