Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
55.56% |
5 / 9 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
| UserRepository | |
55.56% |
5 / 9 |
|
50.00% |
2 / 4 |
5.40 | |
0.00% |
0 / 1 |
| findById | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| updateBetaFlag | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| setPassword | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| updateDeveloperMode | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Repositories; |
| 4 | |
| 5 | use App\Http\Models\Auth\User; |
| 6 | use Illuminate\Support\Facades\Hash; |
| 7 | |
| 8 | /** |
| 9 | * Repository for User data access operations. |
| 10 | * |
| 11 | * Handles all database queries related to the users collection, |
| 12 | * keeping data access logic separate from business logic. |
| 13 | */ |
| 14 | class UserRepository |
| 15 | { |
| 16 | /** |
| 17 | * Find a user by their ID. |
| 18 | * |
| 19 | * @param string $userId The user ID |
| 20 | * @return User|null The user or null if not found |
| 21 | */ |
| 22 | public function findById(string $userId): ?User |
| 23 | { |
| 24 | return User::find($userId); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Update the is_beta flag for a given user. |
| 29 | * |
| 30 | * @param User $user The user to update |
| 31 | * @param bool $isBeta The new value for the is_beta flag |
| 32 | * @return User The updated user |
| 33 | */ |
| 34 | public function updateBetaFlag(User $user, bool $isBeta): User |
| 35 | { |
| 36 | $user->is_beta = $isBeta; |
| 37 | $user->save(); |
| 38 | |
| 39 | return $user->fresh(); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Force-set a new hashed password for a user, bypassing old password verification. |
| 44 | * |
| 45 | * @param User $user The user to update |
| 46 | * @param string $password The new plain-text password (will be hashed) |
| 47 | */ |
| 48 | public function setPassword(User $user, string $password): void |
| 49 | { |
| 50 | $user->password = Hash::make($password); |
| 51 | $user->save(); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Update the developer_mode flag for a given user. |
| 56 | * |
| 57 | * @param User $user The user to update |
| 58 | * @param bool $developer_mode The new value for the developer_mode flag |
| 59 | * @return User The updated user |
| 60 | */ |
| 61 | public function updateDeveloperMode(User $user, bool $developer_mode): User |
| 62 | { |
| 63 | $user->developer_mode = $developer_mode; |
| 64 | $user->save(); |
| 65 | |
| 66 | return $user->fresh(); |
| 67 | } |
| 68 | } |