• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

avoutic / web-framework / 19992775795

06 Dec 2025 06:45PM UTC coverage: 72.97% (-0.009%) from 72.979%
19992775795

push

github

avoutic
Use modern find() variants

27 of 29 new or added lines in 6 files covered. (93.1%)

31 existing lines in 4 files now uncovered.

1995 of 2734 relevant lines covered (72.97%)

2.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Core/UserService.php
1
<?php
2

3
/*
4
 * This file is part of WebFramework.
5
 *
6
 * (c) Avoutic <avoutic@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
namespace WebFramework\Core;
13

14
use Carbon\Carbon;
15
use Psr\Log\LoggerInterface;
16
use WebFramework\Entity\User;
17
use WebFramework\Repository\UserRepository;
18
use WebFramework\Security\PasswordHashService;
19

20
/**
21
 * Class UserService.
22
 *
23
 * Handles user-related operations such as creation and availability checks.
24
 */
25
class UserService
26
{
27
    /**
28
     * UserService constructor.
29
     *
30
     * @param LoggerInterface     $logger              The logger
31
     * @param PasswordHashService $passwordHashService Service for hashing passwords
32
     * @param UserRepository      $userRepository      Repository for user data operations
33
     * @param string              $uniqueIdentifier    The unique identifier type ('email' or 'username')
34
     */
35
    public function __construct(
×
36
        private LoggerInterface $logger,
37
        private PasswordHashService $passwordHashService,
38
        private UserRepository $userRepository,
39
        private string $uniqueIdentifier,
40
    ) {}
×
41

42
    /**
43
     * Create a new user.
44
     *
45
     * @param string $username      The username for the new user
46
     * @param string $password      The password for the new user
47
     * @param string $email         The email address for the new user
48
     * @param int    $termsAccepted Timestamp of when the terms were accepted
49
     *
50
     * @return User The newly created User object
51
     */
52
    public function createUser(string $username, string $password, string $email, int $termsAccepted): User
×
53
    {
54
        $this->logger->info('Creating user', ['username' => $username, 'email' => $email]);
×
55

56
        $solidPassword = $this->passwordHashService->generateHash($password);
×
57

58
        return $this->userRepository->create([
×
59
            'username' => $username,
×
60
            'solid_password' => $solidPassword,
×
61
            'email' => $email,
×
62
            'terms_accepted' => $termsAccepted,
×
63
            'registered' => Carbon::now()->getTimestamp(),
×
64
        ]);
×
65
    }
66

67
    /**
68
     * Check if a username is available.
69
     *
70
     * @param string $username The username to check
71
     *
72
     * @return bool True if the username is available, false otherwise
73
     */
74
    public function isUsernameAvailable(string $username): bool
×
75
    {
76
        // Check if identifier already exists
77
        //
78
        if ($this->uniqueIdentifier == 'email')
×
79
        {
80
            return $this->userRepository
×
UNCOV
81
                ->query(['email' => $username])
×
UNCOV
82
                ->exists() === false
×
83
            ;
×
84
        }
85

UNCOV
86
        return $this->userRepository
×
UNCOV
87
            ->query(['username' => $username])
×
UNCOV
88
            ->exists() === false
×
UNCOV
89
        ;
×
90
    }
91
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc