Skip to content

Commit

Permalink
Merge branch 'b-7.3.x-reafctor_static_methods-OXDEV-9047' into b-7.3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelOxid committed Feb 10, 2025
2 parents ea64e3c + 70ddf9f commit c7a8c5e
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 51 deletions.
6 changes: 0 additions & 6 deletions CHANGELOG-v10.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [10.1.0] - unreleased

## Changed
- Update module to work with OXID eShop 7.3

## [10.0.0] - 2024-11-27
This is stable release for v10.0.0. No changes have been made since v10.0.0-rc.1.

Expand Down Expand Up @@ -45,6 +40,5 @@ This is stable release for v10.0.0. No changes have been made since v10.0.0-rc.1
## Changed
- Renamed OxidEsales\GraphQL\Base\Infrastructure\Token::cleanUpTokens() to deleteOrphanedTokens()

[10.1.0]: https://github.com/OXID-eSales/graphql-base-module/compare/v10.0.0...b-7.3.x
[10.0.0]: https://github.com/OXID-eSales/graphql-base-module/compare/v10.0.0-rc.1...v10.0.0
[10.0.0-rc.1]: https://github.com/OXID-eSales/graphql-base-module/compare/v9.0.0...v10.0.0-rc.1
15 changes: 15 additions & 0 deletions CHANGELOG-v11.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [11.0.0] - unreleased

### Changed
- Update module to work with OXID eShop 7.3
- Replaced `TokenFilterList::fromUserInput` and `TokenSorting::fromUserInput` with direct object instantiation
- Removed static access for `Legacy::createUniqueIdentifier()` and made it an instance method
- Updated `MissingSignatureKey` exception to use a constructor instead of a static factory method

[11.0.0]: https://github.com/OXID-eSales/graphql-base-module/compare/v10.0.0...b-7.3.x
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
"oxid-esales/codeception-modules": "dev-b-7.3.x",
"codeception/module-asserts": "^3.0"
},
"conflict": {
"oxid-esales/oxideshop-ce": "<7.3"
},
"conflict": {
"oxid-esales/oxideshop-ce": "<7.3"
},
"autoload": {
"psr-4": {
"OxidEsales\\GraphQL\\Base\\": "src"
Expand Down Expand Up @@ -76,7 +76,7 @@
},
"autoload-dev": {
"psr-4": {
"OxidEsales\\EshopCommunity\\Tests\\": "./vendor/oxid-esales/oxideshop-ce/tests",
"OxidEsales\\EshopCommunity\\Tests\\": "./vendor/oxid-esales/oxideshop-ce/tests",
"OxidEsales\\GraphQL\\Base\\Tests\\": "./tests"
}
}
Expand Down
8 changes: 3 additions & 5 deletions src/Controller/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,11 @@ public function tokens(
?TokenSorting $sort = null
): array {
return $this->tokenAdministration->tokens(
$filter ?? TokenFilterList::fromUserInput(
new IDFilter(
$this->authentication->getUser()->id()
)
$filter ?? new TokenFilterList(
new IDFilter($this->authentication->getUser()->id())
),
$pagination ?? new Pagination(),
$sort ?? TokenSorting::fromUserInput(Sorting::SORTING_ASC)
$sort ?? new TokenSorting(Sorting::SORTING_ASC),
);
}

Expand Down
17 changes: 9 additions & 8 deletions src/DataType/Sorting/TokenSorting.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@

namespace OxidEsales\GraphQL\Base\DataType\Sorting;

use TheCodingMachine\GraphQLite\Annotations\Factory;
use TheCodingMachine\GraphQLite\Annotations\Field;
use TheCodingMachine\GraphQLite\Annotations\Input;

#[Input]
final class TokenSorting extends Sorting
{
/**
* @Factory(name="TokenSorting",default=true)
*
* Tokens will be sorted by their expiration date ('expires_at' column).
*/
public static function fromUserInput(
string $expiresAt = self::SORTING_ASC
): self {
return new self([
'expires_at' => $expiresAt,
public function __construct(
#[Field]
private string $expiresAt = self::SORTING_ASC,
) {
parent::__construct([
'expires_at' => $this->expiresAt,
]);
}
}
18 changes: 6 additions & 12 deletions src/DataType/TokenFilterList.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@
use OxidEsales\GraphQL\Base\DataType\Filter\DateFilter;
use OxidEsales\GraphQL\Base\DataType\Filter\FilterListInterface;
use OxidEsales\GraphQL\Base\DataType\Filter\IDFilter;
use TheCodingMachine\GraphQLite\Annotations\Factory;
use TheCodingMachine\GraphQLite\Annotations\Field;
use TheCodingMachine\GraphQLite\Annotations\Input;

#[Input]
final class TokenFilterList implements FilterListInterface
{
public function __construct(
#[Field]
private readonly ?IDFilter $customerId = null,
#[Field]
private readonly ?IDFilter $shopId = null,
#[Field]
private readonly ?DateFilter $expiresAt = null
) {
}
Expand Down Expand Up @@ -59,15 +64,4 @@ public function getFilters(): array
'expires_at' => $this->expiresAt,
];
}

/**
* @Factory(name="TokenFilterList",default=true)
*/
public static function fromUserInput(
?IDFilter $customerId,
?IDFilter $shopId = null,
?DateFilter $expiresAt = null
): self {
return new self($customerId, $shopId, $expiresAt);
}
}
4 changes: 2 additions & 2 deletions src/Exception/MissingSignatureKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class MissingSignatureKey extends Error
{
protected const WRONG_SIZE_MESSAGE = 'Signature key is too short';

public static function wrongSize(): self
public function __construct()
{
return new self(self::WRONG_SIZE_MESSAGE);
parent::__construct(self::WRONG_SIZE_MESSAGE);
}
}
4 changes: 2 additions & 2 deletions src/Infrastructure/Legacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function login(?string $username = null, ?string $password = null): UserI
return new User($user, false);
}

$user->setId(self::createUniqueIdentifier());
$user->setId($this->createUniqueIdentifier());
return new User($user, true);
}

Expand Down Expand Up @@ -126,7 +126,7 @@ public function getUserGroupIds(?string $userId): array
return $userGroupIds;
}

