Skip to content

Commit bd52d1f

Browse files
authored
Merge pull request #91 from luka-lta/refactoring
toString method and fixes
2 parents 46cc68a + 5862ba1 commit bd52d1f

File tree

18 files changed

+44
-44
lines changed

18 files changed

+44
-44
lines changed

src/Api/Register/Service/RegisterService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function registerUser(ServerRequestInterface $request): ApiResult
6161

6262
$this->userRepository->create(
6363
User::create(
64-
$email->getEmail(),
64+
$email->asString(),
6565
$username,
6666
$password
6767
)

src/Api/SelfUser/Service/SelfUserService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function updateUser(ServerRequestInterface $request): ApiResult
6666
}
6767

6868
try {
69-
if ($user->getEmail()->getEmail() !== $email->getEmail() || $user->getUsername() !== $username) {
69+
if ($user->getEmail()->asString() !== $email->asString() || $user->getUsername() !== $username) {
7070
$this->validationService->ensureUserDoesNotExists($email, $username);
7171
}
7272
} catch (UserAlreadyExistsException $e) {

src/Api/User/Service/UserService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function createUser(array $body): ApiResult
4747

4848
$this->repository->create(
4949
User::create(
50-
$email->getEmail(),
50+
$email->asString(),
5151
$username,
5252
$password
5353
)
@@ -78,7 +78,7 @@ public function updateUser(ServerRequestInterface $request): ApiResult
7878
}
7979

8080
try {
81-
if ($user->getEmail()->getEmail() !== $email->getEmail() || $user->getUsername() !== $username) {
81+
if ($user->getEmail()->asString() !== $email->asString() || $user->getUsername() !== $username) {
8282
$this->validationService->ensureUserDoesNotExists($email, $username);
8383
}
8484
} catch (UserAlreadyExistsException $e) {

src/Repository/ClickRepository.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ public function recordClick(Click $click): void
3939
$statement = $this->pdo->prepare($sql);
4040
$statement->execute([
4141
'url' => (string)$click->getUrl(),
42-
'click_tag' => $click->getTag()->getValue(),
42+
'click_tag' => $click->getTag()->asString(),
4343
'click_date' => $click->getClickedAt()?->format('Y-m-d H:i:s'),
44-
'ip_address' => $click->getIpAddress(),
45-
'market' => $click->getMarket(),
46-
'user_agent' => $click->getUserAgent()?->getRawUserAgent(),
47-
'os' => $click->getUserAgent()?->getOs(),
48-
'device' => $click->getUserAgent()?->getDevice(),
49-
'referrer' => $click->getReferer(),
44+
'ip_address' => $click->getMetadata()->getIpAddress(),
45+
'market' => $click->getMetadata()->getMarket()?->asString(),
46+
'user_agent' => $click->getMetadata()->getUserAgent()?->asString(),
47+
'os' => $click->getMetadata()->getUserAgent()?->getOs(),
48+
'device' => $click->getMetadata()->getUserAgent()?->getDevice(),
49+
'referrer' => $click->getMetadata()->getReferrer(),
5050
]);
5151
} catch (PDOException $exception) {
5252
throw new ApiDatabaseException(

src/Repository/LinkCollectionRepository.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ public function create(LinkItem $link): LinkItem
3434
try {
3535
$statement = $this->pdo->prepare($sql);
3636
$statement->execute([
37-
'click_tag' => $link->getClickTag()->getValue(),
37+
'click_tag' => $link->getClickTag()->asString(),
3838
'displayname' => (string)$link->getMetaData()->getDisplayName(),
39-
'description' => $link->getMetaData()->getDescription()?->getValue(),
39+
'description' => $link->getMetaData()->getDescription()?->asString(),
4040
'url' => (string)$link->getMetaData()->getLinkUrl(),
4141
'is_active' => $link->getMetaData()->isActive() ? 1 : 0,
42-
'icon_name' => $link->getIconName()?->getValue(),
42+
'icon_name' => $link->getIconName()?->asString(),
4343
'display_order' => $link->getDisplayOrder(),
4444
]);
4545

@@ -64,7 +64,7 @@ public function getByClickTag(ClickTag $tag): ?LinkItem
6464

6565
try {
6666
$stmt = $this->pdo->prepare($sql);
67-
$stmt->execute(['clickTag' => $tag->getValue()]);
67+
$stmt->execute(['clickTag' => $tag->asString()]);
6868
$row = $stmt->fetch();
6969

7070
if ($row === false) {
@@ -126,10 +126,10 @@ public function update(LinkItem $linkItem): LinkItem
126126
$statement = $this->pdo->prepare($sql);
127127
$statement->execute([
128128
'displayname' => (string)$linkItem->getMetaData()->getDisplayName(),
129-
'description' => $linkItem->getMetaData()->getDescription()?->getValue(),
129+
'description' => $linkItem->getMetaData()->getDescription()?->asString(),
130130
'url' => (string)$linkItem->getMetaData()->getLinkUrl(),
131131
'is_active' => $linkItem->getMetaData()->isActive() ? 1 : 0,
132-
'icon_name' => $linkItem->getIconName()?->getValue(),
132+
'icon_name' => $linkItem->getIconName()?->asString(),
133133
'link_id' => $linkItem->getLinkId()?->asInt(),
134134
'display_order' => $linkItem->getDisplayOrder(),
135135
]);

src/Repository/UserRepository.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public function create(User $user): void
3232
try {
3333
$statement = $this->pdo->prepare($sql);
3434
$statement->execute([
35-
'email' => $user->getEmail()->getEmail(),
35+
'email' => $user->getEmail()->asString(),
3636
'username' => $user->getUsername(),
37-
'password' => $user->getPassword()->getPassword(),
37+
'password' => $user->getPassword()->asString(),
3838
'avatar_url' => $user->getAvatarUrl(),
3939
]);
4040
$this->pdo->commit();
@@ -66,8 +66,8 @@ public function update(User $user): void
6666
$statement = $this->pdo->prepare($sql);
6767
$statement->execute([
6868
'username' => $user->getUsername(),
69-
'email' => $user->getEmail()->getEmail(),
70-
'password' => $user->getPassword()->getPassword(),
69+
'email' => $user->getEmail()->asString(),
70+
'password' => $user->getPassword()->asString(),
7171
'avatar_url' => $user->getAvatarUrl(),
7272
'user_id' => $user->getUserId()?->asInt(),
7373
'is_active' => (int)$user->isActive(),
@@ -94,7 +94,7 @@ public function findByEmail(UserEmail $email): ?User
9494

9595
try {
9696
$statement = $this->pdo->prepare($sql);
97-
$statement->execute(['email' => $email->getEmail()]);
97+
$statement->execute(['email' => $email->asString()]);
9898

9999
$row = $statement->fetch(PDO::FETCH_ASSOC);
100100
} catch (PDOException $e) {

src/Service/TokenService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function generateToken(User $user): Jwt
1313
$expiresIn = time() + (int)getenv('JWT_NORMAL_EXPIRATION_TIME');
1414
return Token::builder(getenv('JWT_SECRET'))
1515
->setIssuer('https://api.luka-lta.dev')
16-
->setPayloadClaim('email', $user->getEmail()->getEmail())
16+
->setPayloadClaim('email', $user->getEmail()->asString())
1717
->setPayloadClaim('sub', $user->getUserId()?->asString())
1818
->setIssuedAt(time())
1919
->setExpiration($expiresIn)

src/Value/LinkCollection/Description.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static function fromString(?string $value): ?self
3333
return new self($value);
3434
}
3535

36-
public function getValue(): ?string
36+
public function asString(): ?string
3737
{
3838
return $this->value;
3939
}

src/Value/LinkCollection/IconName.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static function fromString(?string $value): ?self
3434
return new self($value);
3535
}
3636

37-
public function getValue(): ?string
37+
public function asString(): ?string
3838
{
3939
return $this->value;
4040
}

src/Value/LinkCollection/LinkItem.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ public function toArray(bool $mustRef = false): array
7070
{
7171
return [
7272
'id' => $this->linkId?->asInt(),
73-
'clickTag' => $this->clickTag->getValue(),
73+
'clickTag' => $this->clickTag->asString(),
7474
'displayname' => (string)$this->metaData->getDisplayName(),
75-
'description' => $this->metaData->getDescription()->getValue(),
75+
'description' => $this->metaData->getDescription()->asString(),
7676
'url' => $mustRef ? $this->clickTag->getAsTracking() : (string)$this->metaData->getLinkUrl(),
7777
'isActive' => $this->metaData->isActive(),
7878
'createdOn' => $this->createdOn->format('Y-m-d H:i:s'),
79-
'iconName' => $this->iconName->getValue(),
79+
'iconName' => $this->iconName->asString(),
8080
'displayOrder' => $this->displayOrder,
8181
'deactivated' => $this->deactivated,
8282
'deactivatedOn' => $this->deactivatedOn?->format('Y-m-d H:i:s'),

0 commit comments

Comments
 (0)