-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
117 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"symbol-whitelist": [ | ||
"toNullableDateTime" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
/** | ||
* @author: Julien Mercier-Rojas <julien@jeckel-lab.fr> | ||
* Created at: 13/10/2023 | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JeckelLab\MauticWebhookParser; | ||
|
||
use DateTimeImmutable; | ||
use Exception; | ||
use JeckelLab\MauticWebhookParser\Exception\LogicException; | ||
use JeckelLab\MauticWebhookParser\Model\Contact; | ||
|
||
class ContactParser | ||
{ | ||
/** | ||
* @param array<string, mixed> $payload | ||
* @return Contact | ||
* @throws Exception|LogicException | ||
*/ | ||
public function parse(array $payload): Contact | ||
{ | ||
return new Contact( | ||
dateAdded: is_string($payload['dateAdded']) ? new DateTimeImmutable($payload['dateAdded']) : throw new LogicException('Missing dateAdded'), | ||
dateIdentified: is_string($payload['dateIdentified']) ? new DateTimeImmutable($payload['dateIdentified']) : throw new LogicException('Missing dateIdentified'), | ||
dateModified: toNullableDateTime($payload['dateModified'] ?? null), | ||
id: is_int($payload['id']) ? $payload['id'] : throw new LogicException('Missing id'), | ||
isPublished: (bool) $payload['isPublished'], | ||
Check warning on line 31 in src/ContactParser.php GitHub Actions / PHP 8.2
|
||
); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
/** | ||
* @author: Julien Mercier-Rojas <julien@jeckel-lab.fr> | ||
* Created at: 13/10/2023 | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JeckelLab\MauticWebhookParser\Model; | ||
|
||
use DateTimeImmutable; | ||
|
||
readonly class Contact | ||
{ | ||
public function __construct( | ||
public DateTimeImmutable $dateAdded, | ||
public DateTimeImmutable $dateIdentified, | ||
public ?DateTimeImmutable $dateModified, | ||
public int $id, | ||
public bool $isPublished, | ||
) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
/** | ||
* @author: Julien Mercier-Rojas <julien@jeckel-lab.fr> | ||
* Created at: 13/10/2023 | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JeckelLab\MauticWebhookParser; | ||
|
||
use DateTimeImmutable; | ||
use Exception; | ||
|
||
function toNullableDateTime(mixed $date): ?DateTimeImmutable | ||
{ | ||
try { | ||
return is_string($date) ? new DateTimeImmutable($date) : null; | ||
} catch (Exception) { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.