Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
94.44% covered (success)
94.44%
17 / 18
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ScopeRepository
94.44% covered (success)
94.44%
17 / 18
50.00% covered (danger)
50.00%
1 / 2
5.00
0.00% covered (danger)
0.00%
0 / 1
 getScopeEntityByIdentifier
94.12% covered (success)
94.12%
16 / 17
0.00% covered (danger)
0.00%
0 / 1
4.00
 finalizeScopes
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * OAuth2 scope repository.
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public License,
7 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
8 * obtain one at https://mozilla.org/MPL/2.0/.
9 *
10 * @package   phpMyFAQ
11 * @author    Thorsten Rinne <thorsten@phpmyfaq.de>
12 * @copyright 2026 phpMyFAQ Team
13 * @license   https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
14 * @link      https://www.phpmyfaq.de
15 * @since     2026-02-09
16 */
17
18declare(strict_types=1);
19
20namespace phpMyFAQ\Auth\OAuth2\Repository;
21
22use League\OAuth2\Server\Entities\ClientEntityInterface;
23use League\OAuth2\Server\Entities\ScopeEntityInterface;
24use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
25use phpMyFAQ\Auth\OAuth2\Entity\ScopeEntity;
26
27final class ScopeRepository extends AbstractRepository implements ScopeRepositoryInterface
28{
29    public function getScopeEntityByIdentifier(string $identifier): ?ScopeEntityInterface
30    {
31        $query = sprintf(
32            "SELECT scope_id FROM %s WHERE scope_id = '%s'",
33            $this->table('faqoauth_scopes'),
34            $this->db()->escape($identifier),
35        );
36
37        $result = $this->db()->query($query);
38        if ($result === false) {
39            return null;
40        }
41
42        $row = $this->db()->fetchObject($result);
43        if (!is_object($row)) {
44            return null;
45        }
46
47        $scopeIdentifier = (string) $row->scope_id;
48        if ($scopeIdentifier === '') {
49            return null;
50        }
51
52        $scope = new ScopeEntity();
53        $scope->setIdentifier($scopeIdentifier);
54
55        return $scope;
56    }
57
58    public function finalizeScopes(
59        array $scopes,
60        string $grantType,
61        ClientEntityInterface $clientEntity,
62        ?string $userIdentifier = null,
63        ?string $authCodeId = null,
64    ): array {
65        return $scopes;
66    }
67}