Skip to content

Commit 134698f

Browse files
committed
CodeSniffer style changes
1 parent f57bbb7 commit 134698f

File tree

2 files changed

+33
-22
lines changed

2 files changed

+33
-22
lines changed

src/BYUJWT.php

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ class BYUJWT
3232
public static $wellKnownHost = 'https://api.byu.edu';
3333
public static $useCache = true;
3434
public static $lastException;
35-
protected static $_cache = [];
36-
protected static $_client;
35+
protected static $cache = [];
36+
protected static $client;
3737

3838
const BYU_JWT_HEADER_CURRENT = "X-JWT-Assertion";
3939
const BYU_JWT_HEADER_ORIGINAL = "X-JWT-Assertion-Original";
@@ -48,7 +48,7 @@ public static function reset()
4848
static::$wellKnownHost = 'https://api.byu.edu';
4949
static::$useCache = true;
5050
static::$lastException = null;
51-
static::$_cache = [];
51+
static::$cache = [];
5252
}
5353

5454
/**
@@ -59,11 +59,11 @@ public static function reset()
5959
*/
6060
public static function getWellKnown()
6161
{
62-
if(static::$useCache) {
63-
if (array_key_exists(static::$wellKnownHost, static::$_cache) && array_key_exists('well-known', static::$_cache[static::$wellKnownHost])) {
64-
return static::$_cache[static::$wellKnownHost]['well-known'];
62+
if (static::$useCache) {
63+
if (array_key_exists(static::$wellKnownHost, static::$cache) && array_key_exists('well-known', static::$cache[static::$wellKnownHost])) {
64+
return static::$cache[static::$wellKnownHost]['well-known'];
6565
}
66-
static::$_cache[static::$wellKnownHost]['well-known'] = null;
66+
static::$cache[static::$wellKnownHost]['well-known'] = null;
6767
}
6868

6969
try {
@@ -79,7 +79,7 @@ public static function getWellKnown()
7979
}
8080

8181
if (static::$useCache) {
82-
static::$_cache[static::$wellKnownHost]['well-known'] = $output;
82+
static::$cache[static::$wellKnownHost]['well-known'] = $output;
8383
}
8484

8585
return $output;
@@ -88,6 +88,8 @@ public static function getWellKnown()
8888
/**
8989
* Override the base "well known URL"
9090
*
91+
* @param string $host New well known URL
92+
*
9193
* @return void
9294
*/
9395
public static function setWellKnownHost($host)
@@ -102,11 +104,11 @@ public static function setWellKnownHost($host)
102104
*/
103105
public static function getPublicKey()
104106
{
105-
if(static::$useCache) {
106-
if (array_key_exists(static::$wellKnownHost, static::$_cache) && array_key_exists('public-key', static::$_cache[static::$wellKnownHost])) {
107-
return static::$_cache[static::$wellKnownHost]['public-key'];
107+
if (static::$useCache) {
108+
if (array_key_exists(static::$wellKnownHost, static::$cache) && array_key_exists('public-key', static::$cache[static::$wellKnownHost])) {
109+
return static::$cache[static::$wellKnownHost]['public-key'];
108110
}
109-
static::$_cache[static::$wellKnownHost]['public-key'] = null;
111+
static::$cache[static::$wellKnownHost]['public-key'] = null;
110112
}
111113

112114
$wellKnown = static::getWellKnown();
@@ -133,17 +135,17 @@ public static function getPublicKey()
133135

134136
$key = (string)$X509->getPublicKey();
135137
if (static::$useCache) {
136-
static::$_cache[static::$wellKnownHost]['public-key'] = $key;
138+
static::$cache[static::$wellKnownHost]['public-key'] = $key;
137139
}
138140
return $key;
139141
}
140142

141143
/**
142144
* Check if a JWT is valid
143145
*
144-
* @param string JWT
146+
* @param string $jwt JWT
145147
*
146-
* @return boolean true if $jwt is a valid JWT, false if not
148+
* @return bool true if $jwt is a valid JWT, false if not
147149
*/
148150
public static function validateJWT($jwt)
149151
{
@@ -161,7 +163,7 @@ public static function validateJWT($jwt)
161163
/**
162164
* Decode a JWT
163165
*
164-
* @param string JWT
166+
* @param string $jwt JWT
165167
*
166168
* @return object decoded JWT
167169
*
@@ -170,7 +172,7 @@ public static function validateJWT($jwt)
170172
public static function decode($jwt)
171173
{
172174
$key = static::getPublicKey();
173-
$decodedObject = JWT::decode($jwt, $key, ['HS256','RS256','HS512','HS384']);
175+
$decodedObject = JWT::decode($jwt, $key, ['HS256', 'RS256', 'HS512', 'HS384']);
174176

175177
//JWT::decode returns at stdClass object, but iterating through keys is much
176178
//simpler with an array. So here's a quick Object-to-Array conversion
@@ -182,14 +184,21 @@ public static function decode($jwt)
182184
//For BYU we want to ensure that it does exist, as well as being valid
183185
throw new NoExpirationException('No expiration in JWT');
184186
}
187+
185188
return $decoded;
186189
}
187190

191+
/**
192+
* Simple factory for GuzzleHttp\Client so we only have one instance
193+
*
194+
* @return \GuzzleHttp\Client
195+
*/
188196
protected static function client()
189197
{
190-
if (empty(static::$_client)) {
191-
static::$_client = new Client();
198+
if (empty(static::$client)) {
199+
static::$client = new Client();
192200
}
193-
return static::$_client;
201+
202+
return static::$client;
194203
}
195204
}

tests/BYUJWTTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ final class BYUJWTTest extends TestCase
3838
*
3939
* The location of the credentials can be modified using the WSO2_CRED_LOC env variable
4040
*/
41-
public static function setUpBeforeClass() {
41+
public static function setUpBeforeClass()
42+
{
4243
// Set file location to WSO2_CRED_LOC if exists or to wso2-test-credentials.json
4344
$fileLocation = getenv("WSO2_CRED_LOC") ?: dirname(dirname(__FILE__)) . '/wso2-test-credentials.json';
4445

@@ -66,7 +67,8 @@ public static function setUpBeforeClass() {
6667
static::$validJWT = $echoBody['Headers']["X-Jwt-Assertion"][0];
6768
}
6869

69-
public function setUp() {
70+
public function setUp()
71+
{
7072
BYUJWT::reset();
7173
parent::setUp();
7274
}

0 commit comments

Comments
 (0)