Skip to content

Commit

Permalink
require php8.1 (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
qdequippe authored Jun 20, 2024
1 parent 8ff4f90 commit dfae9fd
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 129 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CI

on:
push:
branches: [ master ]
branches: [ main ]
pull_request:

jobs:
Expand All @@ -14,23 +14,21 @@ jobs:
- name: 'Setup PHP'
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.1'

- uses: "ramsey/composer-install@v3"
with:
composer-options: "--prefer-dist"

- name: Code Sniffer
run: vendor/bin/phpcs --standard=psr2 src/
- name: PHP CS Fixer
run: ./vendor/bin/php-cs-fixer check src

test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-version:
- "7.4"
- "8.0"
- "8.1"
- "8.2"
- "8.3"
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
composer.lock
.phpunit.result.cache
/build/
.phpunit.cache
.php-cs-fixer.cache
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
],
"require": {
"league/oauth2-client": "^2.0",
"ext-dom": "*"
"ext-dom": "*",
"php": ">=8.1"
},
"require-dev": {
"mockery/mockery": "^1.3",
"squizlabs/php_codesniffer": "^3.5",
"phpunit/phpunit": ">=8.0 < 10"
"phpunit/phpunit": ">=8.0",
"friendsofphp/php-cs-fixer": "^3.59"
},
"autoload": {
"psr-4": {
Expand All @@ -35,7 +36,7 @@
},
"autoload-dev": {
"psr-4": {
"Qdequippe\\OAuth2\\Client\\Test\\": "tests/src/"
"Qdequippe\\OAuth2\\Client\\Test\\": "tests/"
}
},
"extra": {
Expand Down
14 changes: 6 additions & 8 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
verbose="true">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.2/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" cacheDirectory=".phpunit.cache">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/coverage"/>
Expand All @@ -22,4 +15,9 @@
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
52 changes: 9 additions & 43 deletions src/Provider/SymfonyConnect.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,65 +4,39 @@

use League\OAuth2\Client\Provider\AbstractProvider;
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
use League\OAuth2\Client\Provider\ResourceOwnerInterface;
use League\OAuth2\Client\Token\AccessToken;
use Psr\Http\Message\ResponseInterface;

class SymfonyConnect extends AbstractProvider
{
protected string $api = 'https://connect.symfony.com';

protected $api = 'https://connect.symfony.com';

/**
* @return string
*/
#[\ReturnTypeWillChange]
public function getBaseAuthorizationUrl()
public function getBaseAuthorizationUrl(): string
{
return $this->api . '/oauth/authorize';
}

/**
* @return string
*/
#[\ReturnTypeWillChange]
public function getBaseAccessTokenUrl(array $params)
public function getBaseAccessTokenUrl(array $params): string
{
return $this->api . '/oauth/access_token';
}

/**
* @return string
*/
#[\ReturnTypeWillChange]
public function getResourceOwnerDetailsUrl(AccessToken $token)
public function getResourceOwnerDetailsUrl(AccessToken $token): string
{
return $this->api . '/api?access_token='.$token->getToken();
}

/**
* @return string
*/
#[\ReturnTypeWillChange]
protected function getScopeSeparator()
protected function getScopeSeparator(): string
{
return ' ';
}

/**
* @return array
*/
#[\ReturnTypeWillChange]
protected function getDefaultScopes()
protected function getDefaultScopes(): array
{
return ['SCOPE_PUBLIC'];
}

/**
* @return array
*/
#[\ReturnTypeWillChange]
protected function parseResponse(ResponseInterface $response)
protected function parseResponse(ResponseInterface $response): array
{
$type = $this->getContentType($response);

Expand All @@ -73,11 +47,7 @@ protected function parseResponse(ResponseInterface $response)
return ['xml' => (string)$response->getBody()];
}

/**
* @return void
*/
#[\ReturnTypeWillChange]
protected function checkResponse(ResponseInterface $response, $data)
protected function checkResponse(ResponseInterface $response, $data): void
{
if ($response->getStatusCode() >= 400) {
throw new IdentityProviderException(
Expand All @@ -88,11 +58,7 @@ protected function checkResponse(ResponseInterface $response, $data)
}
}

/**
* @return ResourceOwnerInterface
*/
#[\ReturnTypeWillChange]
protected function createResourceOwner(array $response, AccessToken $token)
protected function createResourceOwner(array $response, AccessToken $token): SymfonyConnectResourceOwner
{
return new SymfonyConnectResourceOwner($response);
}
Expand Down
38 changes: 17 additions & 21 deletions src/Provider/SymfonyConnectResourceOwner.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,8 @@

class SymfonyConnectResourceOwner implements ResourceOwnerInterface
{
/**
* @var \DOMElement
*/
private $data;

/**
* @var \DOMXpath
*/
private $xpath;
private \DOMElement|null|\DOMNode $data;
private \DOMXpath $xpath;

public function __construct($response)
{
Expand All @@ -35,15 +28,12 @@ public function __construct($response)
$this->data = $user->item(0);
}

/**
* @return mixed
**/
public function getId()
public function getId(): ?string
{
return $this->data->attributes->getNamedItem('id')->value;
}

public function getUsername()
public function getUsername(): ?string
{
$accounts = $this->xpath->query('./foaf:account/foaf:OnlineAccount', $this->data);
for ($i = 0; $i < $accounts->length; ++$i) {
Expand All @@ -56,22 +46,22 @@ public function getUsername()
return null;
}

public function getName()
public function getName(): ?string
{
return $this->getUsername() ?: $this->getNodeValue('./foaf:name', $this->data);
}

public function getEmail()
public function getEmail(): ?string
{
return $this->getNodeValue('./foaf:mbox', $this->data);
}

public function getProfilePicture()
public function getProfilePicture(): ?string
{
return $this->getLinkNodeHref('./atom:link[@rel="foaf:depiction"]', $this->data);
}

public function getData()
public function getData(): \DOMNode|\DOMElement|null
{
return $this->data;
}
Expand All @@ -97,23 +87,29 @@ public function toArray(): array
];
}

protected function getNodeValue($query, \DOMNode $element = null, $index = 0)
protected function getNodeValue($query, \DOMNode $element = null, $index = 0): mixed
{
$nodeList = $this->xpath->query($query, $element);

if ($nodeList->length > 0 && $index <= $nodeList->length) {
return $this->sanitizeValue($nodeList->item($index)->nodeValue);
}

return null;
}

protected function getLinkNodeHref($query, \DOMNode $element = null, $position = 0)
protected function getLinkNodeHref($query, \DOMNode $element = null, $position = 0): mixed
{
$nodeList = $this->xpath->query($query, $element);

if ($nodeList && $nodeList->length > 0 && $nodeList->item($position)) {
return $this->sanitizeValue($nodeList->item($position)->attributes->getNamedItem('href')->value);
}

return null;
}

protected function sanitizeValue($value)
protected function sanitizeValue(mixed $value): mixed
{
if ('true' === $value) {
return true;
Expand Down
Loading

0 comments on commit dfae9fd

Please sign in to comment.