public static function createUniqueIdentifier(): string
public function createUniqueIdentifier(): string
{
$utils = Registry::getUtilsObject();
return $utils->generateUId();
Expand Down
2 changes: 1 addition & 1 deletion src/Service/ModuleConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function getSignatureKey(): string
->toString();

if (strlen($signature) < 64) {
throw MissingSignatureKey::wrongSize();
throw new MissingSignatureKey();
}

return $signature;
Expand Down
2 changes: 1 addition & 1 deletion src/Service/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function createTokenForUser(UserInterface $user): UnencryptedToken
->withClaim(self::CLAIM_USERNAME, $user->email())
->withClaim(self::CLAIM_USERID, $user->id()->val())
->withClaim(self::CLAIM_USER_ANONYMOUS, $user->isAnonymous())
->withClaim(self::CLAIM_TOKENID, Legacy::createUniqueIdentifier());
->withClaim(self::CLAIM_TOKENID, $this->legacyInfrastructure->createUniqueIdentifier());

$event = new BeforeTokenCreation($builder, $user);
$this->eventDispatcher->dispatch(
Expand Down
4 changes: 0 additions & 4 deletions tests/PhpMd/phpmd.baseline.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
<?xml version="1.0"?>
<phpmd-baseline>
<violation rule="PHPMD\Rule\CleanCode\StaticAccess" file="src/Component/Widget/GraphQL.php"/>
<violation rule="PHPMD\Rule\CleanCode\StaticAccess" file="src/Controller/Token.php"/>
<violation rule="PHPMD\Rule\Naming\ShortMethodName" file="src/DataType/RefreshTokenInterface.php" method="id"/>
<violation rule="PHPMD\Rule\Naming\ShortMethodName" file="src/DataType/UserInterface.php" method="id"/>
<violation rule="PHPMD\Rule\CleanCode\StaticAccess" file="src/Framework/GraphQLQueryHandler.php"/>
<violation rule="PHPMD\Rule\CleanCode\StaticAccess" file="src/Framework/RequestReader.php"/>
<violation rule="PHPMD\Rule\CleanCode\StaticAccess" file="src/Infrastructure/Legacy.php"/>
<violation rule="PHPMD\Rule\CleanCode\StaticAccess" file="src/Service/JwtConfigurationBuilder.php"/>
<violation rule="PHPMD\Rule\CleanCode\StaticAccess" file="src/Service/ModuleConfiguration.php"/>
<violation rule="PHPMD\Rule\CleanCode\StaticAccess" file="src/Service/Token.php"/>
</phpmd-baseline>
1 change: 1 addition & 0 deletions tests/Unit/Controller/LoginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function testCreateTokenWithValidCredentials(): void
$user = new User($userModelStub);

$this->legacy->method('login')->with($username, $password)->willReturn($user);
$this->legacy->method('createUniqueIdentifier')->willReturn(uniqid());

$loginController = new Login(
$this->tokenService,
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/Controller/TokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public function testTokensQueryWithDefaultFilters(): void
$tokenAdministration = $this->createPartialMock(TokenAdministration::class, ['tokens']);
$tokenAdministration->method('tokens')
->with(
TokenFilterList::fromUserInput(new IDFilter($authentication->getUser()->id())),
new TokenFilterList(new IDFilter($authentication->getUser()->id())),
new Pagination(),
TokenSorting::fromUserInput(TokenSorting::SORTING_ASC)
new TokenSorting(TokenSorting::SORTING_ASC),
)
->willReturn([]);

Expand All @@ -56,12 +56,12 @@ public function testTokensQueryWithCustomFilters(): void
$authentication->method('getUser')
->willReturn(new UserDataType($this->getUserModelStub('_testuserid')));

$filterList = TokenFilterList::fromUserInput(
$filterList = new TokenFilterList(
new IDFilter(new ID('someone_else')),
new IDFilter(new ID(1)),
new DateFilter(null, ['2021-01-12 12:12:12', '2021-12-31 12:12:12'])
);
$sort = TokenSorting::fromUserInput(TokenSorting::SORTING_DESC);
$sort = new TokenSorting(TokenSorting::SORTING_DESC);
$pagination = Pagination::fromUserInput(10, 20);

$tokenAdministration = $this->createPartialMock(TokenAdministration::class, ['tokens']);
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Service/TokenAdministrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function testQueryTokensNotAuthorizedFilterOnNotOwnUserId(): void
$moduleSetup
);
$filterList = new TokenFilterList(new IDFilter(new ID('unknown')));
$sort = TokenSorting::fromUserInput();
$sort = new TokenSorting();
$pagination = new Pagination();

$this->expectException(InvalidLogin::class);
Expand Down Expand Up @@ -84,7 +84,7 @@ public function testQueryTokensNotAuthorizedFilterOnOwnUserId(): void
$moduleSetup
);
$filterList = new TokenFilterList(new IDFilter(new ID('_testuserid')));
$sort = TokenSorting::fromUserInput();
$sort = new TokenSorting();
$pagination = new Pagination();

$tokenAdministration->tokens($filterList, $pagination, $sort);
Expand Down

0 comments on commit c7a8c5e

Please sign in to comment.