Skip to content

Commit

Permalink
Merge pull request #11 from arueckauer/chore/dependencies-upgrade-and…
Browse files Browse the repository at this point in the history
…-code-cleanup

Chore: dependencies upgrade and code cleanup
  • Loading branch information
arueckauer committed Nov 22, 2023
2 parents 773e53c + 830198c commit 4d01656
Show file tree
Hide file tree
Showing 35 changed files with 392 additions and 249 deletions.
60 changes: 33 additions & 27 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
{
"name": "arueckauer/okta-client",
"type": "library",
"description": "PHP client for Core Okta API",
"license": "BSD-3-Clause",
"type": "library",
"keywords": [
"okta",
"okta-api",
"okta-client",
"client"
],
"homepage": "https://github.com/arueckauer/okta-client",
"license": "BSD-3-Clause",
"authors": [
{
"name": "Andi Rückauer",
Expand All @@ -18,46 +17,53 @@
"role": "Project Lead"
}
],
"homepage": "https://github.com/arueckauer/okta-client",
"require": {
"php": "~8.1.0",
"ext-json": "*",
"guzzlehttp/guzzle": "~7.5.0",
"laminas/laminas-config-aggregator": "^1.7",
"laminas/laminas-servicemanager": "^3.10",
"symfony/console": "^5.3"
"guzzlehttp/guzzle": "^7.5",
"laminas/laminas-config-aggregator": "^1.14",
"laminas/laminas-servicemanager": "^3.22",
"symfony/console": "^6.3"
},
"require-dev": {
"laminas/laminas-coding-standard": "^2.3",
"phpunit/phpunit": "^9.5",
"ergebnis/composer-normalize": "^2.39",
"laminas/laminas-coding-standard": "^2.5",
"phpunit/phpunit": "^10.4",
"rector/rector": "^0.18.10",
"roave/security-advisories": "dev-latest",
"vimeo/psalm": "^4.11"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
},
"sort-packages": true
},
"extra": {
"laminas": {
"config-provider": [
"OktaClient\\ConfigProvider"
]
}
"vimeo/psalm": "^5.15"
},
"minimum-stability": "stable",
"prefer-stable": true,
"autoload": {
"psr-4": {
"OktaClient\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"OktaClientTest\\": "test"
"OktaClientTest\\": "test/unit"
}
},
"minimum-stability": "stable",
"prefer-stable": true,
"bin": [
"bin/okta-client"
]
],
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"ergebnis/composer-normalize": true
},
"audit": {
"abandoned": "report"
},
"sort-packages": true
},
"extra": {
"laminas": {
"config-provider": [
"OktaClient\\ConfigProvider"
]
}
}
}
34 changes: 15 additions & 19 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,23 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
convertDeprecationsToExceptions="true"
failOnRisky="true"
failOnWarning="true"
verbose="true"
colors="true">
<testsuites>
<testsuite name="default">
<directory>test</directory>
</testsuite>
</testsuites>

<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
colors="true"
cacheDirectory=".phpunit.cache"
requireCoverageMetadata="true"
beStrictAboutCoverageMetadata="true">
<testsuites>
<testsuite name="default">
<directory>test</directory>
</testsuite>
</testsuites>
<coverage/>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
4 changes: 2 additions & 2 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.10.0@916b098b008f6de4543892b1e0651c1c3b92cbfa">
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352">
<file src="src/Request/GenericFactory.php">
<InvalidStringClass occurrences="1">
<InvalidStringClass>
<code>new $requestedName($client)</code>
</InvalidStringClass>
</file>
Expand Down
3 changes: 3 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
errorBaseline="psalm-baseline.xml"
findUnusedBaselineEntry="true"
findUnusedCode="false"
>
<projectFiles>
<directory name="src" />
<directory name="test" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
Expand Down
19 changes: 19 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

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

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/test',
]);

$rectorConfig->sets([
LevelSetList::UP_TO_PHP_81,
PHPUnitSetList::PHPUNIT_100,
]);
};
11 changes: 4 additions & 7 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@

