Skip to content

Commit

Permalink
Improvements to Illuminate Auth package code formatting
Browse files Browse the repository at this point in the history
This pull request improves the code formatting for the Illuminate Auth
package by cleaning up inconsistent formatting, fixing typos and
spaces, adding better variable names and making some comments and
docblocks more consistent.
  • Loading branch information
lowerends committed May 19, 2015
1 parent b397448 commit cd56ae3
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 35 deletions.
5 changes: 4 additions & 1 deletion src/Illuminate/Auth/AuthManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ protected function callCustomCreator($driver)
{
$custom = parent::callCustomCreator($driver);

if ($custom instanceof Guard) return $custom;
if ($custom instanceof Guard)
{
return $custom;
}

return new Guard($custom, $this->app['session.store']);
}
Expand Down
14 changes: 7 additions & 7 deletions src/Illuminate/Auth/DatabaseUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ public function retrieveById($identifier)
}

/**
* Retrieve a user by by their unique identifier and "remember me" token.
* Retrieve a user by their unique identifier and "remember me" token.
*
* @param mixed $identifier
* @param mixed $identifier
* @param string $token
* @return \Illuminate\Contracts\Auth\Authenticatable|null
*/
public function retrieveByToken($identifier, $token)
{
$user = $this->conn->table($this->table)
->where('id', $identifier)
->where('remember_token', $token)
->first();
->where('id', $identifier)
->where('remember_token', $token)
->first();

return $this->getGenericUser($user);
}
Expand All @@ -83,8 +83,8 @@ public function retrieveByToken($identifier, $token)
public function updateRememberToken(UserContract $user, $token)
{
$this->conn->table($this->table)
->where('id', $user->getAuthIdentifier())
->update(['remember_token' => $token]);
->where('id', $user->getAuthIdentifier())
->update(['remember_token' => $token]);
}

/**
Expand Down
11 changes: 7 additions & 4 deletions src/Illuminate/Auth/EloquentUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public function retrieveByToken($identifier, $token)
$model = $this->createModel();

return $model->newQuery()
->where($model->getKeyName(), $identifier)
->where($model->getRememberTokenName(), $token)
->first();
->where($model->getKeyName(), $identifier)
->where($model->getRememberTokenName(), $token)
->first();
}

/**
Expand Down Expand Up @@ -90,7 +90,10 @@ public function retrieveByCredentials(array $credentials)

foreach ($credentials as $key => $value)
{
if ( ! str_contains($key, 'password')) $query->where($key, $value);
if ( ! str_contains($key, 'password'))
{
$query->where($key, $value);
}
}

return $query->first();
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Auth/GenericUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function getAuthPassword()
}

/**
* Get the token value for the "remember me" session.
* Get the "remember me" token value.
*
* @return string
*/
Expand All @@ -53,7 +53,7 @@ public function getRememberToken()
}

