Skip to content

Commit

Permalink
Merge pull request #437 from GrahamCampbell/patch-1
Browse files Browse the repository at this point in the history
Use the laravel preset, nearly
  • Loading branch information
tymondesigns committed Jan 27, 2016
2 parents eda599a + 25011a4 commit 676fa41
Show file tree
Hide file tree
Showing 17 changed files with 52 additions and 67 deletions.
22 changes: 6 additions & 16 deletions .styleci.yml
@@ -1,22 +1,12 @@
preset: psr2
preset: laravel

enabled:
- duplicate_semicolon
- extra_empty_lines
- logical_not_operators_with_successor_space
- phpdoc_scalar
- return
- short_array_syntax
- single_quote
- spaces_cast
- standardize_not_equal
- ternary_spaces
- trim_array_spaces
- concat_with_spaces
- unalign_double_arrow
- unalign_equals
- unneeded_control_parentheses
- unused_use
- whitespacy_lines

disabled:
- concat_without_spaces
- phpdoc_short_description

linting: true

Expand Down
2 changes: 1 addition & 1 deletion src/Claims/Factory.php
Expand Up @@ -23,7 +23,7 @@ class Factory
'iss' => Issuer::class,
'jti' => JwtId::class,
'nbf' => NotBefore::class,
'sub' => Subject::class
'sub' => Subject::class,
];

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/JWTGenerateSecretCommand.php
Expand Up @@ -57,7 +57,7 @@ public function fire()

if ($confirmed) {
file_put_contents($path, str_replace(
'JWT_SECRET='.$this->laravel['config']['jwt.secret'], 'JWT_SECRET='.$key, file_get_contents($path)
'JWT_SECRET=' . $this->laravel['config']['jwt.secret'], 'JWT_SECRET=' . $key, file_get_contents($path)
));
} else {
return $this->comment('Phew... No changes were made to your secret key.');
Expand Down
2 changes: 1 addition & 1 deletion src/Http/AuthHeaders.php
Expand Up @@ -57,7 +57,7 @@ public function parse(Request $request)
$header = $request->headers->get($this->header, $this->fromAltHeaders($request));

if (! $header || ! Str::startsWith(strtolower($header), $this->prefix)) {
return null;
return;
}

return trim(str_ireplace($this->prefix, '', $header));
Expand Down
4 changes: 2 additions & 2 deletions src/Http/LumenRouteParams.php
Expand Up @@ -28,10 +28,10 @@ public function parse(Request $request)
// It will only work with poorly-specified aspects of certain Lumen releases.
$route = $request->route();

if (! is_array($route) || ! array_has($route, '2.'.$this->key)) {
if (! is_array($route) || ! array_has($route, '2.' . $this->key)) {
// Route is not the expected kind of array, or does not have a parameter
// with the key we want.
return null;
return;
}

return $route[2][$this->key];
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Parser.php
Expand Up @@ -87,7 +87,7 @@ public function parseToken()
}
}

return null;
return;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Http/RouteParams.php
Expand Up @@ -37,7 +37,7 @@ public function parse(Request $request)
if (! is_callable([$route, 'parameter'])) {
// Route may not be an instance of Illuminate\Routing\Route (it's an array
// in Lumen <5.2) or not exist at all (if the request was never dispatched)
return null;
return;
}

return $route->parameter($this->key);
Expand Down
4 changes: 1 addition & 3 deletions src/JWTGuard.php
Expand Up @@ -68,7 +68,7 @@ public function user()
}

if (! $this->requireToken()->check()) {
return null;
return;
}

$id = $this->jwt->getPayload()->get('sub');
Expand Down Expand Up @@ -149,8 +149,6 @@ public function tokenById($id)
if (! is_null($user = $this->provider->retrieveById($id))) {
return $this->jwt->fromUser($user);
}

return null;
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/Validators/PayloadValidator.php
Expand Up @@ -17,8 +17,6 @@

/**
* Class PayloadValidator
*
* @package Tymon\JWTAuth\Validators
*/
class PayloadValidator extends Validator
{
Expand Down
16 changes: 8 additions & 8 deletions tests/BlacklistTest.php
Expand Up @@ -66,7 +66,7 @@ public function it_should_add_a_valid_token_to_the_blacklist()
'exp' => new Expiration(123 + 3600),
'nbf' => new NotBefore(123),
'iat' => new IssuedAt(123),
'jti' => new JwtId('foo')
'jti' => new JwtId('foo'),
];
$payload = new Payload(Collection::make($claims), $this->validator);

Expand All @@ -82,7 +82,7 @@ public function it_should_add_a_token_with_no_exp_to_the_blacklist_forever()
'iss' => new Issuer('http://example.com'),
'nbf' => new NotBefore(123),
'iat' => new IssuedAt(123),
'jti' => new JwtId('foo')
'jti' => new JwtId('foo'),
];
$payload = new Payload(Collection::make($claims), $this->validator);

Expand All @@ -99,7 +99,7 @@ public function it_should_return_true_when_adding_an_expired_token_to_the_blackl
'exp' => new Expiration(123 - 3600),
'nbf' => new NotBefore(123),
'iat' => new IssuedAt(123),
'jti' => new JwtId('foo')
'jti' => new JwtId('foo'),
];
$payload = new Payload(Collection::make($claims), $this->validator, true);

Expand All @@ -116,7 +116,7 @@ public function it_should_check_whether_a_token_has_been_blacklisted()
'exp' => new Expiration(123 + 3600),
'nbf' => new NotBefore(123),
'iat' => new IssuedAt(123),
'jti' => new JwtId('foobar')
'jti' => new JwtId('foobar'),
];
$payload = new Payload(Collection::make($claims), $this->validator);

Expand All @@ -134,7 +134,7 @@ public function it_should_check_whether_a_token_has_been_blacklisted_forever()
'exp' => new Expiration(123 + 3600),
'nbf' => new NotBefore(123),
'iat' => new IssuedAt(123),
'jti' => new JwtId('foobar')
'jti' => new JwtId('foobar'),
];
$payload = new Payload(Collection::make($claims), $this->validator);

Expand All @@ -152,7 +152,7 @@ public function it_should_check_whether_a_token_has_been_blacklisted_when_the_to
'exp' => new Expiration(123 + 3600),
'nbf' => new NotBefore(123),
'iat' => new IssuedAt(123),
'jti' => new JwtId('foobar')
'jti' => new JwtId('foobar'),
];
$payload = new Payload(Collection::make($claims), $this->validator);

Expand All @@ -170,7 +170,7 @@ public function it_should_remove_a_token_from_the_blacklist()
'exp' => new Expiration(123 + 3600),
'nbf' => new NotBefore(123),
'iat' => new IssuedAt(123),
'jti' => new JwtId('foobar')
'jti' => new JwtId('foobar'),
];
$payload = new Payload(Collection::make($claims), $this->validator);

Expand All @@ -187,7 +187,7 @@ public function it_should_set_a_custom_unique_key_for_the_blacklist()
'exp' => new Expiration(123 + 3600),
'nbf' => new NotBefore(123),
'iat' => new IssuedAt(123),
'jti' => new JwtId('foobar')
'jti' => new JwtId('foobar'),
];
$payload = new Payload(Collection::make($claims), $this->validator);

Expand Down
24 changes: 12 additions & 12 deletions tests/Http/ParserTest.php
Expand Up @@ -32,7 +32,7 @@ public function it_should_return_the_token_from_the_authorization_header()
$parser->setChainOrder([
new QueryString,
new AuthHeaders,
new RouteParams
new RouteParams,
]);

$this->assertSame($parser->parseToken(), 'foobar');
Expand All @@ -51,7 +51,7 @@ public function it_should_return_the_token_from_the_alt_authorization_headers()
$parser = new Parser($request1, [
new AuthHeaders,
new QueryString,
new RouteParams
new RouteParams,
]);

$this->assertSame($parser->parseToken(), 'foobar');
Expand All @@ -71,7 +71,7 @@ public function it_should_return_the_token_from_query_string()
$parser->setChainOrder([
new AuthHeaders,
new QueryString,
new RouteParams
new RouteParams,
]);

$this->assertSame($parser->parseToken(), 'foobar');
Expand All @@ -90,7 +90,7 @@ public function it_should_return_the_token_from_route()
$parser->setChainOrder([
new AuthHeaders,
new QueryString,
new RouteParams
new RouteParams,
]);

