Skip to content

Commit

Permalink
Feature update php (#18)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
kristen-kagei authored Nov 12, 2019
1 parent 2a45f08 commit 12527a5
Show file tree
Hide file tree
Showing 30 changed files with 376 additions and 256 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ vendor/

# PHPUnit Results & Code Coverage
test-results/
.phpunit.result.cache

# PHPDoc
build/
Expand Down
10 changes: 4 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
sudo: false
language: php
php:
- '5.6'
- '7.0'
- '7.1'
- '7.2'
- hhvm
- '7.3'
- '7.4'
notifications:
email: false
slack:
slack: true
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=
before_script:
- composer require phpunit/phpunit:4.8.* php-coveralls/php-coveralls
- composer require phpunit/phpunit:8.3 php-coveralls/php-coveralls
- composer install --no-interaction
script: vendor/bin/phpunit
after_script:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ This project is designed to be executed in a server environment with [Apache HTT

### Prerequisites

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

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.)

Expand Down
11 changes: 7 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@
}
},
"require": {
"php": ">=5.6.0",
"php": ">=7.2.0",
"guzzlehttp/guzzle": "~6.0",
"php-di/php-di": "^5.2"
"php-di/php-di": "^6.0"
},
"require-dev": {
"phpunit/phpunit": "4.8.*",
"phpunit/phpunit": "^8",
"phpdocumentor/phpdocumentor": "2.*",
"evert/phpdoc-md": "0.2.0",
"phly/changelog-generator": "^2.1"
}
},
"scripts": {
"test:unit": "./vendor/bin/phpunit tests/unit --verbose"
}
}
8 changes: 2 additions & 6 deletions examples/Router.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
<?php

use Illuminate\Http\Response;
use NPR\One\Controllers\AuthCodeController;
use NPR\One\Controllers\DeviceCodeController;
use NPR\One\Controllers\LogoutController;
use NPR\One\Controllers\RefreshTokenController;
use NPR\One\Controllers\{AuthCodeController, DeviceCodeController, LogoutController, RefreshTokenController};
use NPR\One\Exceptions\ApiException;
use Your\Package\Here\ConfigProvider;
use Your\Package\Here\StorageProvider;
use Your\Package\Here\{ConfigProvider, StorageProvider};


