Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
ClientEntity
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
4 / 4
5
100.00% covered (success)
100.00%
1 / 1
 setName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setRedirectUri
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setConfidential
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 supportsGrantType
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3/**
4 * OAuth2 client entity.
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\Entity;
21
22use League\OAuth2\Server\Entities\ClientEntityInterface;
23use League\OAuth2\Server\Entities\Traits\ClientTrait;
24use League\OAuth2\Server\Entities\Traits\EntityTrait;
25
26final class ClientEntity implements ClientEntityInterface
27{
28    use EntityTrait;
29    use ClientTrait;
30
31    public ?string $secret = null {
32        get {
33            return $this->secret;
34        }
35        set {
36            $this->secret = $value;
37        }
38    }
39
40    /** @var string[] */
41    public array $allowedGrants = [] {
42        set {
43            $this->allowedGrants = $value;
44        }
45    }
46
47    public function setName(string $name): void
48    {
49        $this->name = $name;
50    }
51
52    /**
53     * @param string|string[] $redirectUri
54     */
55    public function setRedirectUri(string|array $redirectUri): void
56    {
57        $this->redirectUri = $redirectUri;
58    }
59
60    public function setConfidential(bool $isConfidential): void
61    {
62        $this->isConfidential = $isConfidential;
63    }
64
65    public function supportsGrantType(string $grantType): bool
66    {
67        if ($this->allowedGrants === []) {
68            return true;
69        }
70
71        return in_array($grantType, $this->allowedGrants, strict: true);
72    }
73}