Skip to content

Commit

Permalink
Merge pull request #14 from ker0x/feature/php-8.1
Browse files Browse the repository at this point in the history
Drop support for PHP < 8.1, convert SCOPE_ constants to enumeration
  • Loading branch information
ker0x committed Nov 4, 2022
2 parents 3966406 + ce64cbe commit 8d9951a
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 143 deletions.
15 changes: 7 additions & 8 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html

# Ignore all test and documentation with "export-ignore".
/.github export-ignore
/tests export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.php_cs.dist export-ignore
/.php_cs.dist export-ignore
/phpunit.xml.dist export-ignore
/.github export-ignore
/tests export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.php-cs-fixer.dist.php export-ignore
/phpunit.xml.dist export-ignore
18 changes: 11 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,33 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: [ '7.4', '8.0' ]
php-version: [ '8.1', '8.2' ]
allow-failure: [ false ]
coverage: [ false ]
composer-flags: [ '' ]
include:
- php-version: '7.3'
coverage: true
- php-version: '8.1'
coverage: true
- php-version: '8.2'
allow-failure: true
composer-flags: '--ignore-platform-req php'

steps:
- uses: actions/checkout@v2
- name: checkout
uses: actions/checkout@v3

- name: php-setup
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: xdebug

- name: composer-validate
run: composer validate

- name: composer-cache
id: composer-cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.lock') }}
Expand All @@ -53,14 +55,16 @@ jobs:
continue-on-error: ${{ matrix.allow-failure }}
env:
PHP_CS_FIXER_IGNORE_ENV: ${{ matrix.allow-failure }}
run: vendor/bin/php-cs-fixer fix --dry-run --diff --verbose --config=.php_cs.dist
run: vendor/bin/php-cs-fixer fix --dry-run --diff --verbose

- name: phpunit
env:
XDEBUG_MODE: coverage
run: composer run-script phpunit

- name: coverage
if: ${{ matrix.coverage }}
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: ./build
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
build/
vendor/
/build/
/vendor/
composer.lock
.php_cs
.php_cs.cache
.php-cs-fixer.cache
.phpunit.result.cache
phpunit.xml
15 changes: 15 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

$finder = (new PhpCsFixer\Finder())
->in(__DIR__)
;

return (new PhpCsFixer\Config())
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'declare_strict_types' => true,
])
->setRiskyAllowed(true)
->setFinder($finder)
;
37 changes: 0 additions & 37 deletions .php_cs.dist

This file was deleted.

