Skip to content

Commit

Permalink
Update base package version and utilize array accessor trait
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenmaguire committed Nov 22, 2016
1 parent 0c8b940 commit 3d734ab
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 6 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
# Changelog
All Notable changes to `oauth2-github` will be documented in this file

## 0.2.2 - 2016-11-21

### Added
- Update base package version from 1.0 to 1.4
- Update GithubResourceOwner to utilize ArrayAccessorTrait from base package

### Deprecated
- Nothing

### Fixed
- Nothing

### Removed
- Nothing

### Security
- Nothing

## 0.2.1 - 2016-04-13

### Added
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
],
"require": {
"php": ">=5.5.0",
"league/oauth2-client": "~1.0"
"league/oauth2-client": "~1.4"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
Expand Down
16 changes: 11 additions & 5 deletions src/Provider/GithubResourceOwner.php
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
*
Expand Down Expand Up @@ -33,7 +37,7 @@ public function __construct(array $response = array())
*/
public function getId()
{
return $this->response['id'] ?: null;
return $this->getValueByKey($this->response, 'id');
}

/**
Expand All @@ -43,7 +47,7 @@ public function getId()
*/
public function getEmail()
{
return $this->response['email'] ?: null;
return $this->getValueByKey($this->response, 'email');
}

/**
Expand All @@ -53,7 +57,7 @@ public function getEmail()
*/
public function getName()
{
return $this->response['name'] ?: null;
return $this->getValueByKey($this->response, 'name');
}

/**
Expand All @@ -63,7 +67,7 @@ public function getName()
*/
public function getNickname()
{
return $this->response['login'] ?: null;
return $this->getValueByKey($this->response, 'login');
}

/**
Expand All @@ -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.

Copy link
@shadowhand

shadowhand Nov 22, 2016

Member

Why count? This is effectively the same:

return $urlParts ? ...;

This comment has been minimized.

Copy link
@stevenmaguire

stevenmaguire Nov 22, 2016

Author Member

Because I've been writing too much ruby and python lately and it's late :)

}

/**
Expand Down
36 changes: 36 additions & 0 deletions test/src/Provider/GithubResourceOwnerTest.php
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);
}
}

0 comments on commit 3d734ab

Please sign in to comment.