for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace XoopsModules\Wggithub\Github\OAuth;
use XoopsModules\Wggithub\Github;
/**
* OAuth token envelope.
*
* @author Miloslav Hůla (https://github.com/milo)
*/
class Token extends Github\Sanity
{
/** @var string */
private $value;
private $type;
/** @var string[] */
private $scopes;
* @param string
* @param string[]
public function __construct($value, $type = '', array $scopes = [])
$this->value = $value;
$this->type = $type;
$this->scopes = $scopes;
}
* @return string
public function getValue()
return $this->value;
public function getType()
return $this->type;
* @return string[]
public function getScopes()
return $this->scopes;
* @see https://developer.github.com/v3/oauth/#scopes
* @return bool
public function hasScope($scope)
if (\in_array($scope, $this->scopes, TRUE)) {
return TRUE;
static $superiors = [
'user:email' => 'user',
'user:follow' => 'user',
'notifications' => 'repo',
];
if (\array_key_exists($scope, $superiors) && \in_array($superiors[$scope], $this->scopes, TRUE)) {
return FALSE;
/** @internal */
public function toArray()
return [
'value' => $this->value,
'type' => $this->type,
'scopes' => $this->scopes,
/** @internal
* @param array $data
* @return Token
public static function createFromArray(array $data)
return new static($data['value'], $data['type'], $data['scopes']);