]> BookStack Code Mirror - bookstack/blobdiff - app/Auth/Access/UserTokenService.php
Fixes for CodeStyle vol.2
[bookstack] / app / Auth / Access / UserTokenService.php
index a1defbf62d439a4bdacdef971271db1dde532afd..565dcb948b4caab36ee2056784d200241417fa27 100644 (file)
@@ -1,4 +1,6 @@
-<?php namespace BookStack\Auth\Access;
+<?php
+
+namespace BookStack\Auth\Access;
 
 use BookStack\Auth\User;
 use BookStack\Exceptions\UserTokenExpiredException;
@@ -10,15 +12,16 @@ use stdClass;
 
 class UserTokenService
 {
-
     /**
      * Name of table where user tokens are stored.
+     *
      * @var string
      */
     protected $tokenTable = 'user_tokens';
 
     /**
      * Token expiry time in hours.
+     *
      * @var int
      */
     protected $expiryTime = 24;
@@ -27,6 +30,7 @@ class UserTokenService
 
     /**
      * UserTokenService constructor.
+     *
      * @param Database $db
      */
     public function __construct(Database $db)
@@ -36,7 +40,9 @@ class UserTokenService
 
     /**
      * Delete all email confirmations that belong to a user.
+     *
      * @param User $user
+     *
      * @return mixed
      */
     public function deleteByUser(User $user)
@@ -48,12 +54,15 @@ class UserTokenService
 
     /**
      * Get the user id from a token, while check the token exists and has not expired.
+     *
      * @param string $token
-     * @return int
+     *
      * @throws UserTokenNotFoundException
      * @throws UserTokenExpiredException
+     *
+     * @return int
      */
-    public function checkTokenAndGetUserId(string $token) : int
+    public function checkTokenAndGetUserId(string $token): int
     {
         $entry = $this->getEntryByToken($token);
 
@@ -70,40 +79,47 @@ class UserTokenService
 
     /**
      * Creates a unique token within the email confirmation database.
+     *
      * @return string
      */
-    protected function generateToken() : string
+    protected function generateToken(): string
     {
         $token = Str::random(24);
         while ($this->tokenExists($token)) {
             $token = Str::random(25);
         }
+
         return $token;
     }
 
     /**
      * Generate and store a token for the given user.
+     *
      * @param User $user
+     *
      * @return string
      */
-    protected function createTokenForUser(User $user) : string
+    protected function createTokenForUser(User $user): string
     {
         $token = $this->generateToken();
         $this->db->table($this->tokenTable)->insert([
-            'user_id' => $user->id,
-            'token' => $token,
+            'user_id'    => $user->id,
+            'token'      => $token,
             'created_at' => Carbon::now(),
-            'updated_at' => Carbon::now()
+            'updated_at' => Carbon::now(),
         ]);
+
         return $token;
     }
 
     /**
      * Check if the given token exists.
+     *
      * @param string $token
+     *
      * @return bool
      */
-    protected function tokenExists(string $token) : bool
+    protected function tokenExists(string $token): bool
     {
         return $this->db->table($this->tokenTable)
             ->where('token', '=', $token)->exists();
@@ -111,7 +127,9 @@ class UserTokenService
 
     /**
      * Get a token entry for the given token.
+     *
      * @param string $token
+     *
      * @return object|null
      */
     protected function getEntryByToken(string $token)
@@ -123,10 +141,12 @@ class UserTokenService
 
     /**
      * Check if the given token entry has expired.
+     *
      * @param stdClass $tokenEntry
+     *
      * @return bool
      */
-    protected function entryExpired(stdClass $tokenEntry) : bool
+    protected function entryExpired(stdClass $tokenEntry): bool
     {
         return Carbon::now()->subHours($this->expiryTime)
             ->gt(new Carbon($tokenEntry->created_at));