Lines 28.00% 7 / 25
Methods 75.00% 3 / 4
Classes 0.00% 0 / 1
Covered by tests of size
Name Lines Methods CRAP
 getUserEntityByUserCredentials 18.18% 4 / 22 0.00% 0 / 1 43.05
 [phpMyFAQ\Auth\OAuth2\Repository\AbstractRepository] __construct 100.00% 1 / 1 100.00% 1 / 1 1
 [phpMyFAQ\Auth\OAuth2\Repository\AbstractRepository] db 100.00% 1 / 1 100.00% 1 / 1 1
 [phpMyFAQ\Auth\OAuth2\Repository\AbstractRepository] table 100.00% 1 / 1 100.00% 1 / 1 1
28final class UserRepository extends AbstractRepository implements UserRepositoryInterface
29{
30    public function getUserEntityByUserCredentials(
31        string $username,
32        #[\SensitiveParameter]
33        string $password,
34        string $grantType,
35        ClientEntityInterface $clientEntity,
36    ): ?UserEntityInterface {
37        try {
38            $authDatabase = new AuthDatabase($this->configuration);
39            if (!$authDatabase->checkCredentials($username, $password)) {
40                return null;
41            }
42        } catch (\Throwable) {
43            return null;
44        }
45
46        $query = sprintf(
47            "SELECT user_id FROM %s WHERE login = '%s'",
48            $this->table('faquser'),
49            $this->db()->escape($username),
50        );
51
52        $result = $this->db()->query($query);
53        if ($result === false) {
54            return null;
55        }
56
57        $row = $this->db()->fetchObject($result);
58        if (!is_object($row) || !property_exists($row, 'user_id') || $row->user_id === null) {
59            return null;
60        }
61
62        $userIdentifier = (string) $row->user_id;
63        if ($userIdentifier === '') {
64            return null;
65        }
66
67        $user = new UserEntity();
68        $user->setIdentifier($userIdentifier);
69
70        return $user;
71    }
72}

Inherited from phpMyFAQ\Auth\OAuth2\Repository\AbstractRepository

28    public function __construct(
29        protected readonly Configuration $configuration,
30    ) {
31    }
33    protected function db(): DatabaseDriver
34    {
35        return $this->configuration->getDb();
36    }
38    protected function table(string $tableName): string
39    {
40        return Database::getTablePrefix() . $tableName;
41    }