Skip to content

Commit

Permalink
Implemented own data objects, typed collections
Browse files Browse the repository at this point in the history
  • Loading branch information
keithbrink committed Apr 17, 2024
1 parent 2bd30f9 commit 261aa16
Show file tree
Hide file tree
Showing 462 changed files with 4,316 additions and 4,170 deletions.
23 changes: 6 additions & 17 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
'magic_method_casing' => true, // added from Symfony
'magic_constant_casing' => true,
'method_argument_space' => true,
'method_chaining_indentation' => true,
'native_function_casing' => true,
'no_alias_functions' => true,
'no_extra_blank_lines' => [
Expand Down Expand Up @@ -104,27 +105,24 @@
'unary_operator_spaces' => true,
'whitespace_after_comma_in_array' => true,

// php-cs-fixer 3: Renamed rules
'constant_case' => ['case' => 'lower'],
'general_phpdoc_tag_rename' => true,
'phpdoc_inline_tag_normalizer' => true,
'phpdoc_tag_type' => true,
'psr_autoloading' => true,
'trailing_comma_in_multiline' => ['elements' => ['arrays']],

// php-cs-fixer 3: Changed options
'binary_operator_spaces' => [
'default' => 'single_space',
'operators' => ['=>' => null],
],
'blank_line_before_statement' => [
'statements' => ['return'],
],
'class_attributes_separation' => [
'elements' => [
'const' => 'one',
'const' => 'only_if_meta',
'method' => 'one',
'property' => 'one',
'property' => 'only_if_meta',
],
],
'class_definition' => [
Expand All @@ -136,7 +134,6 @@
'sort_algorithm' => 'alpha',
],

// php-cs-fixer 3: Removed rootless options (*)
'no_unneeded_control_parentheses' => [
'statements' => ['break', 'clone', 'continue', 'echo_print', 'return', 'switch_case', 'yield'],
],
Expand All @@ -146,23 +143,15 @@
'visibility_required' => [
'elements' => ['property', 'method', 'const'],
],

];

$finder = Finder::create()
->notPath('vendor')
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->ignoreUnreadableDirs()
->name('*.php')
->notName('*.blade.php')
$finder = (new Finder)
->in(__DIR__)
->ignoreDotFiles(true)
->ignoreVCS(true);

return (new Config())
->setFinder($finder)
->setRules($rules)
->setFinder($finder)
->setRiskyAllowed(true)
->setUsingCache(true);
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"guzzlehttp/guzzle": "^7.4",
"aws/aws-sdk-php": "^3.199",
"illuminate/http": "^9.0 || ^10.0",
"spatie/data-transfer-object": "^3.7",
"vlucas/phpdotenv": "^5.3",
"brick/money": "^0.5 || ^0.6 || ^0.7 || ^0.8",
"illuminate/support": "^9.0 || ^10.0",
Expand Down
80 changes: 6 additions & 74 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 20 additions & 19 deletions src/AmznSPAConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
use Illuminate\Http\Client\PendingRequest;
use Jasara\AmznSPA\Constants\Marketplace;
use Jasara\AmznSPA\Constants\MarketplacesList;
use Jasara\AmznSPA\Data\ApplicationKeysDTO;
use Jasara\AmznSPA\Data\AuthTokensDTO;
use Jasara\AmznSPA\Data\GrantlessTokenDTO;
use Jasara\AmznSPA\Data\RestrictedDataTokenDTO;
use Jasara\AmznSPA\Data\ApplicationKeys;
use Jasara\AmznSPA\Data\AuthTokens;
use Jasara\AmznSPA\Data\GrantlessToken;
use Jasara\AmznSPA\Data\RestrictedDataToken;
use Jasara\AmznSPA\Traits\ValidatesParameters;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpKernel\Log\Logger;
Expand All @@ -21,15 +21,15 @@ class AmznSPAConfig

private PendingRequest $http;

private AuthTokensDTO $tokens;
private AuthTokens $tokens;

private Marketplace $marketplace;

private ApplicationKeysDTO $application_keys;
private ApplicationKeys $application_keys;

private GrantlessTokenDTO $grantless_token;
private GrantlessToken $grantless_token;

private RestrictedDataTokenDTO $restricted_data_token;
private RestrictedDataToken $restricted_data_token;

private LoggerInterface $logger;

