Skip to content

Commit 706e862

Browse files
committed
fix: psalm on all, rename oauth and tidy up modern php
1 parent c58feab commit 706e862

13 files changed

Lines changed: 83 additions & 328 deletions

File tree

Cache/NullCache.php

Lines changed: 0 additions & 54 deletions
This file was deleted.
Lines changed: 9 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -13,57 +13,17 @@
1313
use Psr\Log\LoggerInterface;
1414
use Psr\SimpleCache\CacheInterface;
1515

16-
/**
17-
* Class BookboonOauthClient
18-
* @package Bookboon\OauthClient\Client
19-
*/
20-
class OauthClient implements OauthInterface
16+
class AccessTokenClient
2117
{
18+
protected string $_apiUri;
19+
private ?AccessTokenInterface $accessToken;
20+
protected ?string $act;
21+
protected BookboonProvider $provider;
22+
protected array $requestOptions = [];
23+
protected string $apiId;
24+
protected Headers $headers;
25+
protected ?CacheInterface $cache;
2226

23-
const C_VERSION = '2.2';
24-
25-
/** @var string */
26-
protected $_apiUri;
27-
28-
/** @var AccessTokenInterface|null */
29-
private $accessToken;
30-
31-
/** @var string|null */
32-
protected $act;
33-
34-
/** @var BookboonProvider */
35-
protected $provider;
36-
37-
/** @var array */
38-
protected $requestOptions = [];
39-
40-
/** @var string */
41-
protected $apiId;
42-
43-
/** @var string */
44-
protected $apiSecret;
45-
46-
/** @var Headers */
47-
protected $headers;
48-
49-
/** @var CacheInterface|null */
50-
protected $cache;
51-
52-
/**
53-
* ClientCommon constructor.
54-
* @param string $apiId
55-
* @param string $apiSecret
56-
* @param Headers $headers
57-
* @param array $scopes
58-
* @param CacheInterface|null $cache
59-
* @param string|null $redirectUri
60-
* @param string|null $appUserId
61-
* @param string|null $authServiceUri
62-
* @param string|null $apiUri
63-
* @param LoggerInterface|null $logger
64-
* @param array $clientOptions
65-
* @throws UsageException
66-
*/
6727
public function __construct(
6828
string $apiId,
6929
string $apiSecret,
@@ -151,12 +111,6 @@ public function requestAccessToken(
151111
return $this->accessToken;
152112
}
153113

154-
155-
/**
156-
* @param AccessTokenInterface $accessToken
157-
* @return AccessTokenInterface
158-
* @throws IdentityProviderException
159-
*/
160114
public function refreshAccessToken(AccessTokenInterface $accessToken) : AccessTokenInterface
161115
{
162116
$this->accessToken = $this->provider->getAccessToken('refresh_token', [
@@ -166,20 +120,11 @@ public function refreshAccessToken(AccessTokenInterface $accessToken) : AccessTo
166120
return $accessToken;
167121
}
168122

169-
/**
170-
* @return string
171-
*/
172123
public function generateState(): string
173124
{
174125
return $this->provider->generateRandomState();
175126
}
176127

177-
/**
178-
* @param string $stateParameter
179-
* @param string $stateSession
180-
* @return boolean
181-
* @throws ApiInvalidStateException
182-
*/
183128
public function isCorrectState(string $stateParameter, string $stateSession) : bool
184129
{
185130
if (empty($stateParameter) || ($stateParameter !== $stateSession)) {
@@ -189,10 +134,6 @@ public function isCorrectState(string $stateParameter, string $stateSession) : b
189134
return true;
190135
}
191136

192-
/**
193-
* @param array $options
194-
* @return string
195-
*/
196137
public function getAuthorizationUrl(array $options = []): string
197138
{
198139
$provider = $this->provider;
@@ -204,12 +145,6 @@ public function getAuthorizationUrl(array $options = []): string
204145
return $provider->getAuthorizationUrl($options);
205146
}
206147

207-
208-
/**
209-
* @param string|null $uri
210-
* @return string
211-
* @throws \Bookboon\ApiBundle\Exception\UsageException
212-
*/
213148
protected function parseUriOrDefault(?string $uri) : string
214149
{
215150
$protocol = ClientConstants::API_PROTOCOL;

Client/Headers.php

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ class Headers implements ArrayAccess
1414
const HEADER_LANGUAGE = 'Accept-Language';
1515
const HEADER_XFF = 'X-Forwarded-For';
1616

17-
/** @var array */
18-
private $headers = [];
17+
private array $headers = [];
1918

2019
public function __construct(array $headers = [])
2120
{
@@ -26,35 +25,16 @@ public function __construct(array $headers = [])
2625
$this->set(static::HEADER_XFF, $this->getRemoteAddress() ?? '');
2726
}
2827

29-
/**
30-
* Set or override header.
31-
*
32-
* @param string $header
33-
* @param string $value
34-
* @return void
35-
*/
3628
public function set(string $header, string $value) : void
3729
{
3830
$this->headers[$header] = $value;
3931
}
4032

41-
/**
42-
* Get specific header.
43-
*
44-
* @param string $header
45-
*
46-
* @return string|null false if header is not set or string value of header
47-
*/
4833
public function get(string $header) : ?string
4934
{
5035
return $this->headers[$header] ?? null;
5136
}
5237

53-
/**
54-
* Get all headers in CURL format.
55-
*
56-
* @return array
57-
*/
5838
public function getAll() : array
5939
{
6040
$headers = [];
@@ -65,9 +45,6 @@ public function getAll() : array
6545
return $headers;
6646
}
6747

68-
/**
69-
* @return array
70-
*/
7148
public function getHeadersArray() : array
7249
{
7350
return $this->headers;

Client/OauthInterface.php

Lines changed: 0 additions & 51 deletions
This file was deleted.

Client/RawClient.php

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,17 @@
1010
use GuzzleHttp\RequestOptions;
1111
use League\OAuth2\Client\Token\AccessTokenInterface;
1212
use Psr\SimpleCache\CacheInterface;
13-
use Symfony\Component\Serializer\Serializer;
1413
use Symfony\Component\Serializer\SerializerInterface;
1514

1615
class RawClient
1716
{
1817
const CACHE_KEY = "_raw_client_";
19-
/**
20-
* @var MappingCollection
21-
*/
22-
private $_mappings;
23-
/**
24-
* @var ClientInterface
25-
*/
26-
private $_client;
27-
/**
28-
* @var Serializer
29-
*/
30-
private $_serializer;
31-
/**
32-
* @var CacheInterface
33-
*/
34-
private $cache;
3518

36-
/**
37-
* @var AccessTokenInterface|null
38-
*/
39-
private $accessToken;
19+
private MappingCollection $_mappings;
20+
private ClientInterface $_client;
21+
private SerializerInterface $_serializer;
22+
private CacheInterface $cache;
23+
private ?AccessTokenInterface $accessToken;
4024

4125
public function __construct(
4226
MappingCollection $mappings,

DependencyInjection/BookboonApiExtension.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Bookboon\ApiBundle\DependencyInjection;
44

5-
use Bookboon\Api\Cache\Cache;
6-
use Bookboon\ApiBundle\Configuration\ApiConfiguration;
75
use Bookboon\ApiBundle\Helper\ConfigurationHolder;
86
use Symfony\Component\Config\FileLocator;
97
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -12,7 +10,6 @@
1210

1311
class BookboonApiExtension extends Extension
1412
{
15-
1613
/**
1714
* Loads a specific configuration.
1815
*
@@ -23,7 +20,12 @@ class BookboonApiExtension extends Extension
2320
*/
2421
public function load(array $configs, ContainerBuilder $container)
2522
{
26-
$config = $this->processConfiguration($this->getConfiguration($configs, $container), $configs);
23+
$holder = $this->getConfiguration($configs, $container);
24+
if (!$holder) {
25+
throw new \InvalidArgumentException("nulled config");
26+
}
27+
28+
$config = $this->processConfiguration($holder, $configs);
2729

2830
$container->register(ConfigurationHolder::class, ConfigurationHolder::class)
2931
->addArgument($config)

DependencyInjection/Configuration.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@
22

33
namespace Bookboon\ApiBundle\DependencyInjection;
44

5-
use Bookboon\ApiBundle\Cache\NullCache;
65
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
76
use Symfony\Component\Config\Definition\ConfigurationInterface;
87

98
class Configuration implements ConfigurationInterface
109
{
11-
/**
12-
* Generates the configuration tree builder.
13-
*
14-
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The tree builder
15-
*/
1610
public function getConfigTreeBuilder()
1711
{
1812
$treeBuilder = new TreeBuilder('bookboonapi');
@@ -27,13 +21,11 @@ public function getConfigTreeBuilder()
2721
->scalarNode('currency')->end()
2822
->scalarNode('impersonator_id')->defaultNull()->end()
2923
->scalarNode('redirect')->defaultNull()->end()
30-
->scalarNode('cache_service')->defaultValue(NullCache::class)->end()
3124
->arrayNode('languages')->isRequired()->prototype('scalar')->end()->end()
3225
->arrayNode('scopes')->isRequired()->prototype('scalar')->end()->end()
3326
->integerNode('premium_level')->end()
3427
->scalarNode('override_api_uri')->defaultNull()->end()
3528
->scalarNode('override_auth_uri')->defaultNull()->end()
36-
->scalarNode('client_service')->defaultNull()->end()
3729
;
3830

3931
return $treeBuilder;

0 commit comments

Comments
 (0)