| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Parroauth2\Client\Provider; |
||||
| 4 | |||||
| 5 | use Jose\Component\Core\JWKSet; |
||||
| 6 | use Parroauth2\Client\Client; |
||||
| 7 | use Parroauth2\Client\ClientConfig; |
||||
| 8 | use Parroauth2\Client\ClientInterface; |
||||
| 9 | use Parroauth2\Client\ProxyClient; |
||||
| 10 | use Psr\Http\Message\RequestInterface; |
||||
| 11 | use Psr\Http\Message\ResponseInterface; |
||||
| 12 | |||||
| 13 | /** |
||||
| 14 | * Lazy loading implementation of the provider |
||||
| 15 | */ |
||||
| 16 | final class ProxyProvider implements ProviderInterface |
||||
| 17 | { |
||||
| 18 | /** |
||||
| 19 | * @var string|null |
||||
| 20 | */ |
||||
| 21 | private $url; |
||||
| 22 | |||||
| 23 | /** |
||||
| 24 | * @var ProviderLoader|null |
||||
| 25 | */ |
||||
| 26 | private $loader; |
||||
| 27 | |||||
| 28 | /** |
||||
| 29 | * @var ProviderInterface|null |
||||
| 30 | */ |
||||
| 31 | private $provider; |
||||
| 32 | |||||
| 33 | |||||
| 34 | /** |
||||
| 35 | * ProxyProvider constructor. |
||||
| 36 | * |
||||
| 37 | * @param string $url |
||||
| 38 | * @param ProviderLoader $loader |
||||
| 39 | */ |
||||
| 40 | 9 | public function __construct(string $url, ProviderLoader $loader) |
|||
| 41 | { |
||||
| 42 | 9 | $this->url = $url; |
|||
| 43 | 9 | $this->loader = $loader; |
|||
| 44 | 9 | } |
|||
| 45 | |||||
| 46 | /** |
||||
| 47 | * {@inheritdoc} |
||||
| 48 | */ |
||||
| 49 | 3 | public function openid(): bool |
|||
| 50 | { |
||||
| 51 | 3 | return $this->provider()->openid(); |
|||
| 52 | } |
||||
| 53 | |||||
| 54 | /** |
||||
| 55 | * {@inheritdoc} |
||||
| 56 | */ |
||||
| 57 | 3 | public function issuer(): string |
|||
| 58 | { |
||||
| 59 | 3 | return $this->provider()->issuer(); |
|||
| 60 | } |
||||
| 61 | |||||
| 62 | /** |
||||
| 63 | * {@inheritdoc} |
||||
| 64 | */ |
||||
| 65 | 2 | public function metadata(string $parameter, $default = null) |
|||
| 66 | { |
||||
| 67 | 2 | return $this->provider()->metadata($parameter, $default); |
|||
| 68 | } |
||||
| 69 | |||||
| 70 | /** |
||||
| 71 | * {@inheritdoc} |
||||
| 72 | */ |
||||
| 73 | 1 | public function supportsEndpoint(string $name): bool |
|||
| 74 | { |
||||
| 75 | 1 | return $this->provider()->supportsEndpoint($name); |
|||
| 76 | } |
||||
| 77 | |||||
| 78 | /** |
||||
| 79 | * {@inheritdoc} |
||||
| 80 | */ |
||||
| 81 | 1 | public function uri(string $name, array $queryParameters = []): string |
|||
| 82 | { |
||||
| 83 | 1 | return $this->provider()->uri($name, $queryParameters); |
|||
| 84 | } |
||||
| 85 | |||||
| 86 | /** |
||||
| 87 | * {@inheritdoc} |
||||
| 88 | */ |
||||
| 89 | public function request(string $method, string $endpoint, array $queryParameters = [], $body = null): RequestInterface |
||||
| 90 | { |
||||
| 91 | return $this->provider()->request($endpoint, $endpoint, $queryParameters, $body); |
||||
| 92 | } |
||||
| 93 | |||||
| 94 | /** |
||||
| 95 | * {@inheritdoc} |
||||
| 96 | */ |
||||
| 97 | public function sendRequest(RequestInterface $request): ResponseInterface |
||||
| 98 | { |
||||
| 99 | return $this->provider()->sendRequest($request); |
||||
| 100 | } |
||||
| 101 | |||||
| 102 | /** |
||||
| 103 | * {@inheritdoc} |
||||
| 104 | */ |
||||
| 105 | 5 | public function client(ClientConfig $config): ClientInterface |
|||
| 106 | { |
||||
| 107 | return new ProxyClient($config, function (ClientConfig $config) { |
||||
| 108 | 4 | return $this->provider()->client($config); |
|||
| 109 | 5 | }); |
|||
| 110 | } |
||||
| 111 | |||||
| 112 | /** |
||||
| 113 | * {@inheritdoc} |
||||
| 114 | */ |
||||
| 115 | 2 | public function keySet(): JWKSet |
|||
| 116 | { |
||||
| 117 | 2 | return $this->provider()->keySet(); |
|||
| 118 | } |
||||
| 119 | |||||
| 120 | /** |
||||
| 121 | * Get the real provider instance |
||||
| 122 | * |
||||
| 123 | * @return ProviderInterface |
||||
| 124 | * |
||||
| 125 | * @psalm-suppress PossiblyNullReference |
||||
| 126 | * @psalm-suppress PossiblyNullArgument |
||||
| 127 | */ |
||||
| 128 | 8 | private function provider(): ProviderInterface |
|||
| 129 | { |
||||
| 130 | 8 | if ($this->provider) { |
|||
| 131 | 4 | return $this->provider; |
|||
| 132 | } |
||||
| 133 | |||||
| 134 | 8 | $this->provider = $this->loader->discover($this->url); |
|||
|
0 ignored issues
–
show
It seems like
$this->url can also be of type null; however, parameter $providerUrl of Parroauth2\Client\Provid...viderLoader::discover() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 135 | 8 | $this->loader = null; |
|||
| 136 | 8 | $this->url = null; |
|||
| 137 | |||||
| 138 | 8 | return $this->provider; |
|||
| 139 | } |
||||
| 140 | } |
||||
| 141 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.