Expand Down Expand Up @@ -58,21 +58,22 @@ public function __construct(
$this->validateStringEnum($marketplace_id, MarketplacesList::allIdentifiers());

$this->http = (new Factory())->connectTimeout(10);
$this->tokens = new AuthTokensDTO(
$this->tokens = new AuthTokens(
refresh_token: $lwa_refresh_token,
access_token: $lwa_access_token,
expires_at: $lwa_access_token_expires_at,
);
$this->grantless_token = new GrantlessTokenDTO(
$this->grantless_token = new GrantlessToken(
access_token: $grantless_access_token,
expires_at: $grantless_access_token_expires_at,
);
$this->restricted_data_token = new RestrictedDataTokenDTO(
$this->restricted_data_token = new RestrictedDataToken(
access_token: $restricted_data_token,
expires_at: $restricted_data_token_expires_at,
path: null,
);
$this->marketplace = MarketplacesList::getMarketplaceById($marketplace_id);
$this->application_keys = new ApplicationKeysDTO(
$this->application_keys = new ApplicationKeys(
application_id: $application_id,
aws_access_key: $aws_access_key,
aws_secret_key: $aws_secret_key,
Expand All @@ -88,17 +89,17 @@ public function getHttp(): PendingRequest
return clone $this->http;
}

public function getTokens(): AuthTokensDTO
public function getTokens(): AuthTokens
{
return $this->tokens;
}

public function getGrantlessToken(): GrantlessTokenDTO
public function getGrantlessToken(): GrantlessToken
{
return $this->grantless_token;
}

public function getRestrictedDataToken(): RestrictedDataTokenDTO
public function getRestrictedDataToken(): RestrictedDataToken
{
return $this->restricted_data_token;
}
Expand All @@ -108,7 +109,7 @@ public function getMarketplace(): Marketplace
return $this->marketplace;
}

public function getApplicationKeys(): ApplicationKeysDTO
public function getApplicationKeys(): ApplicationKeys
{
return $this->application_keys;
}
Expand Down Expand Up @@ -159,17 +160,17 @@ public function setHttp(Factory|PendingRequest $http): void
$this->http = $http;
}

public function setTokens(AuthTokensDTO $tokens): void
public function setTokens(AuthTokens $tokens): void
{
$this->tokens = $tokens;
}

public function setRestrictedDataToken(RestrictedDataTokenDTO $token): void
public function setRestrictedDataToken(RestrictedDataToken $token): void
{
$this->restricted_data_token = $token;
}

public function setGrantlessToken(GrantlessTokenDTO $token): void
public function setGrantlessToken(GrantlessToken $token): void
{
$this->grantless_token = $token;
}
Expand Down
6 changes: 3 additions & 3 deletions src/AmznSPAHttp.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Illuminate\Support\Str;
use Jasara\AmznSPA\Constants\JasaraNotes;
use Jasara\AmznSPA\Data\Requests\Tokens\CreateRestrictedDataTokenRequest;
use Jasara\AmznSPA\Data\RestrictedDataTokenDTO;
use Jasara\AmznSPA\Data\RestrictedDataToken;
use Jasara\AmznSPA\Data\Schemas\MetadataSchema;
use Jasara\AmznSPA\Exceptions\AmznSPAException;
use Jasara\AmznSPA\Exceptions\AuthenticationException;
Expand Down Expand Up @@ -223,7 +223,7 @@ private function refreshRdtToken(string $url, string $method)
throw new AmznSPAException(implode(',', $response->errors->pluck('message')->toArray() ?: []));
}

$this->config->setRestrictedDataToken(new RestrictedDataTokenDTO(
$this->config->setRestrictedDataToken(new RestrictedDataToken(
access_token: $response->restricted_data_token,
expires_at: $response->expires_in,
path: $path,
Expand Down Expand Up @@ -319,7 +319,7 @@ private function getRestrictedTokenPathFromUrl(string $url): string
return $path;
}

private function isRestrictedTokenCompatibleWithPath(RestrictedDataTokenDTO $token, string $url): bool
private function isRestrictedTokenCompatibleWithPath(RestrictedDataToken $token, string $url): bool
{
$path = $this->getRestrictedTokenPathFromUrl($url);

Expand Down
15 changes: 15 additions & 0 deletions src/Data/ApplicationKeys.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Jasara\AmznSPA\Data;

class ApplicationKeys
{
public function __construct(
public string $application_id,
public ?string $aws_access_key = null,
public ?string $aws_secret_key = null,
public ?string $lwa_client_id = null,
public ?string $lwa_client_secret = null,
) {
}
}
18 changes: 0 additions & 18 deletions src/Data/ApplicationKeysDTO.php

This file was deleted.

23 changes: 23 additions & 0 deletions src/Data/AuthTokens.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Jasara\AmznSPA\Data;

use Carbon\CarbonImmutable;
use Jasara\AmznSPA\Data\Base\Data;

class AuthTokens extends Data
{
public ?CarbonImmutable $expires_at;

public function __construct(
public ?string $access_token,
public ?string $refresh_token,
CarbonImmutable|int|null $expires_at,
) {
$this->expires_at = match (true) {
is_int($expires_at) => CarbonImmutable::now()->addSeconds($expires_at),
$expires_at instanceof CarbonImmutable => $expires_at,
default => null,
};
}
}
Loading

0 comments on commit 261aa16

Please sign in to comment.