From dcb74b4740b02391d3562d6bdba94da54ee7217c Mon Sep 17 00:00:00 2001 From: Zak Henry Date: Wed, 16 Dec 2015 19:49:40 -0500 Subject: [PATCH] Applied fixes from StyleCI --- api/app/Console/Commands/CreateUserCommand.php | 4 ++-- api/app/Models/User.php | 2 +- api/app/Providers/AuthDriverServiceProvider.php | 8 ++++---- .../Auth/Providers/JWTAuthDriverServiceProvider.php | 10 +++++----- api/src/Rbac/Access/Gate.php | 2 +- api/tests/Auth/PayloadFactoryTest.php | 2 +- api/tests/Auth/PayloadValidatorFactoryTest.php | 8 ++++---- api/tests/CommandTest.php | 10 +++------- api/tests/integration/AuthTest.php | 4 ++-- 9 files changed, 23 insertions(+), 27 deletions(-) diff --git a/api/app/Console/Commands/CreateUserCommand.php b/api/app/Console/Commands/CreateUserCommand.php index bba3926d..f8afe5ff 100644 --- a/api/app/Console/Commands/CreateUserCommand.php +++ b/api/app/Console/Commands/CreateUserCommand.php @@ -60,7 +60,7 @@ public function handle() $validator = Validator::make($userData, $validationRules); if ($validator->fails()) { - $this->error("Validation failed:"); + $this->error('Validation failed:'); // @codeCoverageIgnoreStart if (env('APP_ENV') != 'testing') { (new Dumper)->dump($validator->errors()->toArray()); @@ -76,7 +76,7 @@ public function handle() $user->setCredential(new UserCredential(['password' => $password])); - $this->info("Successfully created user:"); + $this->info('Successfully created user:'); // @codeCoverageIgnoreStart if (env('APP_ENV') != 'testing') { diff --git a/api/app/Models/User.php b/api/app/Models/User.php index c848315d..6d97e9b0 100644 --- a/api/app/Models/User.php +++ b/api/app/Models/User.php @@ -66,7 +66,7 @@ class User extends IndexedModel implements AuthenticatableContract, SocialiteAut ]; /** - * Model validation + * Model validation. * @param null $entityId * @return array */ diff --git a/api/app/Providers/AuthDriverServiceProvider.php b/api/app/Providers/AuthDriverServiceProvider.php index 4a7fb0b7..a7fa8401 100644 --- a/api/app/Providers/AuthDriverServiceProvider.php +++ b/api/app/Providers/AuthDriverServiceProvider.php @@ -37,10 +37,10 @@ protected function getPayloadGenerators() return $transformer->transformItem($user); }, - 'method' => function (SocialiteAuthenticatable $user) { return $user->getCurrentAuthMethod() ?: 'password';}, - 'iss' => function () use ($request) { return $request->getHttpHost();}, - 'aud' => function () use ($request) { return str_replace('api.', '', $request->getHttpHost());}, - 'sub' => function (Authenticatable $user) {return $user->getAuthIdentifier();}, + 'method' => function (SocialiteAuthenticatable $user) { return $user->getCurrentAuthMethod() ?: 'password'; }, + 'iss' => function () use ($request) { return $request->getHttpHost(); }, + 'aud' => function () use ($request) { return str_replace('api.', '', $request->getHttpHost()); }, + 'sub' => function (Authenticatable $user) {return $user->getAuthIdentifier(); }, ] ); } diff --git a/api/src/Auth/Providers/JWTAuthDriverServiceProvider.php b/api/src/Auth/Providers/JWTAuthDriverServiceProvider.php index 8888671d..aa457202 100644 --- a/api/src/Auth/Providers/JWTAuthDriverServiceProvider.php +++ b/api/src/Auth/Providers/JWTAuthDriverServiceProvider.php @@ -261,11 +261,11 @@ protected function getPayloadGenerators() $request = $this->app['request']; return [ - 'iss' => function () use ($request) { return $request->url();}, - 'iat' => function () { return Carbon::now()->format('U');}, - 'exp' => function () { return Carbon::now()->addMinutes($this->ttl)->format('U');}, - 'nbf' => function () { return Carbon::now()->format('U');}, - 'jti' => function () { return str_random(16);}, + 'iss' => function () use ($request) { return $request->url(); }, + 'iat' => function () { return Carbon::now()->format('U'); }, + 'exp' => function () { return Carbon::now()->addMinutes($this->ttl)->format('U'); }, + 'nbf' => function () { return Carbon::now()->format('U'); }, + 'jti' => function () { return str_random(16); }, ]; } diff --git a/api/src/Rbac/Access/Gate.php b/api/src/Rbac/Access/Gate.php index bdc0264e..0e6e3658 100644 --- a/api/src/Rbac/Access/Gate.php +++ b/api/src/Rbac/Access/Gate.php @@ -118,7 +118,7 @@ public function check($itemName, $arguments = []) */ public function forUser(Authenticatable $user) { - return new static($this->getStorage(), function () use ($user) {return $user;}, $this->defaultRoles); + return new static($this->getStorage(), function () use ($user) {return $user; }, $this->defaultRoles); } /** diff --git a/api/tests/Auth/PayloadFactoryTest.php b/api/tests/Auth/PayloadFactoryTest.php index b2b5fa30..189e4e6f 100644 --- a/api/tests/Auth/PayloadFactoryTest.php +++ b/api/tests/Auth/PayloadFactoryTest.php @@ -26,7 +26,7 @@ public function testFactory() $user = m::mock(Authenticatable::class); $this->assertEquals($array, $factory->createFromUser($user)); - $factory->addPayloadGenerator('user', function ($user) {return $user;}); + $factory->addPayloadGenerator('user', function ($user) {return $user; }); $array['user'] = $user; diff --git a/api/tests/Auth/PayloadValidatorFactoryTest.php b/api/tests/Auth/PayloadValidatorFactoryTest.php index 77fc6c07..9a7606c7 100644 --- a/api/tests/Auth/PayloadValidatorFactoryTest.php +++ b/api/tests/Auth/PayloadValidatorFactoryTest.php @@ -17,13 +17,13 @@ public function testFactory() { $payload = ['one' => true, 'two' => 'two']; $closure = [ - 'one' => function ($payload) {return $payload['one'];}, + 'one' => function ($payload) {return $payload['one']; }, ]; $factory = new PayloadValidationFactory($closure); $this->assertNull($factory->validatePayload($payload)); - $factory->addValidationRule('two', function ($payload) {return $payload['two'] == 'two';}); + $factory->addValidationRule('two', function ($payload) {return $payload['two'] == 'two'; }); $this->assertNull($factory->validatePayload($payload)); } @@ -31,7 +31,7 @@ public function testRuleFailed() { $payload = ['one' => true, 'two' => 'two']; $closure = [ - 'one' => function () {return false;}, + 'one' => function () {return false; }, ]; $factory = new PayloadValidationFactory($closure); @@ -42,7 +42,7 @@ public function testRuleFailed() public function testMissingRule() { $closure = [ - 'three' => function ($payload) {return true;}, + 'three' => function ($payload) {return true; }, ]; $factory = new PayloadValidationFactory($closure); diff --git a/api/tests/CommandTest.php b/api/tests/CommandTest.php index 41c036e9..03840f0c 100644 --- a/api/tests/CommandTest.php +++ b/api/tests/CommandTest.php @@ -45,7 +45,6 @@ public function testGenerateKeysCommandMakeDirectory() public function testCreateUserCommand() { - $email = 'john.command.example@example.com'; $name = 'John'; $username = 'john'; @@ -67,17 +66,15 @@ public function testCreateUserCommand() $this->assertEquals($name, $userCreated->first_name); $this->assertEquals($username, $userCreated->username); - $this->assertTrue($userCreated->roles->contains(function ($key, Role $roleModel) use ($role){ + $this->assertTrue($userCreated->roles->contains(function ($key, Role $roleModel) use ($role) { return $roleModel->key == $role; }), 'Role is applied'); $this->assertTrue(Auth::attempt(['email' => $email, 'password' => $password]), 'Credentials work.'); - } public function testCreateInvalidUserCommand() { - $email = 'invalid-email'; $name = 'John'; $username = 'john'; @@ -101,7 +98,7 @@ public function testCreateInvalidUserCommand() private function mockUserCreateCommand($email, $name, $username, $password, $role) { /** @var CreateUserCommand $cmd */ - $cmd = Mockery::mock(CreateUserCommand::class . "[ask, secret, choice, info, error]"); + $cmd = Mockery::mock(CreateUserCommand::class.'[ask, secret, choice, info, error]'); $cmd->shouldReceive('ask') ->with('Enter email') @@ -127,8 +124,7 @@ private function mockUserCreateCommand($email, $name, $username, $password, $rol ->with('What roles should be applied? (comma separate options)', ROLE::$roles, null, null, true) ->once() ->andReturn([$role]); + return $cmd; } - - } diff --git a/api/tests/integration/AuthTest.php b/api/tests/integration/AuthTest.php index 6fa5f64d..8104ce5b 100644 --- a/api/tests/integration/AuthTest.php +++ b/api/tests/integration/AuthTest.php @@ -550,8 +550,8 @@ public function testValidateCustomPayload() { /** @var Guard $guard */ $guard = $this->app['auth']; - $guard->getPayloadFactory()->addPayloadGenerator('foo', function () {return 'foo';}); - $guard->getValidationFactory()->addValidationRule('foo', function () { return false;}); + $guard->getPayloadFactory()->addPayloadGenerator('foo', function () {return 'foo'; }); + $guard->getValidationFactory()->addValidationRule('foo', function () { return false; }); $user = $this->createUser(); $token = $this->tokenFromUser($user);