$this->assertSame($parser->parseToken(), 'foobar');
Expand All @@ -102,14 +102,14 @@ public function it_should_ignore_routeless_requests()
{
$request = Request::create('foo', 'GET', ['foo' => 'bar']);
$request->setRouteResolver(function () {
return null;
return;
});

$parser = new Parser($request);
$parser->setChainOrder([
new AuthHeaders,
new QueryString,
new RouteParams
new RouteParams,
]);

$this->assertNull($parser->parseToken());
Expand All @@ -121,14 +121,14 @@ public function it_should_ignore_lumen_request_arrays()
{
$request = Request::create('foo', 'GET', ['foo' => 'bar']);
$request->setRouteResolver(function () {
return [false, ['uses'=>'someController'], ['token'=>'foobar']];
return [false, ['uses' => 'someController'], ['token' => 'foobar']];
});

$parser = new Parser($request);
$parser->setChainOrder([
new AuthHeaders,
new QueryString,
new RouteParams
new RouteParams,
]);

$this->assertNull($parser->parseToken());
Expand All @@ -140,14 +140,14 @@ public function it_should_accept_lumen_request_arrays_with_special_class()
{
$request = Request::create('foo', 'GET', ['foo' => 'bar']);
$request->setRouteResolver(function () {
return [false, ['uses'=>'someController'], ['token'=>'foobar']];
return [false, ['uses' => 'someController'], ['token' => 'foobar']];
});

$parser = new Parser($request);
$parser->setChainOrder([
new AuthHeaders,
new QueryString,
new LumenRouteParams
new LumenRouteParams,
]);

$this->assertSame($parser->parseToken(), 'foobar');
Expand All @@ -166,7 +166,7 @@ public function it_should_return_null_if_no_token_in_request()
$parser->setChainOrder([
new AuthHeaders,
new QueryString,
new RouteParams
new RouteParams,
]);

$this->assertNull($parser->parseToken());
Expand All @@ -179,7 +179,7 @@ public function it_should_retrieve_the_chain()
$chain = [
new AuthHeaders,
new QueryString,
new RouteParams
new RouteParams,
];

$parser = new Parser(Mockery::mock('Illuminate\Http\Request'));
Expand Down
12 changes: 6 additions & 6 deletions tests/ManagerTest.php
Expand Up @@ -75,7 +75,7 @@ public function it_should_encode_a_payload()
new Expiration(123 + 3600),
new NotBefore(123),
new IssuedAt(123),
new JwtId('foo')
new JwtId('foo'),
];
$payload = new Payload(Collection::make($claims), $this->validator);

Expand All @@ -95,7 +95,7 @@ public function it_should_decode_a_token()
new Expiration(123 + 3600),
new NotBefore(123),
new IssuedAt(123),
new JwtId('foo')
new JwtId('foo'),
];
$payload = new Payload(Collection::make($claims), $this->validator);
$token = new Token('foo.bar.baz');
Expand Down Expand Up @@ -125,7 +125,7 @@ public function it_should_throw_exception_when_token_is_blacklisted()
new Expiration(123 + 3600),
new NotBefore(123),
new IssuedAt(123),
new JwtId('foo')
new JwtId('foo'),
];
$payload = new Payload(Collection::make($claims), $this->validator);
$token = new Token('foo.bar.baz');
Expand All @@ -150,7 +150,7 @@ public function it_should_refresh_a_token()
new Expiration(123 - 3600),
new NotBefore(123),
new IssuedAt(123),
new JwtId('foo')
new JwtId('foo'),
];
$payload = new Payload(Collection::make($claims), $this->validator, true);
$token = new Token('foo.bar.baz');
Expand Down Expand Up @@ -181,7 +181,7 @@ public function it_should_invalidate_a_token()
new Expiration(123 + 3600),
new NotBefore(123),
new IssuedAt(123),
new JwtId('foo')
new JwtId('foo'),
];
$payload = new Payload(Collection::make($claims), $this->validator);
$token = new Token('foo.bar.baz');
Expand All @@ -208,7 +208,7 @@ public function it_should_force_invalidate_a_token_forever()
new Expiration(123 + 3600),
new NotBefore(123),
new IssuedAt(123),
new JwtId('foo')
new JwtId('foo'),
];
$payload = new Payload(Collection::make($claims), $this->validator);
$token = new Token('foo.bar.baz');
Expand Down
1 change: 0 additions & 1 deletion tests/Middleware/RefreshTokenTest.php
Expand Up @@ -26,7 +26,6 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
/**
* @var \Mockery\MockInterface
*/

protected $request;
/**
* @var \Tymon\JWTAuth\Middleware\RefreshToken
Expand Down
2 changes: 1 addition & 1 deletion tests/PayloadTest.php
Expand Up @@ -42,7 +42,7 @@ public function setUp()
'exp' => new Expiration(time() + 3600),
'nbf' => new NotBefore(time()),
'iat' => new IssuedAt(time()),
'jti' => new JwtId('foo')
'jti' => new JwtId('foo'),
];

$this->validator = Mockery::mock('Tymon\JWTAuth\Validators\PayloadValidator');
Expand Down
2 changes: 1 addition & 1 deletion tests/Providers/Storage/IlluminateTest.php
Expand Up @@ -102,7 +102,7 @@ private function emulateTags()
$this->cache->shouldReceive('tags')->with('tymon.jwt')->once()->andReturn(Mockery::self());
}

/** @test */
/** @test */
public function it_should_add_the_item_to_tagged_storage()
{
$this->emulateTags();
Expand Down
2 changes: 1 addition & 1 deletion tests/Stubs/UserStub.php
Expand Up @@ -24,7 +24,7 @@ public function getJWTCustomClaims()
{
return [
'foo' => 'bar',
'role' => 'admin'
'role' => 'admin',
];
}
}

0 comments on commit 676fa41

Please sign in to comment.