/**
* Set the token value for the "remember me" session.
* Set the "remember me" token value.
*
* @param string $value
* @return void
Expand Down Expand Up @@ -88,7 +88,7 @@ public function __get($key)
* Dynamically set an attribute on the user.
*
* @param string $key
* @param mixed $value
* @param mixed $value
* @return void
*/
public function __set($key, $value)
Expand Down
38 changes: 26 additions & 12 deletions src/Illuminate/Auth/Guard.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ public function user()
*/
public function id()
{
if ($this->loggedOut) return;
if ($this->loggedOut)
{
return;
}

$id = $this->session->get($this->getName(), $this->getRecallerId());

Expand Down Expand Up @@ -282,12 +285,18 @@ public function validate(array $credentials = [])
*/
public function basic($field = 'email')
{
if ($this->check()) return;
if ($this->check())
{
return;
}

// If a username is set on the HTTP basic request, we will return out without
// interrupting the request lifecycle. Otherwise, we'll need to generate a
// request indicating that the given credentials were invalid for login.
if ($this->attemptBasic($this->getRequest(), $field)) return;
if ($this->attemptBasic($this->getRequest(), $field))
{
return;
}

return $this->getBasicResponse();
}
Expand Down Expand Up @@ -315,7 +324,10 @@ public function onceBasic($field = 'email')
*/
protected function attemptBasic(Request $request, $field)
{
if ( ! $request->getUser()) return false;
if ( ! $request->getUser())
{
return false;
}

return $this->attempt($this->getBasicCredentials($request, $field));
}
Expand Down Expand Up @@ -364,8 +376,10 @@ public function attempt(array $credentials = [], $remember = false, $login = tru
if ($this->hasValidCredentials($user, $credentials))
{
if ($login) $this->login($user, $remember);
{
return true;

return true;
}
}

return false;
Expand All @@ -387,8 +401,8 @@ protected function hasValidCredentials($user, $credentials)
* Fire the attempt event with the arguments.
*
* @param array $credentials
* @param bool $remember
* @param bool $login
* @param bool $remember
* @param bool $login
* @return void
*/
protected function fireAttemptEvent(array $credentials, $remember, $login)
Expand Down Expand Up @@ -515,7 +529,7 @@ protected function queueRecallerCookie(UserContract $user)
}

/**
* Create a remember me cookie for a given ID.
* Create a "remember me" cookie for a given ID.
*
* @param string $value
* @return \Symfony\Component\HttpFoundation\Cookie
Expand Down Expand Up @@ -572,7 +586,7 @@ protected function clearUserDataFromStorage()
}

/**
* Refresh the remember token for the user.
* Refresh the "remember me" token for the user.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @return void
Expand All @@ -585,7 +599,7 @@ protected function refreshRememberToken(UserContract $user)
}

/**
* Create a new remember token for the user if one doesn't already exist.
* Create a new "remember me" token for the user if one doesn't already exist.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @return void
Expand Down Expand Up @@ -681,7 +695,7 @@ public function setProvider(UserProvider $provider)
}

/**
* Return the currently cached user of the application.
* Return the currently cached user.
*
* @return \Illuminate\Contracts\Auth\Authenticatable|null
*/
Expand All @@ -691,7 +705,7 @@ public function getUser()
}

/**
* Set the current user of the application.
* Set the current user.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @return void
Expand Down
8 changes: 4 additions & 4 deletions src/Illuminate/Auth/Passwords/DatabaseTokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ public function exists(CanResetPasswordContract $user, $token)
*/
protected function tokenExpired($token)
{
$createdPlusHour = strtotime($token['created_at']) + $this->expires;
$expirationTime = strtotime($token['created_at']) + $this->expires;

return $createdPlusHour < $this->getCurrentTime();
return $expirationTime < $this->getCurrentTime();
}

/**
Expand Down Expand Up @@ -153,9 +153,9 @@ public function delete($token)
*/
public function deleteExpired()
{
$expired = Carbon::now()->subSeconds($this->expires);
$expiredAt = Carbon::now()->subSeconds($this->expires);

$this->getTable()->where('created_at', '<', $expired)->delete();
$this->getTable()->where('created_at', '<', $expiredAt)->delete();
}

/**
Expand Down
13 changes: 9 additions & 4 deletions src/Illuminate/Auth/Passwords/PasswordBroker.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,17 @@ public function emailResetLink(CanResetPasswordContract $user, $token, Closure $
{
$m->to($user->getEmailForPasswordReset());

if ( ! is_null($callback)) call_user_func($callback, $m, $user, $token);
if ( ! is_null($callback))
{
call_user_func($callback, $m, $user, $token);
}
});
}

/**
* Reset the password for the given token.
*
* @param array $credentials
* @param array $credentials
* @param \Closure $callback
* @return mixed
*/
Expand Down Expand Up @@ -193,7 +196,8 @@ public function validator(Closure $callback)
public function validateNewPassword(array $credentials)
{
list($password, $confirm) = [
$credentials['password'], $credentials['password_confirmation'],
$credentials['password'],
$credentials['password_confirmation'],
];

if (isset($this->passwordValidator))
Expand All @@ -214,7 +218,8 @@ public function validateNewPassword(array $credentials)
protected function validatePasswordWithDefaults(array $credentials)
{
list($password, $confirm) = [
$credentials['password'], $credentials['password_confirmation'],
$credentials['password'],
$credentials['password_confirmation'],
];

return $password === $confirm && mb_strlen($password) >= 6;
Expand Down

0 comments on commit cd56ae3

Please sign in to comment.