Skip to content

Commit

Permalink
Merge pull request #80 from mailjet/DE-1302-laravel-no-exceptions-err…
Browse files Browse the repository at this point in the history
…ors-thrown-on-config-error

End of support php 7.3 and below. PHP 7.4+ only
  • Loading branch information
oleksandr-mykhailenko authored Aug 23, 2024
2 parents bded9b6 + 6f886e3 commit 4eeb55a
Show file tree
Hide file tree
Showing 27 changed files with 123 additions and 74 deletions.
11 changes: 8 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
}
],
"require": {
"php": "^7.1.3|^8.0",
"php": "^7.4|^8.0",
"laravel/framework": "^9.0|^10.0|^11.0",
"mailjet/mailjet-apiv3-php": "^1.5.6|^1.5",
"symfony/http-client": "^7.1",
Expand All @@ -39,8 +39,9 @@
"require-dev": {
"fakerphp/faker": "~1",
"mockery/mockery": "0.9.*|^1.0",
"phpunit/phpunit": "~7.0|^8.0|^9|^10.0",
"orchestra/testbench": "3.6|^4.0|^5.0|^6.0|^8.0|^9.0"
"orchestra/testbench": "3.6|^4.0|^5.0|^6.0|^8.0|^9.0",
"phpcompatibility/php-compatibility": "^9.3",
"phpunit/phpunit": "~7.0|^8.0|^9|^10.0"
},
"autoload": {
"psr-4": {
Expand All @@ -65,5 +66,9 @@
"config": {
"sort-packages": true,
"bin-dir": "bin"
},
"scripts": {
"post-install-cmd": "\"bin/phpcs\" --config-set installed_paths vendor/phpcompatibility/php-compatibility",
"post-update-cmd" : "\"bin/phpcs\" --config-set installed_paths vendor/phpcompatibility/php-compatibility"
}
}
6 changes: 3 additions & 3 deletions src/Exception/MailjetException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ class MailjetException extends \Exception
/**
* @var string
*/
private $errorInfo;
private string $errorInfo;

/**
* @var string
*/
private $errorMessage;
private string $errorMessage;

/**
* @var string
*/
private $errorIdentifier;
private string $errorIdentifier;

/**
* https://dev.mailjet.com/guides/#about-the-mailjet-restful-api
Expand Down
5 changes: 5 additions & 0 deletions src/MailjetServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Illuminate\Support\Facades\Mail;
use Illuminate\Support\ServiceProvider;
use InvalidArgumentException;
use Mailjet\LaravelMailjet\Services\MailjetService;
use Symfony\Component\Mailer\Bridge\Mailjet\Transport\MailjetTransportFactory;
use Symfony\Component\Mailer\Transport\Dsn;
Expand Down Expand Up @@ -43,6 +44,10 @@ public function register(): void
$call = $this->app['config']->get('services.mailjet.common.call', true);
$options = $this->app['config']->get('services.mailjet.common.options', []);

if (!isset($config['key'], $config['secret'])) {
throw new InvalidArgumentException('The Mailjet service is not configured.');
}

return new MailjetService($config['key'], $config['secret'], $call, $options);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Campaign extends Model
/**
* @var string
*/
protected $fromEmail;
protected string $fromEmail;

/**
* @param string $fromEmail
Expand Down
39 changes: 24 additions & 15 deletions src/Model/CampaignDraft.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,54 @@ class CampaignDraft extends Model
/**
* @var string
*/
protected $locale;
protected string $locale;

/**
* @var string
*/
protected $sender;
protected string $sender;

/**
* @var string
*/
protected $senderEmail;
protected string $senderEmail;

/**
* @var string
*/
protected $subject;
protected string $subject;

/**
* @var string
*/
protected $contactsListId;
protected string $contactsListId;

/**
* @var array|null
*/
protected $content;
protected ?array $content;

/**
* @var string|null
*/
protected $id;

public function __construct(string $locale,
string $sender,
string $senderEmail,
string $subject,
string $contactsListId,
array $optionalProperties = [])
{
protected ?string $id;

/**
* @param string $locale
* @param string $sender
* @param string $senderEmail
* @param string $subject
* @param string $contactsListId
* @param array $optionalProperties
*/
public function __construct(
string $locale,
string $sender,
string $senderEmail,
string $subject,
string $contactsListId,
array $optionalProperties = []
) {
$this->locale = $locale;
$this->sender = $sender;
$this->senderEmail = $senderEmail;
Expand Down
12 changes: 7 additions & 5 deletions src/Model/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ class Contact extends Model
/**
* @var string
*/
protected $email;
protected string $email;

/**
* @var string|null
*/
protected $name;
protected ?string $name;

/**
* @var string|null
*/
protected $action;
protected ?string $action;

public function __construct(string $email, array $optionalProperties = [])
{
Expand Down Expand Up @@ -63,6 +63,7 @@ public function format(): array

/**
* Correspond to Email in Mailjet request.
* @return string
*/
public function getEmail(): string
{
Expand All @@ -76,7 +77,7 @@ public function getEmail(): string
*
* @return Contact
*/
public function setEmail($email): Contact
public function setEmail(string $email): Contact
{
$this->email = $email;

Expand All @@ -85,6 +86,7 @@ public function setEmail($email): Contact

/**
* Correspond to Name in MailJet request.
* @return string|null
*/
public function getName(): ?string
{
Expand Down Expand Up @@ -122,7 +124,7 @@ public function getAction(): ?string
*
* @return Contact
*/
public function setAction($action): Contact
public function setAction(string $action): Contact
{
if (! $this->validateAction($action)) {
throw new RuntimeException("$action: is not a valid Action.");
Expand Down
4 changes: 2 additions & 2 deletions src/Model/ContactMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ class ContactMetadata implements Requestable
/**
* @var string
*/
protected $name;
protected string $name;

/**
* @var string
*/
protected $datatype;
protected string $datatype;

public function __construct(string $name, string $datatype)
{
Expand Down
20 changes: 14 additions & 6 deletions src/Model/ContactsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,23 @@ class ContactsList extends Model
/**
* @var string
*/
protected $listId;
protected string $listId;

/**
* @var string
*/
protected $action;
protected string $action;

/**
* @var array
*/
protected $contacts;
protected array $contacts;

/**
* @param string $listId
* @param string $action
* @param array $contacts
*/
public function __construct(string $listId, string $action, array $contacts)
{
if (! $this->validateAction($action)) {
Expand Down Expand Up @@ -62,6 +67,7 @@ public function format(): array

/**
* Get list id
* @return string
*/
public function getListId(): string
{
Expand All @@ -70,6 +76,7 @@ public function getListId(): string

/**
* Get action.
* @return string
*/
public function getAction(): string
{
Expand All @@ -78,10 +85,10 @@ public function getAction(): string

/**
* Set action.
*
* @param string $action
* @return ContactsList
*/
public function setAction($action): ContactsList
public function setAction(string $action): ContactsList
{
if (! $this->validateAction($action)) {
throw new RuntimeException("$action: is not a valid Action.");
Expand All @@ -94,6 +101,7 @@ public function setAction($action): ContactsList

/**
* Get contacts.
* @return array
*/
public function getContacts(): array
{
Expand All @@ -107,7 +115,7 @@ public function getContacts(): array
*
* @return bool
*/
protected function validateAction($action): bool
protected function validateAction(string $action): bool
{
$actionsAvailable = [self::ACTION_ADDFORCE, self::ACTION_ADDNOFORCE, self::ACTION_REMOVE, self::ACTION_UNSUB];

Expand Down
44 changes: 27 additions & 17 deletions src/Model/EventCallbackUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,51 +25,61 @@ class EventCallbackUrl implements Requestable
/**
* @var string|null
*/
protected $apiKeyId;
protected ?string $apiKeyId;

/**
* @var string
*/
protected $url;
protected string $url;

/**
* @var string
*/
protected $type;
protected string $type;

/**
* @var string
*/
protected $status;
protected string $status;

/**
* @var bool
*/
protected $isBackup;
protected bool $isBackup;

/**
* @var int
*/
protected $version;
protected int $version;

/**
* @var bool
*/
protected $groupEvent;

public function __construct($url,
$type = self::EVENT_TYPE_OPEN,
$groupEvent = false,
$isBackup = false,
$status = self::EVENT_STATUS_ALIVE,
$version = 1,
$apiKeyId = null
protected bool $groupEvent;

/**
* @param string $url
* @param string $type
* @param bool $groupEvent
* @param bool $isBackup
* @param string $status
* @param int $version
* @param $apiKeyId
*/
public function __construct(
string $url,
string $type = self::EVENT_TYPE_OPEN,
bool $groupEvent = false,
bool $isBackup = false,
string $status = self::EVENT_STATUS_ALIVE,
int $version = 1,
$apiKeyId = null
) {
if (! $this->validateType($type)) {
if (!$this->validateType($type)) {
throw new RuntimeException("$type: is not a valid event type.");
}

if (! $this->validateStatus($status)) {
if (!$this->validateStatus($status)) {
throw new RuntimeException("$status: is not a valid event status.");
}

Expand Down
2 changes: 1 addition & 1 deletion src/Model/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ abstract class Model implements Requestable
/**
* @var array
*/
protected $optionalProperties;
protected array $optionalProperties;

/**
* Format MailJet API request.
Expand Down
Loading

0 comments on commit 4eeb55a

Please sign in to comment.