Skip to content

Commit

Permalink
Merge pull request #8 from kangaroodev/master
Browse files Browse the repository at this point in the history
Upgrade to PHP 8.1
  • Loading branch information
ursuleacv authored Dec 5, 2024
2 parents e3def50 + 2440d6e commit 4a0db05
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 66 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/build
/vendor
composer.phar
composer.lock
composer.lock
.phpunit.result.cache
15 changes: 4 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@ language: php

matrix:
include:
- php: 7.0
- php: 7.1
- php: 7.2
- php: 8.1
- php: 8.2
- php: 8.3
- php: 8.4
- php: nightly
- php: hhvm-3.15
sudo: required
dist: trusty
group: edge
- php: hhvm-nightly
sudo: required
dist: trusty
group: edge
fast_finish: true
allow_failures:
- php: nightly
Expand Down
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ This package is compliant with [PSR-1][], [PSR-2][], [PSR-4][], and [PSR-7][]. I

The following versions of PHP are supported.

* PHP 7.0
* PHP 7.1
* PHP 7.2
* PHP 8.1
* PHP 8.2
* PHP 8.3
* PHP 8.4
* HHVM

## Installation
Expand All @@ -28,7 +29,7 @@ Add the following to your `composer.json` file.
```json
{
"require": {
"ursuleacv/oauth2-lightspeed": "~2.0"
"ursuleacv/oauth2-lightspeed": "~3.0"
}
}
```
Expand Down Expand Up @@ -102,6 +103,12 @@ echo '</pre>';
$ ./vendor/bin/phpunit
```

## Upgrading

```bash
vendor/bin/rector process src --dry-run
```

## Contributing

Please see [CONTRIBUTING](https://github.com/ursuleacv/oauth2-lightspeed/blob/master/CONTRIBUTING.md) for details.
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
{
"name": "Valentin Ursuleac",
"email": "[email protected]",
"homepage": "http://valnet.ca",
"role": "Developer"
"role": "Software Developer"
}
],
"keywords": [
Expand All @@ -19,16 +18,17 @@
"LightSpeed"
],
"require": {
"php": ">=5.6.0",
"php": ">=8.1.0",
"ext-curl": "*",
"ext-json": "*",
"league/oauth2-client": "~2.0",
"guzzlehttp/guzzle": "~6.0"
"guzzlehttp/guzzle": "^7.0"
},
"require-dev": {
"phpunit/phpunit": "~6.0",
"phpunit/phpunit": "~10.0",
"mockery/mockery": "~1.0",
"squizlabs/php_codesniffer": "^3.4"
"squizlabs/php_codesniffer": "^3.4",
"rector/rector": "^1.2"
},
"autoload": {
"psr-4": {
Expand Down
5 changes: 0 additions & 5 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Package Test Suite">
Expand Down
18 changes: 18 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\PHPUnit\Set\PHPUnitSetList;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->withSets([
PHPUnitSetList::PHPUNIT_100,
])
// uncomment to reach your current PHP version
->withPhpSets(php81: true)
->withTypeCoverageLevel(0);
2 changes: 1 addition & 1 deletion src/Grant/LsExchangeToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class LsExchangeToken extends AbstractGrant
{
public function __toString()
public function __toString(): string
{
return 'ls_exchange_token';
}
Expand Down
11 changes: 6 additions & 5 deletions src/Provider/Lightspeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use InvalidArgumentException;
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
use League\OAuth2\Client\Token\AccessToken;
use League\OAuth2\Client\Token\AccessTokenInterface;
use Psr\Http\Message\ResponseInterface;

class Lightspeed extends AbstractProvider
Expand Down Expand Up @@ -39,12 +40,12 @@ public function getBaseAuthorizationUrl()
* @param array $params
* @return string
*/
public function getBaseAccessTokenUrl(array $params)
public function getBaseAccessTokenUrl(array $params): string
{
return static::LIGHTSPEED_TOKEN_ENDPOINT;
}

public function getDefaultScopes()
public function getDefaultScopes(): array
{
return ['employee:all'];
}
Expand All @@ -54,7 +55,7 @@ public function getDefaultScopes()
* @param array $params
* @return AccessToken
*/
public function getAccessToken($grant = 'authorization_code', array $params = [])
public function getAccessToken($grant = 'authorization_code', array $params = []): AccessTokenInterface
{
return parent::getAccessToken($grant, $params);
}
Expand All @@ -66,7 +67,7 @@ public function getAccessToken($grant = 'authorization_code', array $params = []
*
* @return \League\OAuth2\Client\Token\AccessToken
*/
public function getLongLivedAccessToken($accessToken)
public function getLongLivedAccessToken($accessToken): AccessTokenInterface
{
$params = [
'ls_exchange_token' => (string) $accessToken,
Expand All @@ -90,7 +91,7 @@ public function getAccountId(AccessToken $token)
* @param AccessToken $token
* @return mixed
*/
public function getResourceOwnerDetailsUrl(AccessToken $token)
public function getResourceOwnerDetailsUrl(AccessToken $token): string
{
return $this->getBaseLightspeedApiUrl() . 'Account/.json?oauth_token=' . $token;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/LightspeedResourceOwner.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class LightspeedResourceOwner implements ResourceOwnerInterface
*
* @param array $response
*/
public function __construct(array $response = array())
public function __construct(array $response = [])
{
$this->response = $response;
}
Expand Down
26 changes: 6 additions & 20 deletions src/Provider/MerchantOS.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ class MerchantOS extends Lightspeed
*/
private $oauthToken;

/**
* @var mixed
*/
protected $accountId;

/**
* @var string
*/
Expand Down Expand Up @@ -50,10 +45,9 @@ class MerchantOS extends Lightspeed
* @param AccessToken $token
* @param mixed $accountId
*/
public function __construct(AccessToken $token, $accountId)
public function __construct(AccessToken $token, protected $accountId)
{
$this->oauthToken = $token->getToken();
$this->accountId = $accountId;
}

/**
Expand Down Expand Up @@ -1040,11 +1034,7 @@ public function getConfig()
{
$response = $this->makeAPICall('Account.Config', 'GET', null, [], []);

if (isset($response['Config'])) {
return $response['Config'];
}

return [];
return $response['Config'] ?? [];
}

/**
Expand All @@ -1068,11 +1058,7 @@ public function getLocale()
{
$response = $this->makeAPICall('Locale', 'GET', null, [], []);

if (isset($response['Locale'])) {
return $response['Locale'];
}

return [];
return $response['Locale'] ?? [];
}

/**
Expand All @@ -1094,7 +1080,7 @@ public function makeAPICall($controlUrl, $action, $uniqueId, $params, $data)
$url = $this->prepareApiUrl($controlUrl, $this->accountId, $uniqueId, $params);

$this->context['apiCall'] = $url;
$this->context['action'] = strtoupper($action);
$this->context['action'] = strtoupper((string) $action);

$headers = [
'User-Agent' => $this->userAgent,
Expand Down Expand Up @@ -1175,7 +1161,7 @@ protected function buildQueryString(array $data)
} else {
$qs = '';
foreach ($data as $key => $value) {
$append = urlencode($key) . '=' . urlencode($value);
$append = urlencode($key) . '=' . urlencode((string) $value);
$qs .= $qs ? '&' . $append : $append;
}
return $qs;
Expand Down Expand Up @@ -1231,7 +1217,7 @@ protected function sleepIfNecessary()

$bucketLevelStr = $headers['X-LS-API-Bucket-Level'][0];

list($currentLevel, $bucketSize) = explode('/', $bucketLevelStr);
[$currentLevel, $bucketSize] = explode('/', (string) $bucketLevelStr);

//The drip rate is calculated by dividing the bucket size by 60 seconds.
$dripRate = $bucketSize / 60;
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Provider/LightspeedResourceOwnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class LightspeedResourceOwnerTest extends \PHPUnit\Framework\TestCase
*/
protected $account;

protected function setUp()
protected function setUp(): void
{
$arr = [
'[@attributes' => [
Expand Down
38 changes: 27 additions & 11 deletions tests/src/Provider/LightspeedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use League\OAuth2\Client\Provider\Lightspeed;
use League\OAuth2\Client\Token\AccessToken;
use Psr\Http\Message\StreamInterface;
use Mockery as m;

class FooLightspeedProvider extends Lightspeed
Expand All @@ -22,7 +23,7 @@ class LightspeedTest extends \PHPUnit\Framework\TestCase
*/
protected $provider;

protected function setUp()
protected function setUp(): void
{
$this->provider = new Lightspeed([
'clientId' => 'mock_client_id',
Expand All @@ -31,7 +32,7 @@ protected function setUp()
]);
}

public function tearDown()
public function tearDown(): void
{
m::close();
parent::tearDown();
Expand Down Expand Up @@ -62,15 +63,23 @@ public function testGetBaseAccessTokenUrl()

public function testGetAccessToken()
{
$response = m::mock('Psr\Http\Message\ResponseInterface');
$stream = $this->createMock(StreamInterface::class);
$stream
->method('__toString')
->willReturn('{"access_token":"mock_access_token","token_type":"bearer","expires_in":3600}');

$response = m::mock(\Psr\Http\Message\ResponseInterface::class);
$response->shouldReceive('getHeader')
->times(1)
->andReturn('application/json');
// ->andReturn('application/json');
->andReturn(['Content-Type' => 'application/json']);
$response->shouldReceive('getBody')
->times(1)
->andReturn('{"access_token":"mock_access_token","token_type":"bearer","expires_in":3600}');
// ->andReturn('{"access_token":"mock_access_token","token_type":"bearer","expires_in":3600}');
// ->andReturn(m::mock(StreamInterface::class, ['getContents' => '{"access_token":"long-lived-token","token_type":"bearer","expires_in":3600}']));
->andReturn($stream);

$client = m::mock('GuzzleHttp\ClientInterface');
$client = m::mock(\GuzzleHttp\ClientInterface::class);
$client->shouldReceive('send')->times(1)->andReturn($response);
$this->provider->setHttpClient($client);

Expand All @@ -85,15 +94,22 @@ public function testGetAccessToken()

public function testCanGetALongLivedAccessTokenFromShortLivedOne()
{
$response = m::mock('Psr\Http\Message\ResponseInterface');
$stream = $this->createMock(StreamInterface::class);
$stream
->method('__toString')
->willReturn('{"access_token":"long-lived-token","token_type":"bearer","expires_in":3600}');

$response = m::mock(\Psr\Http\Message\ResponseInterface::class);
$response->shouldReceive('getHeader')
->times(1)
->andReturn('application/json');
// ->andReturn('application/json');
->andReturn(['Content-Type' => 'application/json']);
$response->shouldReceive('getBody')
->times(1)
->andReturn('{"access_token":"long-lived-token","token_type":"bearer","expires_in":3600}');
// ->andReturn('{"access_token":"long-lived-token","token_type":"bearer","expires_in":3600}');
->andReturn($stream);

$client = m::mock('GuzzleHttp\ClientInterface');
$client = m::mock(\GuzzleHttp\ClientInterface::class);
$client->shouldReceive('send')->times(1)->andReturn($response);
$this->provider->setHttpClient($client);

Expand All @@ -111,7 +127,7 @@ public function testAccountData()
{
$provider = new FooLightspeedProvider();

$token = m::mock('League\OAuth2\Client\Token\AccessToken');
$token = m::mock(\League\OAuth2\Client\Token\AccessToken::class);
$account = $provider->getResourceOwner($token);

$this->assertEquals(12345, $account->getId($token));
Expand Down

0 comments on commit 4a0db05

Please sign in to comment.