/**
Expand Down
5 changes: 2 additions & 3 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
stopOnFailure="false">
<testsuites>
<testsuite name="Backend Proxy Test Suite">
<directory suffix=".php">./tests/</directory>
Expand All @@ -24,6 +23,6 @@
</filter>
<logging>
<log type="coverage-clover" target="test-results/coverage.xml"/>
<log type="junit" target="test-results/junit.xml" logIncompleteSkipped="false"/>
<log type="junit" target="test-results/junit.xml"/>
</logging>
</phpunit>
22 changes: 9 additions & 13 deletions src/Controllers/AbstractOAuth2Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@
use GuzzleHttp\Client;
use NPR\One\DI\DI;
use NPR\One\Exceptions\ApiException;
use NPR\One\Interfaces\ConfigInterface;
use NPR\One\Interfaces\EncryptionInterface;
use NPR\One\Interfaces\StorageInterface;
use NPR\One\Interfaces\{ConfigInterface, EncryptionInterface, StorageInterface};
use NPR\One\Models\AccessTokenModel;
use NPR\One\Providers\CookieProvider;
use NPR\One\Providers\EncryptionProvider;
use NPR\One\Providers\SecureCookieProvider;
use NPR\One\Providers\{CookieProvider, EncryptionProvider, SecureCookieProvider};


/**
Expand Down Expand Up @@ -64,7 +60,7 @@ public function __construct()
*
* @return string[]
*/
public function getHeaders()
public function getHeaders(): array
{
return $this->headers;
}
Expand All @@ -76,7 +72,7 @@ public function getHeaders()
* @param ConfigInterface $configProvider
* @return $this
*/
public function setConfigProvider(ConfigInterface $configProvider)
public function setConfigProvider(ConfigInterface $configProvider): AbstractOAuth2Controller
{
$this->config = $configProvider;
return $this;
Expand All @@ -90,7 +86,7 @@ public function setConfigProvider(ConfigInterface $configProvider)
* @param StorageInterface $storageProvider
* @return $this
*/
public function setSecureStorageProvider(StorageInterface $storageProvider)
public function setSecureStorageProvider(StorageInterface $storageProvider): AbstractOAuth2Controller
{
$this->secureStorage = $storageProvider;
return $this;
Expand All @@ -105,7 +101,7 @@ public function setSecureStorageProvider(StorageInterface $storageProvider)
* @param EncryptionInterface $encryptionProvider
* @return $this
*/
public function setEncryptionProvider(EncryptionInterface $encryptionProvider)
public function setEncryptionProvider(EncryptionInterface $encryptionProvider): AbstractOauth2Controller
{
$this->encryption = $encryptionProvider;
return $this;
Expand Down Expand Up @@ -162,7 +158,7 @@ protected function ensureExternalProvidersExist()
* @internal
* @return ConfigInterface
*/
final protected function getConfigProvider()
final protected function getConfigProvider(): ConfigInterface
{
return $this->config;
}
Expand All @@ -173,7 +169,7 @@ final protected function getConfigProvider()
* @internal
* @return StorageInterface
*/
final protected function getSecureStorageProvider()
final protected function getSecureStorageProvider(): StorageInterface
{
return $this->secureStorage;
}
Expand Down Expand Up @@ -214,7 +210,7 @@ final protected function validateScopes(array $scopes)
* @throws \Exception
* @throws \GuzzleHttp\Exception\GuzzleException
*/
final protected function createAccessToken($grantType, $additionalParams = [])
final protected function createAccessToken($grantType, $additionalParams = []): AccessTokenModel
{
if (empty($grantType) || !is_string($grantType))
{
Expand Down
15 changes: 7 additions & 8 deletions src/Controllers/AuthCodeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
namespace NPR\One\Controllers;

use NPR\One\DI\DI;
use NPR\One\Interfaces\ConfigInterface;
use NPR\One\Interfaces\StorageInterface;
use NPR\One\Interfaces\{ConfigInterface, StorageInterface};
use NPR\One\Models\AccessTokenModel;
use NPR\One\Providers\CookieProvider;

Expand Down Expand Up @@ -42,7 +41,7 @@ public function __construct()
/**
* {@inheritdoc}
*/
public function setConfigProvider(ConfigInterface $configProvider)
public function setConfigProvider(ConfigInterface $configProvider): AbstractOAuth2Controller
{
parent::setConfigProvider($configProvider);
$this->cookies->setDomain($configProvider->getCookieDomain());
Expand All @@ -56,7 +55,7 @@ public function setConfigProvider(ConfigInterface $configProvider)
* @param StorageInterface $storageProvider
* @return $this
*/
public function setStorageProvider(StorageInterface $storageProvider)
public function setStorageProvider(StorageInterface $storageProvider): AuthCodeController
{
$this->storage = $storageProvider;
return $this;
Expand All @@ -81,7 +80,7 @@ final protected function ensureExternalProvidersExist()
*
* @return string
*/
public function getRedirectUri()
public function getRedirectUri(): string
{
$this->ensureExternalProvidersExist();

Expand All @@ -97,7 +96,7 @@ public function getRedirectUri()
* @throws \InvalidArgumentException
* @throws \Exception
*/
public function startAuthorizationGrant(array $scopes)
public function startAuthorizationGrant(array $scopes): string
{
$this->ensureExternalProvidersExist();

Expand Down Expand Up @@ -125,7 +124,7 @@ public function startAuthorizationGrant(array $scopes)
* @throws \Exception when state param is invalid
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function completeAuthorizationGrant($authorizationCode, $state)
public function completeAuthorizationGrant($authorizationCode, $state): AccessTokenModel
{
if (empty($authorizationCode) || !is_string($authorizationCode))
{
Expand Down Expand Up @@ -159,7 +158,7 @@ public function completeAuthorizationGrant($authorizationCode, $state)
* @internal
* @return string
*/
private function generateOAuth2State()
private function generateOAuth2State(): string
{
$key = mt_rand();
$value = mt_rand();
Expand Down
10 changes: 4 additions & 6 deletions src/Controllers/DeviceCodeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
use GuzzleHttp\Client;
use NPR\One\DI\DI;
use NPR\One\Exceptions\ApiException;
use NPR\One\Models\AccessTokenModel;
use NPR\One\Models\DeviceCodeModel;

use NPR\One\Models\{AccessTokenModel, DeviceCodeModel};

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

Expand All @@ -51,7 +49,7 @@ public function startDeviceCodeGrant(array $scopes)
* @throws \Exception
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function pollDeviceCodeGrant()
public function pollDeviceCodeGrant(): AccessTokenModel
{
$this->ensureExternalProvidersExist();

Expand Down Expand Up @@ -81,7 +79,7 @@ public function pollDeviceCodeGrant()
* @throws \Exception
* @throws \GuzzleHttp\Exception\GuzzleException
*/
private function createDeviceCode(array $scopes)
private function createDeviceCode(array $scopes): DeviceCodeModel
{
/** @var Client $client */
$client = DI::container()->get(Client::class);
Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/RefreshTokenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class RefreshTokenController extends AbstractOAuth2Controller
* @throws \Exception
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function generateNewAccessTokenFromRefreshToken()
public function generateNewAccessTokenFromRefreshToken(): AccessTokenModel
{
$this->ensureExternalProvidersExist();

Expand Down
12 changes: 5 additions & 7 deletions src/DI/DI.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

use DI\ContainerBuilder;
use GuzzleHttp\Client;
use NPR\One\Providers\CookieProvider;
use NPR\One\Providers\SecureCookieProvider;
use NPR\One\Providers\EncryptionProvider;
use NPR\One\Providers\{CookieProvider, SecureCookieProvider, EncryptionProvider};


/**
Expand Down Expand Up @@ -34,11 +32,11 @@ public static function container()

$containerBuilder = new ContainerBuilder;
$containerBuilder->addDefinitions([
CookieProvider::class => \DI\object(CookieProvider::class),
SecureCookieProvider::class => \DI\object(SecureCookieProvider::class),
EncryptionProvider::class => \DI\object(EncryptionProvider::class),
CookieProvider::class => \DI\create(CookieProvider::class),
SecureCookieProvider::class => \DI\create(SecureCookieProvider::class),
EncryptionProvider::class => \DI\create(EncryptionProvider::class),
// Bind an interface to an implementation
Client::class => \DI\object(Client::class)->constructor([
Client::class => \DI\create(Client::class)->constructor([
'timeout' => 5.0,
'http_errors' => false
]),
Expand Down
9 changes: 4 additions & 5 deletions src/Exceptions/ApiException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

namespace NPR\One\Exceptions;

use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Psr7\Stream;
use GuzzleHttp\Psr7\{Response, Stream};


/**
Expand Down Expand Up @@ -51,7 +50,7 @@ public function __construct($message, Response $response)
*
* @return int
*/
public function getStatusCode()
public function getStatusCode(): int
{
return $this->statusCode;
}
Expand All @@ -61,7 +60,7 @@ public function getStatusCode()
*
* @return string
*/
public function getStatusText()
public function getStatusText(): string
{
return $this->statusText;
}
Expand All @@ -71,7 +70,7 @@ public function getStatusText()
*
* @return Stream
*/
public function getBody()
public function getBody(): Stream
{
return $this->body;
}
Expand Down
Loading

0 comments on commit 12527a5

Please sign in to comment.