Skip to content

Commit 91e6b6d

Browse files
cl77claude
andcommitted
refactor: improve resource payload building and flexibility
- Contact: only include avatar and groups if they have values - Properties: only include non-null values in payload - ValidateForVoice: make sender nullable, set voice default to false - JournalResource: remove unused replies method 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 9922c85 commit 91e6b6d

File tree

4 files changed

+22
-33
lines changed

4 files changed

+22
-33
lines changed

src/Resource/Contacts/Contact.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ public static function fromApi(object $obj): Contact {
2525
}
2626

2727
public function toPayload(): array {
28-
return [
29-
...$this->properties->toPayload(),
30-
'avatar' => $this->avatar,
31-
'groups[]' => $this->groups,
32-
];
28+
$payload = $this->properties->toPayload();
29+
if ($this->avatar !== null) $payload['avatar'] = $this->avatar;
30+
// Only include groups if not empty
31+
if (!empty($this->groups)) {
32+
$payload['groups'] = $this->groups;
33+
}
34+
return $payload;
3335
}
3436

3537
public function getAvatar(): string {

src/Resource/Contacts/Properties.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,18 @@ public static function fromApi(object $obj): Properties {
3434
}
3535

3636
public function toPayload(): array {
37-
return [
38-
'address' => $this->getAddress(),
39-
'birthday' => $this->getBirthday()->format('Y-m-d'),
40-
'city' => $this->getCity(),
41-
'email' => $this->getEmail(),
42-
'firstname' => $this->getFirstname(),
43-
'home_number' => $this->getHomeNumber(),
44-
'lastname' => $this->getLastname(),
45-
'mobile_number' => $this->getMobileNumber(),
46-
'notes' => $this->getNotes(),
47-
'postal_code' => $this->getPostalCode(),
48-
];
37+
$payload = [];
38+
if ($this->getAddress() !== null) $payload['address'] = $this->getAddress();
39+
if ($this->getBirthday() !== null) $payload['birthday'] = $this->getBirthday()->format('Y-m-d');
40+
if ($this->getCity() !== null) $payload['city'] = $this->getCity();
41+
if ($this->getEmail() !== null) $payload['email'] = $this->getEmail();
42+
if ($this->getFirstname() !== null) $payload['firstname'] = $this->getFirstname();
43+
if ($this->getHomeNumber() !== null) $payload['home_number'] = $this->getHomeNumber();
44+
if ($this->getLastname() !== null) $payload['lastname'] = $this->getLastname();
45+
if ($this->getMobileNumber() !== null) $payload['mobile_number'] = $this->getMobileNumber();
46+
if ($this->getNotes() !== null) $payload['notes'] = $this->getNotes();
47+
if ($this->getPostalCode() !== null) $payload['postal_code'] = $this->getPostalCode();
48+
return $payload;
4949
}
5050

5151
public function getAddress(): ?string {

src/Resource/Journal/JournalResource.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,6 @@ public function outbound(JournalParams $params = new JournalParams): array {
6565
return $this->fetch('outbound', JournalOutbound::class, $params);
6666
}
6767

68-
/**
69-
* @return JournalReply[]
70-
* @throws ForbiddenIpException
71-
* @throws InvalidApiKeyException
72-
* @throws InvalidOptionalArgumentException
73-
* @throws MissingAccessRightsException
74-
* @throws RandomException
75-
* @throws SigningHashVerificationException
76-
* @throws UnexpectedApiResponseException
77-
*/
78-
public function replies(JournalParams $params = new JournalParams): array {
79-
return $this->fetch('replies', JournalReply::class, $params);
80-
}
8168

8269
/**
8370
* @return JournalVoice[]

src/Resource/ValidateForVoice/ValidateForVoice.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ class ValidateForVoice {
77
protected ?string $error = null;
88
protected ?string $formattedOutput = null;
99
protected ?int $id = null;
10-
protected string $sender;
10+
protected ?string $sender = null;
1111
protected bool $success;
12-
protected bool $voice;
12+
protected bool $voice = false;
1313

1414
public function __construct(object $data) {
1515
if (property_exists($data, 'code')) $this->code = (int)$data->code;
@@ -38,7 +38,7 @@ public function getId(): ?int {
3838
return $this->id;
3939
}
4040

41-
public function getSender(): string {
41+
public function getSender(): ?string {
4242
return $this->sender;
4343
}
4444

0 commit comments

Comments
 (0)