class Client
{
private HttpClient $client;
private string $apiKey;

public function __construct(HttpClient $client, string $apiKey)
{
$this->client = $client;
$this->apiKey = $apiKey;
public function __construct(
private readonly HttpClient $client,
private readonly string $apiKey,
) {
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/ClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
namespace OktaClient;

use GuzzleHttp\Client as HttpClient;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;

use function assert;
use function is_array;

class ClientFactory
{
/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function __invoke(ContainerInterface $container): Client
{
$config = $container->get('config')[Client::class] ?? [];
Expand Down
7 changes: 7 additions & 0 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

namespace OktaClient;

/**
* @psalm-type _Configuration = array{
* dependencies: array{
* factories: array<class-string, class-string>
* }
* }
*/
class ConfigProvider
{
public function __invoke(): array
Expand Down
28 changes: 15 additions & 13 deletions src/Dto/GroupMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@

class GroupMember
{
public string $id = '';
public string $status = '';
public string $firstName = '';
public string $lastName = '';
public string $email = '';
public function __construct(
public readonly string $id,
public readonly string $status,
public readonly string $firstName,
public readonly string $lastName,
public readonly string $email
) {
}

public static function fromArray(array $input): self
{
$self = new self();
$self->id = (string) ($input['id'] ?? '');
$self->status = (string) ($input['status'] ?? '');
$self->firstName = (string) ($input['profile']['firstName'] ?? '');
$self->lastName = (string) ($input['profile']['lastName'] ?? '');
$self->email = (string) ($input['profile']['email'] ?? '');

return $self;
return new self(
(string) ($input['id'] ?? ''),
(string) ($input['status'] ?? ''),
(string) ($input['profile']['firstName'] ?? ''),
(string) ($input['profile']['lastName'] ?? ''),
(string) ($input['profile']['email'] ?? ''),
);
}
}
6 changes: 5 additions & 1 deletion src/Dto/GroupMemberCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace OktaClient\Dto;

use JsonException;
use Psr\Http\Message\ResponseInterface;

use function json_decode;
Expand All @@ -20,11 +21,14 @@ public function __construct(GroupMember ...$data)
$this->data = $data;
}

/**
* @throws JsonException
*/
public static function fromResponse(ResponseInterface $response): self
{
/** @var array $payload */
$payload = json_decode(
(string) $response->getBody(),
$response->getBody()->getContents(),
true,
512,
JSON_THROW_ON_ERROR
Expand Down
20 changes: 11 additions & 9 deletions src/Dto/UserGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@

class UserGroup
{
public string $id = '';
public string $type = '';
public string $profileName = '';
public function __construct(
public readonly string $id,
public readonly string $type,
public readonly string $profileName
) {
}

public static function fromArray(array $input): self
{
$self = new self();
$self->id = isset($input['id']) ? (string) $input['id'] : '';
$self->type = isset($input['type']) ? (string) $input['type'] : '';
$self->profileName = isset($input['profile']['name']) ? (string) $input['profile']['name'] : '';

return $self;
return new self(
isset($input['id']) ? (string) $input['id'] : '',
isset($input['type']) ? (string) $input['type'] : '',
isset($input['profile']['name']) ? (string) $input['profile']['name'] : '',
);
}
}
2 changes: 1 addition & 1 deletion src/Dto/UserGroupCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static function fromResponse(ResponseInterface $response): self

/** @var array $payload */
$payload = json_decode(
(string) $response->getBody(),
$response->getBody()->getContents(),
true,
512,
JSON_THROW_ON_ERROR
Expand Down
8 changes: 3 additions & 5 deletions src/Group/GetMembers.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@

class GetMembers
{
private ListGroupMembers $listGroupMembers;

public function __construct(ListGroupMembers $listGroupMembers)
{
$this->listGroupMembers = $listGroupMembers;
public function __construct(
private readonly ListGroupMembers $listGroupMembers,
) {
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/Group/GetMembersFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@
namespace OktaClient\Group;

use OktaClient\Request\ListGroupMembers;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;

use function assert;

class GetMembersFactory
{
/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function __invoke(ContainerInterface $container): GetMembers
{
$listGroupMembers = $container->get(ListGroupMembers::class);
Expand Down
Loading

0 comments on commit 4d01656

Please sign in to comment.