-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update base package version and utilize array accessor trait
- Loading branch information
1 parent
0c8b940
commit 3d734ab
Showing
4 changed files
with
66 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
<?php namespace League\OAuth2\Client\Provider; | ||
|
||
use League\OAuth2\Client\Tool\ArrayAccessorTrait; | ||
|
||
class GithubResourceOwner implements ResourceOwnerInterface | ||
{ | ||
use ArrayAccessorTrait; | ||
|
||
/** | ||
* Domain | ||
* | ||
|
@@ -33,7 +37,7 @@ public function __construct(array $response = array()) | |
*/ | ||
public function getId() | ||
{ | ||
return $this->response['id'] ?: null; | ||
return $this->getValueByKey($this->response, 'id'); | ||
} | ||
|
||
/** | ||
|
@@ -43,7 +47,7 @@ public function getId() | |
*/ | ||
public function getEmail() | ||
{ | ||
return $this->response['email'] ?: null; | ||
return $this->getValueByKey($this->response, 'email'); | ||
} | ||
|
||
/** | ||
|
@@ -53,7 +57,7 @@ public function getEmail() | |
*/ | ||
public function getName() | ||
{ | ||
return $this->response['name'] ?: null; | ||
return $this->getValueByKey($this->response, 'name'); | ||
} | ||
|
||
/** | ||
|
@@ -63,7 +67,7 @@ public function getName() | |
*/ | ||
public function getNickname() | ||
{ | ||
return $this->response['login'] ?: null; | ||
return $this->getValueByKey($this->response, 'login'); | ||
} | ||
|
||
/** | ||
|
@@ -73,7 +77,9 @@ public function getNickname() | |
*/ | ||
public function getUrl() | ||
{ | ||
return trim($this->domain.'/'.$this->getNickname()) ?: null; | ||
$urlParts = array_filter([$this->domain, $this->getNickname()]); | ||
|
||
return count($urlParts) ? implode('/', $urlParts) : null; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
stevenmaguire
Author
Member
|
||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php namespace League\OAuth2\Client\Test\Provider; | ||
|
||
use Mockery as m; | ||
|
||
class GithubResourceOwnerTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testUrlIsNullWithoutDomainOrNickname() | ||
{ | ||
$user = new \League\OAuth2\Client\Provider\GithubResourceOwner; | ||
|
||
$url = $user->getUrl(); | ||
|
||
$this->assertNull($url); | ||
} | ||
|
||
public function testUrlIsDomainWithoutNickname() | ||
{ | ||
$domain = uniqid(); | ||
$user = new \League\OAuth2\Client\Provider\GithubResourceOwner; | ||
$user->setDomain($domain); | ||
|
||
$url = $user->getUrl(); | ||
|
||
$this->assertEquals($domain, $url); | ||
} | ||
|
||
public function testUrlIsNicknameWithoutDomain() | ||
{ | ||
$nickname = uniqid(); | ||
$user = new \League\OAuth2\Client\Provider\GithubResourceOwner(['login' => $nickname]); | ||
|
||
$url = $user->getUrl(); | ||
|
||
$this->assertEquals($nickname, $url); | ||
} | ||
} |
Why
count
? This is effectively the same: