Skip to content

Commit 5bb935a

Browse files
tkcreateitMarcelOxid
authored andcommitted
OXDEV-9047 Remove static methods access
1 parent ea64e3c commit 5bb935a

File tree

12 files changed

+38
-41
lines changed

12 files changed

+38
-41
lines changed

CHANGELOG-v10.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [10.1.0] - unreleased
88

9-
## Changed
9+
### Changed
1010
- Update module to work with OXID eShop 7.3
11+
- Replaced `TokenFilterList::fromUserInput` and `TokenSorting::fromUserInput` with direct object instantiation
12+
- Removed static access for `Legacy::createUniqueIdentifier()` and made it an instance method
13+
- Updated `MissingSignatureKey` exception to use a constructor instead of a static factory method
14+
15+
### Removed
16+
- `fromUserInput` factory methods from `TokenFilterList` and `TokenSorting`.
1117

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

src/Controller/Token.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,11 @@ public function tokens(
5353
?TokenSorting $sort = null
5454
): array {
5555
return $this->tokenAdministration->tokens(
56-
$filter ?? TokenFilterList::fromUserInput(
57-
new IDFilter(
58-
$this->authentication->getUser()->id()
59-
)
56+
$filter ?? new TokenFilterList(
57+
new IDFilter($this->authentication->getUser()->id())
6058
),
6159
$pagination ?? new Pagination(),
62-
$sort ?? TokenSorting::fromUserInput(Sorting::SORTING_ASC)
60+
$sort ?? new TokenSorting(Sorting::SORTING_ASC),
6361
);
6462
}
6563

src/DataType/Sorting/TokenSorting.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,21 @@
99

1010
namespace OxidEsales\GraphQL\Base\DataType\Sorting;
1111

12-
use TheCodingMachine\GraphQLite\Annotations\Factory;
12+
use TheCodingMachine\GraphQLite\Annotations\Field;
13+
use TheCodingMachine\GraphQLite\Annotations\Input;
1314

15+
#[Input]
1416
final class TokenSorting extends Sorting
1517
{
1618
/**
17-
* @Factory(name="TokenSorting",default=true)
18-
*
1919
* Tokens will be sorted by their expiration date ('expires_at' column).
2020
*/
21-
public static function fromUserInput(
22-
string $expiresAt = self::SORTING_ASC
23-
): self {
24-
return new self([
25-
'expires_at' => $expiresAt,
21+
public function __construct(
22+
#[Field]
23+
private string $expiresAt = self::SORTING_ASC,
24+
) {
25+
parent::__construct([
26+
'expires_at' => $this->expiresAt,
2627
]);
2728
}
2829
}

src/DataType/TokenFilterList.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@
1313
use OxidEsales\GraphQL\Base\DataType\Filter\DateFilter;
1414
use OxidEsales\GraphQL\Base\DataType\Filter\FilterListInterface;
1515
use OxidEsales\GraphQL\Base\DataType\Filter\IDFilter;
16-
use TheCodingMachine\GraphQLite\Annotations\Factory;
16+
use TheCodingMachine\GraphQLite\Annotations\Field;
17+
use TheCodingMachine\GraphQLite\Annotations\Input;
1718

19+
#[Input]
1820
final class TokenFilterList implements FilterListInterface
1921
{
2022
public function __construct(
23+
#[Field]
2124
private readonly ?IDFilter $customerId = null,
25+
#[Field]
2226
private readonly ?IDFilter $shopId = null,
27+
#[Field]
2328
private readonly ?DateFilter $expiresAt = null
2429
) {
2530
}
@@ -59,15 +64,4 @@ public function getFilters(): array
5964
'expires_at' => $this->expiresAt,
6065
];
6166
}
62-
63-
/**
64-
* @Factory(name="TokenFilterList",default=true)
65-
*/
66-
public static function fromUserInput(
67-
?IDFilter $customerId,
68-
?IDFilter $shopId = null,
69-
?DateFilter $expiresAt = null
70-
): self {
71-
return new self($customerId, $shopId, $expiresAt);
72-
}
7367
}

src/Exception/MissingSignatureKey.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class MissingSignatureKey extends Error
1313
{
1414
protected const WRONG_SIZE_MESSAGE = 'Signature key is too short';
1515

16-
public static function wrongSize(): self
16+
public function __construct()
1717
{
18-
return new self(self::WRONG_SIZE_MESSAGE);
18+
parent::__construct(self::WRONG_SIZE_MESSAGE);
1919
}
2020
}

src/Infrastructure/Legacy.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function login(?string $username = null, ?string $password = null): UserI
4848
return new User($user, false);
4949
}
5050

51-
$user->setId(self::createUniqueIdentifier());
51+
$user->setId($this->createUniqueIdentifier());
5252
return new User($user, true);
5353
}
5454

@@ -126,7 +126,7 @@ public function getUserGroupIds(?string $userId): array
126126
return $userGroupIds;
127127
}
128128

129-
public static function createUniqueIdentifier(): string
129+
public function createUniqueIdentifier(): string
130130
{
131131
$utils = Registry::getUtilsObject();
132132
return $utils->generateUId();

src/Service/ModuleConfiguration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function getSignatureKey(): string
7777
->toString();
7878

7979
if (strlen($signature) < 64) {
80-
throw MissingSignatureKey::wrongSize();
80+
throw new MissingSignatureKey();
8181
}
8282

8383
return $signature;

src/Service/Token.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function createTokenForUser(UserInterface $user): UnencryptedToken
9292
->withClaim(self::CLAIM_USERNAME, $user->email())
9393
->withClaim(self::CLAIM_USERID, $user->id()->val())
9494
->withClaim(self::CLAIM_USER_ANONYMOUS, $user->isAnonymous())
95-
->withClaim(self::CLAIM_TOKENID, Legacy::createUniqueIdentifier());
95+
->withClaim(self::CLAIM_TOKENID, $this->legacyInfrastructure->createUniqueIdentifier());
9696

9797
$event = new BeforeTokenCreation($builder, $user);
9898
$this->eventDispatcher->dispatch(

tests/PhpMd/phpmd.baseline.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
<?xml version="1.0"?>
22
<phpmd-baseline>
33
<violation rule="PHPMD\Rule\CleanCode\StaticAccess" file="src/Component/Widget/GraphQL.php"/>
4-
<violation rule="PHPMD\Rule\CleanCode\StaticAccess" file="src/Controller/Token.php"/>
54
<violation rule="PHPMD\Rule\Naming\ShortMethodName" file="src/DataType/RefreshTokenInterface.php" method="id"/>
65
<violation rule="PHPMD\Rule\Naming\ShortMethodName" file="src/DataType/UserInterface.php" method="id"/>
76
<violation rule="PHPMD\Rule\CleanCode\StaticAccess" file="src/Framework/GraphQLQueryHandler.php"/>
87
<violation rule="PHPMD\Rule\CleanCode\StaticAccess" file="src/Framework/RequestReader.php"/>
98
<violation rule="PHPMD\Rule\CleanCode\StaticAccess" file="src/Infrastructure/Legacy.php"/>
109
<violation rule="PHPMD\Rule\CleanCode\StaticAccess" file="src/Service/JwtConfigurationBuilder.php"/>
11-
<violation rule="PHPMD\Rule\CleanCode\StaticAccess" file="src/Service/ModuleConfiguration.php"/>
12-
<violation rule="PHPMD\Rule\CleanCode\StaticAccess" file="src/Service/Token.php"/>
1310
</phpmd-baseline>

tests/Unit/Controller/LoginTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public function testCreateTokenWithValidCredentials(): void
7272
$user = new User($userModelStub);
7373

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

7677
$loginController = new Login(
7778
$this->tokenService,

0 commit comments

Comments
 (0)