Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Commit 5d92daa

Browse files
committed
Merge pull request #20 from Adldap2/analysis-qMVOKz
Applied fixes from StyleCI
2 parents 9c8fe26 + 7a94d76 commit 5d92daa

File tree

5 files changed

+31
-30
lines changed

5 files changed

+31
-30
lines changed

src/AdldapAuthServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function boot()
3131
$this->mergeConfigFrom($auth, 'adldap_auth');
3232

3333
// Extend Laravel authentication with Adldap driver.
34-
Auth::extend('adldap', function($app) {
34+
Auth::extend('adldap', function ($app) {
3535
return new AdldapAuthUserProvider($app['hash'], $app['config']['auth.model']);
3636
});
3737
}

src/AdldapAuthUserProvider.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
namespace Adldap\Laravel;
44

55
use Adldap\Laravel\Facades\Adldap;
6-
use Adldap\Schemas\ActiveDirectory;
76
use Adldap\Models\User;
7+
use Adldap\Schemas\ActiveDirectory;
8+
use Illuminate\Auth\EloquentUserProvider;
9+
use Illuminate\Contracts\Auth\Authenticatable;
10+
use Illuminate\Database\Eloquent\Model;
811
use Illuminate\Support\Arr;
912
use Illuminate\Support\Facades\Config;
10-
use Illuminate\Database\Eloquent\Model;
11-
use Illuminate\Contracts\Auth\Authenticatable;
12-
use Illuminate\Auth\EloquentUserProvider;
1313

1414
class AdldapAuthUserProvider extends EloquentUserProvider
1515
{
1616
/**
17-
* {@inheritDoc}
17+
* {@inheritdoc}
1818
*/
1919
public function retrieveById($identifier)
2020
{
@@ -24,7 +24,7 @@ public function retrieveById($identifier)
2424
}
2525

2626
/**
27-
* {@inheritDoc}
27+
* {@inheritdoc}
2828
*/
2929
public function retrieveByToken($identifier, $token)
3030
{
@@ -34,7 +34,7 @@ public function retrieveByToken($identifier, $token)
3434
}
3535

3636
/**
37-
* {@inheritDoc}
37+
* {@inheritdoc}
3838
*/
3939
public function retrieveByCredentials(array $credentials)
4040
{
@@ -54,30 +54,30 @@ public function retrieveByCredentials(array $credentials)
5454
$user = $query->first();
5555

5656
// If the user is an Adldap User model instance.
57-
if($user instanceof User) {
57+
if ($user instanceof User) {
5858
// Retrieve the users login attribute.
5959
$username = $user->{$this->getLoginAttribute()};
6060

61-
if(is_array($username)) {
61+
if (is_array($username)) {
6262
$username = Arr::get($username, 0);
6363
}
6464

6565
// Get the password input array key.
6666
$key = $this->getPasswordKey();
6767

6868
// Try to log the user in.
69-
if($this->authenticate($username, $credentials[$key])) {
69+
if ($this->authenticate($username, $credentials[$key])) {
7070
// Login was successful, we'll create a new
7171
// Laravel model with the Adldap user.
7272
return $this->getModelFromAdldap($user, $credentials[$key]);
7373
}
7474
}
7575

76-
return null;
76+
return;
7777
}
7878

7979
/**
80-
* Creates a local User from Active Directory
80+
* Creates a local User from Active Directory.
8181
*
8282
* @param User $user
8383
* @param string $password
@@ -105,7 +105,9 @@ protected function getModelFromAdldap(User $user, $password)
105105
$model = $this->createModel()->newQuery()->where([$key => $username])->first();
106106

107107
// Create the model instance of it isn't found.
108-
if(!$model) $model = $this->createModel();
108+
if (!$model) {
109+
$model = $this->createModel();
110+
}
109111

110112
// Set the username and password in case
111113
// of changes in active directory.
@@ -118,7 +120,7 @@ protected function getModelFromAdldap(User $user, $password)
118120
// attributes on the model.
119121
$model = $this->syncModelFromAdldap($user, $model);
120122

121-
if($this->getBindUserToModel()) {
123+
if ($this->getBindUserToModel()) {
122124
$model = $this->bindAdldapToModel($user, $model);
123125
}
124126

@@ -137,10 +139,10 @@ protected function syncModelFromAdldap(User $user, Authenticatable $model)
137139
{
138140
$attributes = $this->getSyncAttributes();
139141

140-
foreach($attributes as $modelField => $adField) {
142+
foreach ($attributes as $modelField => $adField) {
141143
$adValue = $user->{$adField};
142144

143-
if(is_array($adValue)) {
145+
if (is_array($adValue)) {
144146
// If the AD Value is an array, we'll
145147
// retrieve the first value.
146148
$adValue = Arr::get($adValue, 0);
@@ -150,7 +152,7 @@ protected function syncModelFromAdldap(User $user, Authenticatable $model)
150152
}
151153

152154
// Only save models that contain changes.
153-
if($model instanceof Model && count($model->getDirty()) > 0) {
155+
if ($model instanceof Model && count($model->getDirty()) > 0) {
154156
$model->save();
155157
}
156158

src/AdldapServiceProvider.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,17 @@ public function boot()
3535
public function register()
3636
{
3737
// Bind the Adldap instance to the IoC
38-
$this->app->bind('adldap', function()
39-
{
38+
$this->app->bind('adldap', function () {
4039
$config = $this->app['config']->get('adldap');
4140

4241
// Verify configuration
43-
if(is_null($config)) {
42+
if (is_null($config)) {
4443
$message = 'Adldap configuration could not be found. Try re-publishing using `php artisan vendor:publish`.';
4544

4645
throw new ConfigurationMissingException($message);
4746
}
4847

49-
return new Adldap($config['connection_settings'], new $config['connection'], $config['auto_connect']);
48+
return new Adldap($config['connection_settings'], new $config['connection'](), $config['auto_connect']);
5049
});
5150

5251
// Bind the Adldap contract to the Adldap object

tests/AdldapTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace Adldap\Laravel\Tests;
44

5-
use Mockery;
6-
use Adldap\Models\User;
75
use Adldap\Laravel\Facades\Adldap;
8-
use Illuminate\Support\Facades\Auth;
6+
use Adldap\Models\User;
97
use Illuminate\Support\Facades\App;
8+
use Illuminate\Support\Facades\Auth;
9+
use Mockery;
1010

1111
class AdldapTest extends FunctionalTestCase
1212
{
@@ -52,8 +52,8 @@ public function testAuthPasses()
5252

5353
$rawAttributes = [
5454
'samaccountname' => ['jdoe'],
55-
'mail' => ['jdoe@email.com'],
56-
'cn' => ['John Doe'],
55+
'mail' => ['jdoe@email.com'],
56+
'cn' => ['John Doe'],
5757
];
5858

5959
$adUser = (new User([], $mockedBuilder))->setRawAttributes($rawAttributes);
@@ -122,8 +122,8 @@ public function testAuthFailsWhenUserFound()
122122

123123
$rawAttributes = [
124124
'samaccountname' => ['jdoe'],
125-
'mail' => ['jdoe@email.com'],
126-
'cn' => ['John Doe'],
125+
'mail' => ['jdoe@email.com'],
126+
'cn' => ['John Doe'],
127127
];
128128

129129
$adUser = (new User([], $mockedBuilder))->setRawAttributes($rawAttributes);

tests/Models/User.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
use Adldap\Laravel\Traits\AdldapUserModelTrait;
66
use Illuminate\Auth\Authenticatable;
7-
use Illuminate\Database\Eloquent\Model;
87
use Illuminate\Auth\Passwords\CanResetPassword;
98
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
109
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
10+
use Illuminate\Database\Eloquent\Model;
1111

1212
class User extends Model implements AuthenticatableContract, CanResetPasswordContract
1313
{

0 commit comments

Comments
 (0)