53 changes: 31 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<img src="https://img.shields.io/codecov/c/gh/ker0x/oauth2-spotify?style=for-the-badge" alt="Coverage">
</a>
<a href="https://php.net" title="PHP Version">
<img src="https://img.shields.io/badge/php-%3E%3D%207.3-8892BF.svg?style=for-the-badge" alt="PHP Version">
<img src="https://img.shields.io/badge/php-%3E%3D%208.1-8892BF.svg?style=for-the-badge" alt="PHP Version">
</a>
<a href="https://packagist.org/packages/kerox/oauth2-spotify" title="Downloads">
<img src="https://img.shields.io/packagist/dt/kerox/oauth2-spotify.svg?style=for-the-badge" alt="Downloads">
Expand Down Expand Up @@ -52,7 +52,7 @@ if (!isset($_GET['code'])) {
// If we don't have an authorization code then get one
$authUrl = $provider->getAuthorizationUrl([
'scope' => [
Kerox\OAuth2\Client\Provider\Spotify::SCOPE_USER_READ_EMAIL,
Kerox\OAuth2\Client\Provider\SpotifyScope::USER_READ_EMAIL->value,
]
]);

Expand Down Expand Up @@ -108,26 +108,35 @@ echo '</pre>';

### Authorization Scopes

All scopes described in the [official documentation](https://developer.spotify.com/documentation/general/guides/scopes/) are available through public constants in `\Kerox\OAuth2\Client\Provider\Spotify`:

* SCOPE_UGC_IMAGE_UPLOAD
* SCOPE_USER_MODIFY_PLAYBACK_STATE
* SCOPE_USER_READ_PLAYBACK_STATE
* SCOPE_USER_READ_CURRENTLY_PLAYING
* SCOPE_USER_TOP_READ
* SCOPE_USER_READ_RECENTLY_PLAYED
* SCOPE_USER_LIBRARY_MODIFY
* SCOPE_USER_LIBRARY_READ
* SCOPE_USER_FOLLOW_MODIFY
* SCOPE_USER_FOLLOW_READ
* SCOPE_PLAYLIST_READ_PRIVATE
* SCOPE_PLAYLIST_MODIFY_PUBLIC
* SCOPE_PLAYLIST_MODIFY_PRIVATE
* SCOPE_PLAYLIST_READ_COLLABORATIVE
* SCOPE_USER_READ_PRIVATE
* SCOPE_USER_READ_EMAIL
* SCOPE_APP_REMOTE_CONTROL
* SCOPE_STREAMING
All scopes described in the [official documentation](https://developer.spotify.com/documentation/general/guides/authorization/scopes/) are available through the `\Kerox\OAuth2\Client\Provider\SpotifyScope` enumeration:

- Images
* UGC_IMAGE_UPLOAD
- Spotify Connect
* USER_READ_PLAYBACK_STATE
* USER_MODIFY_PLAYBACK_STATE
* USER_READ_CURRENTLY_PLAYING
- Playback
* APP_REMOTE_CONTROL
* STREAMING
- Playlists
* PLAYLIST_READ_PRIVATE
* PLAYLIST_READ_COLLABORATIVE
* PLAYLIST_MODIFY_PRIVATE
* PLAYLIST_MODIFY_PUBLIC
- Follow
* USER_FOLLOW_MODIFY
* USER_FOLLOW_READ
- Listening History
* USER_READ_PLAYBACK_POSITION
* USER_TOP_READ
* USER_READ_RECENTLY_PLAYED
- Library
* USER_LIBRARY_MODIFY
* USER_LIBRARY_READ
- Users
* USER_READ_PRIVATE
* USER_READ_EMAIL

## Contributing

Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
}
],
"require": {
"php": ">=7.3",
"php": ">=8.1",
"league/oauth2-client": "^2.6"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.17",
"phpunit/phpunit": "^9.0"
"friendsofphp/php-cs-fixer": "^3.0",
"phpunit/phpunit": "^9.5"
},
"config": {
"optimize-autoloader": true,
Expand All @@ -43,7 +43,7 @@
}
},
"scripts": {
"php-cs-fixer": "vendor/bin/php-cs-fixer fix --diff --verbose --config=.php_cs",
"php-cs-fixer": "vendor/bin/php-cs-fixer fix --diff --verbose",
"phpunit": "vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml"
}
}
42 changes: 3 additions & 39 deletions src/Provider/Spotify.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,45 +19,9 @@ class Spotify extends AbstractProvider
public const BASE_SPOTIFY_URL = 'https://accounts.spotify.com/';
public const RESPONSE_TYPE = 'code';

// Available scopes.

// Images
public const SCOPE_UGC_IMAGE_UPLOAD = 'ugc-image-upload';

// Spotify Connect
public const SCOPE_USER_MODIFY_PLAYBACK_STATE = 'user-modify-playback-state';
public const SCOPE_USER_READ_PLAYBACK_STATE = 'user-read-playback-state';
public const SCOPE_USER_READ_CURRENTLY_PLAYING = 'user-read-currently-playing';

// Listening History
public const SCOPE_USER_TOP_READ = 'user-top-read';
public const SCOPE_USER_READ_RECENTLY_PLAYED = 'user-read-recently-played';

// Library
public const SCOPE_USER_LIBRARY_MODIFY = 'user-library-modify';
public const SCOPE_USER_LIBRARY_READ = 'user-library-read';

// Follow
public const SCOPE_USER_FOLLOW_MODIFY = 'user-follow-modify';
public const SCOPE_USER_FOLLOW_READ = 'user-follow-read';

// Playlist
public const SCOPE_PLAYLIST_READ_PRIVATE = 'playlist-read-private';
public const SCOPE_PLAYLIST_MODIFY_PUBLIC = 'playlist-modify-public';
public const SCOPE_PLAYLIST_MODIFY_PRIVATE = 'playlist-modify-private';
public const SCOPE_PLAYLIST_READ_COLLABORATIVE = 'playlist-read-collaborative';

// User
public const SCOPE_USER_READ_PRIVATE = 'user-read-private';
public const SCOPE_USER_READ_EMAIL = 'user-read-email';

// Playback
public const SCOPE_APP_REMOTE_CONTROL = 'app-remote-control';
public const SCOPE_STREAMING = 'streaming';

