Completed
Push — master ( 9c5d15...436069 )
by smiley
01:51
created
src/Core/OAuth2Interface.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
 
13 13
 namespace chillerlan\OAuth\Core;
14 14
 
15
-interface OAuth2Interface extends OAuthInterface{
15
+interface OAuth2Interface extends OAuthInterface {
16 16
 
17 17
 	const HEADER_OAUTH              = 0;
18 18
 	const HEADER_BEARER             = 1;
Please login to merge, or discard this patch.
src/Core/ClientCredentials.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
 
13 13
 namespace chillerlan\OAuth\Core;
14 14
 
15
-interface ClientCredentials{
15
+interface ClientCredentials {
16 16
 
17 17
 	/**
18 18
 	 * @param array $scopes
Please login to merge, or discard this patch.
src/Core/AccessToken.php 2 patches
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -138,11 +138,9 @@
 block discarded – undo
138 138
 
139 139
 		if($expires === 0 || $expires === $this::EOL_NEVER_EXPIRES){
140 140
 			$this->expires = $this::EOL_NEVER_EXPIRES;
141
-		}
142
-		elseif($expires > $now){
141
+		} elseif($expires > $now){
143 142
 			$this->expires = $expires;
144
-		}
145
-		elseif($expires > 0 && $expires < $this::EXPIRY_MAX){
143
+		} elseif($expires > 0 && $expires < $this::EXPIRY_MAX){
146 144
 			$this->expires = $now + $expires;
147 145
 		}
148 146
 
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
  * @property int    $expires
30 30
  * @property string $provider
31 31
  */
32
-class AccessToken extends SettingsContainerAbstract{
32
+class AccessToken extends SettingsContainerAbstract {
33 33
 
34 34
 	/**
35 35
 	 * Denotes an unknown end of life time.
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 	 *
84 84
 	 * @param iterable|null $properties
85 85
 	 */
86
-	public function __construct(iterable $properties = null){
86
+	public function __construct(iterable $properties = null) {
87 87
 		parent::__construct($properties);
88 88
 
89 89
 		$this->setExpiry($this->expires);
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 	 */
100 100
 	public function __set(string $property, $value):void{
101 101
 
102
-		if(property_exists($this, $property)){
102
+		if (property_exists($this, $property)) {
103 103
 			$property === 'expires'
104 104
 				? $this->setExpiry($value)
105 105
 				: $this->{$property} = $value;
@@ -115,19 +115,19 @@  discard block
 block discarded – undo
115 115
 	public function setExpiry(int $expires = null):AccessToken{
116 116
 		$now = time();
117 117
 
118
-		if($expires!== null){
119
-			$expires =  intval($expires);
118
+		if ($expires !== null) {
119
+			$expires = intval($expires);
120 120
 		}
121 121
 
122 122
 		$this->expires = $this::EOL_UNKNOWN;
123 123
 
124
-		if($expires === 0 || $expires === $this::EOL_NEVER_EXPIRES){
124
+		if ($expires === 0 || $expires === $this::EOL_NEVER_EXPIRES) {
125 125
 			$this->expires = $this::EOL_NEVER_EXPIRES;
126 126
 		}
127
-		elseif($expires > $now){
127
+		elseif ($expires > $now) {
128 128
 			$this->expires = $expires;
129 129
 		}
130
-		elseif($expires > 0 && $expires < $this::EXPIRY_MAX){
130
+		elseif ($expires > 0 && $expires < $this::EXPIRY_MAX) {
131 131
 			$this->expires = $now + $expires;
132 132
 		}
133 133
 
Please login to merge, or discard this patch.
src/Storage/OAuthStorageException.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -14,4 +14,4 @@
 block discarded – undo
14 14
 
15 15
 use chillerlan\OAuth\OAuthException;
16 16
 
17
-class OAuthStorageException extends OAuthException{}
17
+class OAuthStorageException extends OAuthException {}
Please login to merge, or discard this patch.
src/Storage/MemoryStorage.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 
15 15
 use chillerlan\OAuth\Core\AccessToken;
16 16
 
17
-class MemoryStorage extends OAuthStorageAbstract{
17
+class MemoryStorage extends OAuthStorageAbstract {
18 18
 
19 19
 	/**
20 20
 	 * @var array
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 	 */
47 47
 	public function getAccessToken(string $service):AccessToken{
48 48
 
49
-		if($this->hasAccessToken($service)){
49
+		if ($this->hasAccessToken($service)) {
50 50
 			return $this->tokens[$service];
51 51
 		}
52 52
 
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	 */
70 70
 	public function clearAccessToken(string $service):OAuthStorageInterface{
71 71
 
72
-		if(array_key_exists($service, $this->tokens)){
72
+		if (array_key_exists($service, $this->tokens)) {
73 73
 			unset($this->tokens[$service]);
74 74
 		}
75 75
 
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 	 */
82 82
 	public function clearAllAccessTokens():OAuthStorageInterface{
83 83
 
84
-		foreach(array_keys($this->tokens) as $service){
84
+		foreach (array_keys($this->tokens) as $service) {
85 85
 			unset($this->tokens[$service]); // trigger the memzero destructor
86 86
 		}
87 87
 
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	 */
111 111
 	public function getCSRFState(string $service):string{
112 112
 
113
-		if($this->hasCSRFState($service)){
113
+		if ($this->hasCSRFState($service)) {
114 114
 			return $this->states[$service];
115 115
 		}
116 116
 
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 	 */
134 134
 	public function clearCSRFState(string $service):OAuthStorageInterface{
135 135
 
136
-		if(array_key_exists($service, $this->states)){
136
+		if (array_key_exists($service, $this->states)) {
137 137
 			unset($this->states[$service]);
138 138
 		}
139 139
 
Please login to merge, or discard this patch.
src/Storage/SessionStorage.php 2 patches
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -83,8 +83,7 @@  discard block
 block discarded – undo
83 83
 
84 84
 		if(isset($_SESSION[$this->sessionVar]) && is_array($_SESSION[$this->sessionVar])){
85 85
 			$_SESSION[$this->sessionVar][$service] = $token;
86
-		}
87
-		else{
86
+		} else{
88 87
 			$_SESSION[$this->sessionVar] = [$service => $token];
89 88
 		}
90 89
 
@@ -153,8 +152,7 @@  discard block
 block discarded – undo
153 152
 
154 153
 		if(isset($_SESSION[$this->stateVar]) && is_array($_SESSION[$this->stateVar])){
155 154
 			$_SESSION[$this->stateVar][$service] = $state;
156
-		}
157
-		else{
155
+		} else{
158 156
 			$_SESSION[$this->stateVar] = [$service => $state];
159 157
 		}
160 158
 
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 use chillerlan\OAuth\Core\AccessToken;
16 16
 use chillerlan\Settings\SettingsContainerInterface;
17 17
 
18
-class SessionStorage extends OAuthStorageAbstract{
18
+class SessionStorage extends OAuthStorageAbstract {
19 19
 
20 20
 	/**
21 21
 	 * @var bool
@@ -37,21 +37,21 @@  discard block
 block discarded – undo
37 37
 	 *
38 38
 	 * @param \chillerlan\Settings\SettingsContainerInterface|null $options
39 39
 	 */
40
-	public function __construct(SettingsContainerInterface $options = null){
40
+	public function __construct(SettingsContainerInterface $options = null) {
41 41
 		parent::__construct($options);
42 42
 
43 43
 		$this->sessionVar = $this->options->sessionTokenVar;
44 44
 		$this->stateVar = $this->options->sessionStateVar;
45 45
 
46
-		if($this->options->sessionStart && !$this->sessionIsActive()){
46
+		if ($this->options->sessionStart && !$this->sessionIsActive()) {
47 47
 			session_start();
48 48
 		}
49 49
 
50
-		if(!isset($_SESSION[$this->sessionVar])){
50
+		if (!isset($_SESSION[$this->sessionVar])) {
51 51
 			$_SESSION[$this->sessionVar] = [];
52 52
 		}
53 53
 
54
-		if(!isset($_SESSION[$this->stateVar])){
54
+		if (!isset($_SESSION[$this->stateVar])) {
55 55
 			$_SESSION[$this->stateVar] = [];
56 56
 		}
57 57
 
@@ -62,8 +62,8 @@  discard block
 block discarded – undo
62 62
 	 *
63 63
 	 * @codeCoverageIgnore
64 64
 	 */
65
-	public function __destruct(){
66
-		if($this->options->sessionStart){
65
+	public function __destruct() {
66
+		if ($this->options->sessionStart) {
67 67
 			session_write_close();
68 68
 		}
69 69
 	}
@@ -77,10 +77,10 @@  discard block
 block discarded – undo
77 77
 	public function storeAccessToken(string $service, AccessToken $token):OAuthStorageInterface{
78 78
 		$token = $token->toJSON();
79 79
 
80
-		if(isset($_SESSION[$this->sessionVar]) && is_array($_SESSION[$this->sessionVar])){
80
+		if (isset($_SESSION[$this->sessionVar]) && is_array($_SESSION[$this->sessionVar])) {
81 81
 			$_SESSION[$this->sessionVar][$service] = $token;
82 82
 		}
83
-		else{
83
+		else {
84 84
 			$_SESSION[$this->sessionVar] = [$service => $token];
85 85
 		}
86 86
 
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 	 */
96 96
 	public function getAccessToken(string $service):AccessToken{
97 97
 
98
-		if($this->hasAccessToken($service)){
98
+		if ($this->hasAccessToken($service)) {
99 99
 			return (new AccessToken)->fromJSON($_SESSION[$this->sessionVar][$service]);
100 100
 		}
101 101
 
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 	 */
119 119
 	public function clearAccessToken(string $service):OAuthStorageInterface{
120 120
 
121
-		if(array_key_exists($service, $_SESSION[$this->sessionVar])){
121
+		if (array_key_exists($service, $_SESSION[$this->sessionVar])) {
122 122
 			unset($_SESSION[$this->sessionVar][$service]);
123 123
 		}
124 124
 
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 	 */
131 131
 	public function clearAllAccessTokens():OAuthStorageInterface{
132 132
 
133
-		foreach(array_keys($_SESSION[$this->sessionVar]) as $service){
133
+		foreach (array_keys($_SESSION[$this->sessionVar]) as $service) {
134 134
 			unset($_SESSION[$this->sessionVar][$service]); // trigger the memzero destructor
135 135
 		}
136 136
 
@@ -147,10 +147,10 @@  discard block
 block discarded – undo
147 147
 	 */
148 148
 	public function storeCSRFState(string $service, string $state):OAuthStorageInterface{
149 149
 
150
-		if(isset($_SESSION[$this->stateVar]) && is_array($_SESSION[$this->stateVar])){
150
+		if (isset($_SESSION[$this->stateVar]) && is_array($_SESSION[$this->stateVar])) {
151 151
 			$_SESSION[$this->stateVar][$service] = $state;
152 152
 		}
153
-		else{
153
+		else {
154 154
 			$_SESSION[$this->stateVar] = [$service => $state];
155 155
 		}
156 156
 
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 	 */
166 166
 	public function getCSRFState(string $service):string{
167 167
 
168
-		if($this->hasCSRFState($service)){
168
+		if ($this->hasCSRFState($service)) {
169 169
 			return $_SESSION[$this->stateVar][$service];
170 170
 		}
171 171
 
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 	 */
189 189
 	public function clearCSRFState(string $service):OAuthStorageInterface{
190 190
 
191
-		if(array_key_exists($service, $_SESSION[$this->stateVar])){
191
+		if (array_key_exists($service, $_SESSION[$this->stateVar])) {
192 192
 			unset($_SESSION[$this->stateVar][$service]);
193 193
 		}
194 194
 
Please login to merge, or discard this patch.
src/Storage/OAuthStorageInterface.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@
 block discarded – undo
14 14
 
15 15
 use chillerlan\OAuth\Core\AccessToken;
16 16
 
17
-interface OAuthStorageInterface{
17
+interface OAuthStorageInterface {
18 18
 
19 19
 	public const TOKEN_NONCE = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01";
20 20
 
Please login to merge, or discard this patch.
examples/oauth-example-common.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@
 block discarded – undo
35 35
 ];
36 36
 
37 37
 /** @var \chillerlan\Settings\SettingsContainerInterface $options */
38
-$options = new class($options_arr) extends OAuthOptions{
38
+$options = new class($options_arr) extends OAuthOptions {
39 39
 	use LogOptionsTrait;
40 40
 
41 41
 	protected $sleep;
Please login to merge, or discard this patch.
src/Core/OAuth2Provider.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
  * @method array setState(array $params)
21 21
  * @method \chillerlan\OAuth\Core\OAuth2Interface checkState(string $state = null)
22 22
  */
23
-abstract class OAuth2Provider extends OAuthProvider implements OAuth2Interface{
23
+abstract class OAuth2Provider extends OAuthProvider implements OAuth2Interface {
24 24
 
25 25
 	/**
26 26
 	 * @var int
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 	public function getAuthURL(array $params = null, array $scopes = null):UriInterface{
57 57
 		$params = $params ?? [];
58 58
 
59
-		if(isset($params['client_secret'])){
59
+		if (isset($params['client_secret'])) {
60 60
 			unset($params['client_secret']);
61 61
 		}
62 62
 
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 			'type'          => 'web_server',
69 69
 		]);
70 70
 
71
-		if($this instanceof CSRFToken){
71
+		if ($this instanceof CSRFToken) {
72 72
 			$params = $this->setState($params);
73 73
 		}
74 74
 
@@ -84,19 +84,19 @@  discard block
 block discarded – undo
84 84
 	protected function parseTokenResponse(ResponseInterface $response):AccessToken{
85 85
 		$data = json_decode($response->getBody()->getContents(), true);
86 86
 
87
-		if(!is_array($data)){
87
+		if (!is_array($data)) {
88 88
 			throw new ProviderException('unable to parse token response');
89 89
 		}
90 90
 
91
-		foreach(['error_description', 'error'] as $field){
91
+		foreach (['error_description', 'error'] as $field) {
92 92
 
93
-			if(isset($data[$field])){
93
+			if (isset($data[$field])) {
94 94
 				throw new ProviderException('error retrieving access token: "'.$data[$field].'"');
95 95
 			}
96 96
 
97 97
 		}
98 98
 
99
-		if(!isset($data['access_token'])){
99
+		if (!isset($data['access_token'])) {
100 100
 			throw new ProviderException('token missing');
101 101
 		}
102 102
 
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 	 */
123 123
 	public function getAccessToken(string $code, string $state = null):AccessToken{
124 124
 
125
-		if($this instanceof CSRFToken){
125
+		if ($this instanceof CSRFToken) {
126 126
 			$this->checkState($state);
127 127
 		}
128 128
 
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
 			->withHeader('Content-Type', 'application/x-www-form-urlencoded')
140 140
 			->withBody($this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738)));
141 141
 
142
-		foreach($this->authHeaders as $header => $value){
142
+		foreach ($this->authHeaders as $header => $value) {
143 143
 			$request = $request->withHeader($header, $value);
144 144
 		}
145 145
 
@@ -159,15 +159,15 @@  discard block
 block discarded – undo
159 159
 	 */
160 160
 	public function getRequestAuthorization(RequestInterface $request, AccessToken $token):RequestInterface{
161 161
 
162
-		if(array_key_exists($this->authMethod, $this::AUTH_METHODS_HEADER)){
162
+		if (array_key_exists($this->authMethod, $this::AUTH_METHODS_HEADER)) {
163 163
 			$request = $request->withHeader('Authorization', $this::AUTH_METHODS_HEADER[$this->authMethod].$token->accessToken);
164 164
 		}
165
-		elseif(array_key_exists($this->authMethod, $this::AUTH_METHODS_QUERY)){
165
+		elseif (array_key_exists($this->authMethod, $this::AUTH_METHODS_QUERY)) {
166 166
 			$uri = Psr7\merge_query((string)$request->getUri(), [$this::AUTH_METHODS_QUERY[$this->authMethod] => $token->accessToken]);
167 167
 
168 168
 			$request = $request->withUri($this->uriFactory->createUri($uri));
169 169
 		}
170
-		else{
170
+		else {
171 171
 			throw new ProviderException('invalid auth type');
172 172
 		}
173 173
 
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -161,13 +161,11 @@
 block discarded – undo
161 161
 
162 162
 		if(array_key_exists($this->authMethod, $this::AUTH_METHODS_HEADER)){
163 163
 			$request = $request->withHeader('Authorization', $this::AUTH_METHODS_HEADER[$this->authMethod].$token->accessToken);
164
-		}
165
-		elseif(array_key_exists($this->authMethod, $this::AUTH_METHODS_QUERY)){
164
+		} elseif(array_key_exists($this->authMethod, $this::AUTH_METHODS_QUERY)){
166 165
 			$uri = Psr7\merge_query((string)$request->getUri(), [$this::AUTH_METHODS_QUERY[$this->authMethod] => $token->accessToken]);
167 166
 
168 167
 			$request = $request->withUri($this->uriFactory->createUri($uri));
169
-		}
170
-		else{
168
+		} else{
171 169
 			throw new ProviderException('invalid auth type');
172 170
 		}
173 171
 
Please login to merge, or discard this patch.