Skip to content

Commit 12527a5

Browse files
Feature update php (#18)
* add type def to functions * update phpunit * fix router example use declarations * fix travis version * delete hhvm * remove PHP v from travis, fix tests * add composer script * add support for php 7.3 and 7.4 * add return type for AuthCode setConfigProvider * enhance config in AuthCodeControllerTest * mute slack for now * fix setConfigProvider return type * fix return type at EncryptionInterface isValid * fix encrypt type * fix decrypt type * test getMockBuilder * adjust unit tests, still failing * fix mocks, testing travis * fix some mocks * fix DI object * fix authcode error * fix authcode test, forgot one * fix mocks * remove support for php 7.1 * turn slack notifications back on
1 parent 2a45f08 commit 12527a5

30 files changed

+376
-256
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ vendor/
5555

5656
# PHPUnit Results & Code Coverage
5757
test-results/
58+
.phpunit.result.cache
5859

5960
# PHPDoc
6061
build/

.travis.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
sudo: false
22
language: php
33
php:
4-
- '5.6'
5-
- '7.0'
6-
- '7.1'
74
- '7.2'
8-
- hhvm
5+
- '7.3'
6+
- '7.4'
97
notifications:
108
email: false
11-
slack:
9+
slack: true
1210
secure: EO2s9RZiCroLbMtsHn+ls+7yZ0xe/NU0SwS0BQdI7C656fEfCUA7YwT3t/KBA7wDWXE+NRSZbxGzPlA3OxJSMPG1bWraFHjHov9Ip+0Ekbp56XfmZYcMXjxO9McW70syVwTTo5SyGGAv6MURmNc2DkkSFWpcuRqccfFCDHiHMqdDrThj9Pq/XU4W21m+2JI8iC+WlwIxOf2eu8wgf1NsDh2MbxuK/+bQ6XRd3R/m0ht1i52u8190HUTFJ3epSAaX0qnZK5XEo+fHXmR1hHNSITwsDLrGoQ9o9Pu1JAXaJdSRTJpOCFdgIY9oqcSRlneStAbCw4xeEwlgutq77ASVwm/3epAMTWbfJe1a6bfAzh8xvyj/gTT7eI3uQ6GDh6+4gfGZNUKehmWU3Qgb4SLQXmmwaL3CRFedpTq8BhRb+zgVhESuXCBwsFdqMZ4OrcH4I4SpTEDirXmAdXXjeK8IqFsPiYhmoCPD8TC0LGXjsW5vXv8XTAcaL9CdruGUjr+WXyETGKGRsAEHLNRBZcb+Jfq+NczeeTd3Nj4EcW1by/d1uAhc6eVRqXf9FkiXDZQWpOhX54WYIobSSWDsGqGd5UcoS4IHZhaejD3I+zeqopFdLp2RuWCtdbzVWAMF4upLjwimVAM3p+3fYzia/rBlDvjgvf9qF6L3F7tsFEsA3ys=
1311
before_script:
14-
- composer require phpunit/phpunit:4.8.* php-coveralls/php-coveralls
12+
- composer require phpunit/phpunit:8.3 php-coveralls/php-coveralls
1513
- composer install --no-interaction
1614
script: vendor/bin/phpunit
1715
after_script:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ This project is designed to be executed in a server environment with [Apache HTT
5151

5252
### Prerequisites
5353

54-
A recent version of [PHP](https://php.net/), equal to or greater than 5.6.0 is required.
54+
A recent version of [PHP](https://php.net/), equal to or greater than 7.2.0 is required.
5555

5656
The default [EncryptionProvider](/src/Providers/EncryptionProvider.php) class provided in this package relies on the [OpenSSL](https://php.net/manual/en/book.openssl.php) extension. If OpenSSL is unavailable, the consumer has the option to implement a custom EncryptionProvider class that implements our [EncryptionInterface](/src/Interfaces/EncryptionInterface.php). (For more information, see the [EncryptionProvider](#encryptionprovider) section.)
5757

composer.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,17 @@
4242
}
4343
},
4444
"require": {
45-
"php": ">=5.6.0",
45+
"php": ">=7.2.0",
4646
"guzzlehttp/guzzle": "~6.0",
47-
"php-di/php-di": "^5.2"
47+
"php-di/php-di": "^6.0"
4848
},
4949
"require-dev": {
50-
"phpunit/phpunit": "4.8.*",
50+
"phpunit/phpunit": "^8",
5151
"phpdocumentor/phpdocumentor": "2.*",
5252
"evert/phpdoc-md": "0.2.0",
5353
"phly/changelog-generator": "^2.1"
54-
}
54+
},
55+
"scripts": {
56+
"test:unit": "./vendor/bin/phpunit tests/unit --verbose"
57+
}
5558
}

examples/Router.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
<?php
22

33
use Illuminate\Http\Response;
4-
use NPR\One\Controllers\AuthCodeController;
5-
use NPR\One\Controllers\DeviceCodeController;
6-
use NPR\One\Controllers\LogoutController;
7-
use NPR\One\Controllers\RefreshTokenController;
4+
use NPR\One\Controllers\{AuthCodeController, DeviceCodeController, LogoutController, RefreshTokenController};
85
use NPR\One\Exceptions\ApiException;
9-
use Your\Package\Here\ConfigProvider;
10-
use Your\Package\Here\StorageProvider;
6+
use Your\Package\Here\{ConfigProvider, StorageProvider};
117

128

139
/**

phpunit.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
convertNoticesToExceptions="true"
88
convertWarningsToExceptions="true"
99
processIsolation="false"
10-
stopOnFailure="false"
11-
syntaxCheck="false">
10+
stopOnFailure="false">
1211
<testsuites>
1312
<testsuite name="Backend Proxy Test Suite">
1413
<directory suffix=".php">./tests/</directory>
@@ -24,6 +23,6 @@
2423
</filter>
2524
<logging>
2625
<log type="coverage-clover" target="test-results/coverage.xml"/>
27-
<log type="junit" target="test-results/junit.xml" logIncompleteSkipped="false"/>
26+
<log type="junit" target="test-results/junit.xml"/>
2827
</logging>
2928
</phpunit>

src/Controllers/AbstractOAuth2Controller.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,9 @@
55
use GuzzleHttp\Client;
66
use NPR\One\DI\DI;
77
use NPR\One\Exceptions\ApiException;
8-
use NPR\One\Interfaces\ConfigInterface;
9-
use NPR\One\Interfaces\EncryptionInterface;
10-
use NPR\One\Interfaces\StorageInterface;
8+
use NPR\One\Interfaces\{ConfigInterface, EncryptionInterface, StorageInterface};
119
use NPR\One\Models\AccessTokenModel;
12-
use NPR\One\Providers\CookieProvider;
13-
use NPR\One\Providers\EncryptionProvider;
14-
use NPR\One\Providers\SecureCookieProvider;
10+
use NPR\One\Providers\{CookieProvider, EncryptionProvider, SecureCookieProvider};
1511

1612

1713
/**
@@ -64,7 +60,7 @@ public function __construct()
6460
*
6561
* @return string[]
6662
*/
67-
public function getHeaders()
63+
public function getHeaders(): array
6864
{
6965
return $this->headers;
7066
}
@@ -76,7 +72,7 @@ public function getHeaders()
7672
* @param ConfigInterface $configProvider
7773
* @return $this
7874
*/
79-
public function setConfigProvider(ConfigInterface $configProvider)
75+
public function setConfigProvider(ConfigInterface $configProvider): AbstractOAuth2Controller
8076
{
8177
$this->config = $configProvider;
8278
return $this;
@@ -90,7 +86,7 @@ public function setConfigProvider(ConfigInterface $configProvider)
9086
* @param StorageInterface $storageProvider
9187
* @return $this
9288
*/
93-
public function setSecureStorageProvider(StorageInterface $storageProvider)
89+
public function setSecureStorageProvider(StorageInterface $storageProvider): AbstractOAuth2Controller
9490
{
9591
$this->secureStorage = $storageProvider;
9692
return $this;
@@ -105,7 +101,7 @@ public function setSecureStorageProvider(StorageInterface $storageProvider)
105101
* @param EncryptionInterface $encryptionProvider
106102
* @return $this
107103
*/
108-
public function setEncryptionProvider(EncryptionInterface $encryptionProvider)
104+
public function setEncryptionProvider(EncryptionInterface $encryptionProvider): AbstractOauth2Controller
109105
{
110106
$this->encryption = $encryptionProvider;
111107
return $this;
@@ -162,7 +158,7 @@ protected function ensureExternalProvidersExist()
162158
* @internal
163159
* @return ConfigInterface
164160
*/
165-
final protected function getConfigProvider()
161+
final protected function getConfigProvider(): ConfigInterface
166162
{
167163
return $this->config;
168164
}
@@ -173,7 +169,7 @@ final protected function getConfigProvider()
173169
* @internal
174170
* @return StorageInterface
175171
*/
176-
final protected function getSecureStorageProvider()
172+
final protected function getSecureStorageProvider(): StorageInterface
177173
{
178174
return $this->secureStorage;
179175
}
@@ -214,7 +210,7 @@ final protected function validateScopes(array $scopes)
214210
* @throws \Exception
215211
* @throws \GuzzleHttp\Exception\GuzzleException
216212
*/
217-
final protected function createAccessToken($grantType, $additionalParams = [])
213+
final protected function createAccessToken($grantType, $additionalParams = []): AccessTokenModel
218214
{
219215
if (empty($grantType) || !is_string($grantType))
220216
{

src/Controllers/AuthCodeController.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
namespace NPR\One\Controllers;
44

55
use NPR\One\DI\DI;
6-
use NPR\One\Interfaces\ConfigInterface;
7-
use NPR\One\Interfaces\StorageInterface;
6+
use NPR\One\Interfaces\{ConfigInterface, StorageInterface};
87
use NPR\One\Models\AccessTokenModel;
98
use NPR\One\Providers\CookieProvider;
109

@@ -42,7 +41,7 @@ public function __construct()
4241
/**
4342
* {@inheritdoc}
4443
*/
45-
public function setConfigProvider(ConfigInterface $configProvider)
44+
public function setConfigProvider(ConfigInterface $configProvider): AbstractOAuth2Controller
4645
{
4746
parent::setConfigProvider($configProvider);
4847
$this->cookies->setDomain($configProvider->getCookieDomain());
@@ -56,7 +55,7 @@ public function setConfigProvider(ConfigInterface $configProvider)
5655
* @param StorageInterface $storageProvider
5756
* @return $this
5857
*/
59-
public function setStorageProvider(StorageInterface $storageProvider)
58+
public function setStorageProvider(StorageInterface $storageProvider): AuthCodeController
6059
{
6160
$this->storage = $storageProvider;
6261
return $this;
@@ -81,7 +80,7 @@ final protected function ensureExternalProvidersExist()
8180
*
8281
* @return string
8382
*/
84-
public function getRedirectUri()
83+
public function getRedirectUri(): string
8584
{
8685
$this->ensureExternalProvidersExist();
8786

@@ -97,7 +96,7 @@ public function getRedirectUri()
9796
* @throws \InvalidArgumentException
9897
* @throws \Exception
9998
*/
100-
public function startAuthorizationGrant(array $scopes)
99+
public function startAuthorizationGrant(array $scopes): string
101100
{
102101
$this->ensureExternalProvidersExist();
103102

@@ -125,7 +124,7 @@ public function startAuthorizationGrant(array $scopes)
125124
* @throws \Exception when state param is invalid
126125
* @throws \GuzzleHttp\Exception\GuzzleException
127126
*/
128-
public function completeAuthorizationGrant($authorizationCode, $state)
127+
public function completeAuthorizationGrant($authorizationCode, $state): AccessTokenModel
129128
{
130129
if (empty($authorizationCode) || !is_string($authorizationCode))
131130
{
@@ -159,7 +158,7 @@ public function completeAuthorizationGrant($authorizationCode, $state)
159158
* @internal
160159
* @return string
161160
*/
162-
private function generateOAuth2State()
161+
private function generateOAuth2State(): string
163162
{
164163
$key = mt_rand();
165164
$value = mt_rand();

src/Controllers/DeviceCodeController.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
use GuzzleHttp\Client;
66
use NPR\One\DI\DI;
77
use NPR\One\Exceptions\ApiException;
8-
use NPR\One\Models\AccessTokenModel;
9-
use NPR\One\Models\DeviceCodeModel;
10-
8+
use NPR\One\Models\{AccessTokenModel, DeviceCodeModel};
119

1210
/**
1311
* Use this controller to power your OAuth2 proxy if you are using the `device_code` grant.
@@ -29,7 +27,7 @@ class DeviceCodeController extends AbstractOAuth2Controller
2927
* @throws \Exception
3028
* @throws \GuzzleHttp\Exception\GuzzleException
3129
*/
32-
public function startDeviceCodeGrant(array $scopes)
30+
public function startDeviceCodeGrant(array $scopes): DeviceCodeModel
3331
{
3432
$this->ensureExternalProvidersExist();
3533

@@ -51,7 +49,7 @@ public function startDeviceCodeGrant(array $scopes)
5149
* @throws \Exception
5250
* @throws \GuzzleHttp\Exception\GuzzleException
5351
*/
54-
public function pollDeviceCodeGrant()
52+
public function pollDeviceCodeGrant(): AccessTokenModel
5553
{
5654
$this->ensureExternalProvidersExist();
5755

@@ -81,7 +79,7 @@ public function pollDeviceCodeGrant()
8179
* @throws \Exception
8280
* @throws \GuzzleHttp\Exception\GuzzleException
8381
*/
84-
private function createDeviceCode(array $scopes)
82+
private function createDeviceCode(array $scopes): DeviceCodeModel
8583
{
8684
/** @var Client $client */
8785
$client = DI::container()->get(Client::class);

src/Controllers/RefreshTokenController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class RefreshTokenController extends AbstractOAuth2Controller
2424
* @throws \Exception
2525
* @throws \GuzzleHttp\Exception\GuzzleException
2626
*/
27-
public function generateNewAccessTokenFromRefreshToken()
27+
public function generateNewAccessTokenFromRefreshToken(): AccessTokenModel
2828
{
2929
$this->ensureExternalProvidersExist();
3030

src/DI/DI.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
use DI\ContainerBuilder;
66
use GuzzleHttp\Client;
7-
use NPR\One\Providers\CookieProvider;
8-
use NPR\One\Providers\SecureCookieProvider;
9-
use NPR\One\Providers\EncryptionProvider;
7+
use NPR\One\Providers\{CookieProvider, SecureCookieProvider, EncryptionProvider};
108

119

1210
/**
@@ -34,11 +32,11 @@ public static function container()
3432

3533
$containerBuilder = new ContainerBuilder;
3634
$containerBuilder->addDefinitions([
37-
CookieProvider::class => \DI\object(CookieProvider::class),
38-
SecureCookieProvider::class => \DI\object(SecureCookieProvider::class),
39-
EncryptionProvider::class => \DI\object(EncryptionProvider::class),
35+
CookieProvider::class => \DI\create(CookieProvider::class),
36+
SecureCookieProvider::class => \DI\create(SecureCookieProvider::class),
37+
EncryptionProvider::class => \DI\create(EncryptionProvider::class),
4038
// Bind an interface to an implementation
41-
Client::class => \DI\object(Client::class)->constructor([
39+
Client::class => \DI\create(Client::class)->constructor([
4240
'timeout' => 5.0,
4341
'http_errors' => false
4442
]),

src/Exceptions/ApiException.php

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

33
namespace NPR\One\Exceptions;
44

5-
use GuzzleHttp\Psr7\Response;
6-
use GuzzleHttp\Psr7\Stream;
5+
use GuzzleHttp\Psr7\{Response, Stream};
76

87

98
/**
@@ -51,7 +50,7 @@ public function __construct($message, Response $response)
5150
*
5251
* @return int
5352
*/
54-
public function getStatusCode()
53+
public function getStatusCode(): int
5554
{
5655
return $this->statusCode;
5756
}
@@ -61,7 +60,7 @@ public function getStatusCode()
6160
*
6261
* @return string
6362
*/
64-
public function getStatusText()
63+
public function getStatusText(): string
6564
{
6665
return $this->statusText;
6766
}
@@ -71,7 +70,7 @@ public function getStatusText()
7170
*
7271
* @return Stream
7372
*/
74-
public function getBody()
73+
public function getBody(): Stream
7574
{
7675
return $this->body;
7776
}

0 commit comments

Comments
 (0)