public function __construct(array $options = [], array $collaborators = [])
{
if (!isset($options['responseType']) || $options['responseType'] !== self::RESPONSE_TYPE) {
if (!isset($options['responseType']) || self::RESPONSE_TYPE !== $options['responseType']) {
$options['responseType'] = self::RESPONSE_TYPE;
}

Expand All @@ -69,15 +33,15 @@ public function __construct(array $options = [], array $collaborators = [])
*/
public function getBaseAuthorizationUrl(): string
{
return self::BASE_SPOTIFY_URL . 'authorize';
return self::BASE_SPOTIFY_URL.'authorize';
}

/**
* Returns the base URL for requesting an access token.
*/
public function getBaseAccessTokenUrl(array $params): string
{
return self::BASE_SPOTIFY_URL . 'api/token';
return self::BASE_SPOTIFY_URL.'api/token';
}

/**
Expand Down
7 changes: 2 additions & 5 deletions src/Provider/SpotifyResourceOwner.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

class SpotifyResourceOwner implements ResourceOwnerInterface
{
/**
* @var array
*/
protected $data;
protected array $data;

public function __construct(array $response)
{
Expand Down Expand Up @@ -79,7 +76,7 @@ public function getUri(): string
}

/**
* Return all of the owner details available as an array.
* Return all the owner details available as an array.
*/
public function toArray(): array
{
Expand Down
43 changes: 43 additions & 0 deletions src/Provider/SpotifyScope.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace Kerox\OAuth2\Client\Provider;

enum SpotifyScope: string
{
// Images
case UGC_IMAGE_UPLOAD = 'ugc-image-upload';

// Spotify Connect
case USER_READ_PLAYBACK_STATE = 'user-read-playback-state';
case USER_MODIFY_PLAYBACK_STATE = 'user-modify-playback-state';
case USER_READ_CURRENTLY_PLAYING = 'user-read-currently-playing';

// Playback
case APP_REMOTE_CONTROL = 'app-remote-control';
case STREAMING = 'streaming';

// Playlist
case PLAYLIST_READ_PRIVATE = 'playlist-read-private';
case PLAYLIST_READ_COLLABORATIVE = 'playlist-read-collaborative';
case PLAYLIST_MODIFY_PRIVATE = 'playlist-modify-private';
case PLAYLIST_MODIFY_PUBLIC = 'playlist-modify-public';

// Follow
case USER_FOLLOW_MODIFY = 'user-follow-modify';
case USER_FOLLOW_READ = 'user-follow-read';

// Listening History
case USER_READ_PLAYBACK_POSITION = 'user-read-playback-position';
case USER_TOP_READ = 'user-top-read';
case USER_READ_RECENTLY_PLAYED = 'user-read-recently-played';

// Library
case USER_LIBRARY_MODIFY = 'user-library-modify';
case USER_LIBRARY_READ = 'user-library-read';

// User
case USER_READ_PRIVATE = 'user-read-private';
case USER_READ_EMAIL = 'user-read-email';
}
9 changes: 3 additions & 6 deletions tests/Provider/SpotifyResourceOwnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@

class SpotifyResourceOwnerTest extends TestCase
{
/**
* @var \Kerox\OAuth2\Client\Provider\SpotifyResourceOwner
*/
protected $resourceOwner;
protected SpotifyResourceOwner $resourceOwner;

protected function setUp(): void
{
$user = json_decode(file_get_contents(__DIR__ . '/../Mocks/user.json'), true, 512, \JSON_THROW_ON_ERROR);
$user = json_decode(file_get_contents(__DIR__.'/../Mocks/user.json'), true, 512, \JSON_THROW_ON_ERROR);

$this->resourceOwner = new SpotifyResourceOwner($user);
}
Expand Down Expand Up @@ -45,7 +42,7 @@ public function testGetter(): void

public function testToArray(): void
{
$array = json_decode(file_get_contents(__DIR__ . '/../Mocks/user.json'), true, 512, \JSON_THROW_ON_ERROR);
$array = json_decode(file_get_contents(__DIR__.'/../Mocks/user.json'), true, 512, \JSON_THROW_ON_ERROR);

self::assertSame($array, $this->resourceOwner->toArray());
}
Expand Down
Loading

0 comments on commit 8d9951a

Please sign in to comment.