Skip to content

Commit 4eeb55a

Browse files
Merge pull request #80 from mailjet/DE-1302-laravel-no-exceptions-errors-thrown-on-config-error
End of support php 7.3 and below. PHP 7.4+ only
2 parents bded9b6 + 6f886e3 commit 4eeb55a

27 files changed

+123
-74
lines changed

composer.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
}
3131
],
3232
"require": {
33-
"php": "^7.1.3|^8.0",
33+
"php": "^7.4|^8.0",
3434
"laravel/framework": "^9.0|^10.0|^11.0",
3535
"mailjet/mailjet-apiv3-php": "^1.5.6|^1.5",
3636
"symfony/http-client": "^7.1",
@@ -39,8 +39,9 @@
3939
"require-dev": {
4040
"fakerphp/faker": "~1",
4141
"mockery/mockery": "0.9.*|^1.0",
42-
"phpunit/phpunit": "~7.0|^8.0|^9|^10.0",
43-
"orchestra/testbench": "3.6|^4.0|^5.0|^6.0|^8.0|^9.0"
42+
"orchestra/testbench": "3.6|^4.0|^5.0|^6.0|^8.0|^9.0",
43+
"phpcompatibility/php-compatibility": "^9.3",
44+
"phpunit/phpunit": "~7.0|^8.0|^9|^10.0"
4445
},
4546
"autoload": {
4647
"psr-4": {
@@ -65,5 +66,9 @@
6566
"config": {
6667
"sort-packages": true,
6768
"bin-dir": "bin"
69+
},
70+
"scripts": {
71+
"post-install-cmd": "\"bin/phpcs\" --config-set installed_paths vendor/phpcompatibility/php-compatibility",
72+
"post-update-cmd" : "\"bin/phpcs\" --config-set installed_paths vendor/phpcompatibility/php-compatibility"
6873
}
6974
}

src/Exception/MailjetException.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ class MailjetException extends \Exception
1212
/**
1313
* @var string
1414
*/
15-
private $errorInfo;
15+
private string $errorInfo;
1616

1717
/**
1818
* @var string
1919
*/
20-
private $errorMessage;
20+
private string $errorMessage;
2121

2222
/**
2323
* @var string
2424
*/
25-
private $errorIdentifier;
25+
private string $errorIdentifier;
2626

2727
/**
2828
* https://dev.mailjet.com/guides/#about-the-mailjet-restful-api

src/MailjetServiceProvider.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

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

47+
if (!isset($config['key'], $config['secret'])) {
48+
throw new InvalidArgumentException('The Mailjet service is not configured.');
49+
}
50+
4651
return new MailjetService($config['key'], $config['secret'], $call, $options);
4752
});
4853
}

src/Model/Campaign.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Campaign extends Model
1414
/**
1515
* @var string
1616
*/
17-
protected $fromEmail;
17+
protected string $fromEmail;
1818

1919
/**
2020
* @param string $fromEmail

src/Model/CampaignDraft.php

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,45 +18,54 @@ class CampaignDraft extends Model
1818
/**
1919
* @var string
2020
*/
21-
protected $locale;
21+
protected string $locale;
2222

2323
/**
2424
* @var string
2525
*/
26-
protected $sender;
26+
protected string $sender;
2727

2828
/**
2929
* @var string
3030
*/
31-
protected $senderEmail;
31+
protected string $senderEmail;
3232

3333
/**
3434
* @var string
3535
*/
36-
protected $subject;
36+
protected string $subject;
3737

3838
/**
3939
* @var string
4040
*/
41-
protected $contactsListId;
41+
protected string $contactsListId;
4242

4343
/**
4444
* @var array|null
4545
*/
46-
protected $content;
46+
protected ?array $content;
4747

4848
/**
4949
* @var string|null
5050
*/
51-
protected $id;
52-
53-
public function __construct(string $locale,
54-
string $sender,
55-
string $senderEmail,
56-
string $subject,
57-
string $contactsListId,
58-
array $optionalProperties = [])
59-
{
51+
protected ?string $id;
52+
53+
/**
54+
* @param string $locale
55+
* @param string $sender
56+
* @param string $senderEmail
57+
* @param string $subject
58+
* @param string $contactsListId
59+
* @param array $optionalProperties
60+
*/
61+
public function __construct(
62+
string $locale,
63+
string $sender,
64+
string $senderEmail,
65+
string $subject,
66+
string $contactsListId,
67+
array $optionalProperties = []
68+
) {
6069
$this->locale = $locale;
6170
$this->sender = $sender;
6271
$this->senderEmail = $senderEmail;

src/Model/Contact.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ class Contact extends Model
2424
/**
2525
* @var string
2626
*/
27-
protected $email;
27+
protected string $email;
2828

2929
/**
3030
* @var string|null
3131
*/
32-
protected $name;
32+
protected ?string $name;
3333

3434
/**
3535
* @var string|null
3636
*/
37-
protected $action;
37+
protected ?string $action;
3838

3939
public function __construct(string $email, array $optionalProperties = [])
4040
{
@@ -63,6 +63,7 @@ public function format(): array
6363

6464
/**
6565
* Correspond to Email in Mailjet request.
66+
* @return string
6667
*/
6768
public function getEmail(): string
6869
{
@@ -76,7 +77,7 @@ public function getEmail(): string
7677
*
7778
* @return Contact
7879
*/
79-
public function setEmail($email): Contact
80+
public function setEmail(string $email): Contact
8081
{
8182
$this->email = $email;
8283

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

8687
/**
8788
* Correspond to Name in MailJet request.
89+
* @return string|null
8890
*/
8991
public function getName(): ?string
9092
{
@@ -122,7 +124,7 @@ public function getAction(): ?string
122124
*
123125
* @return Contact
124126
*/
125-
public function setAction($action): Contact
127+
public function setAction(string $action): Contact
126128
{
127129
if (! $this->validateAction($action)) {
128130
throw new RuntimeException("$action: is not a valid Action.");

src/Model/ContactMetadata.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ class ContactMetadata implements Requestable
2020
/**
2121
* @var string
2222
*/
23-
protected $name;
23+
protected string $name;
2424

2525
/**
2626
* @var string
2727
*/
28-
protected $datatype;
28+
protected string $datatype;
2929

3030
public function __construct(string $name, string $datatype)
3131
{

src/Model/ContactsList.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,23 @@ class ContactsList extends Model
1919
/**
2020
* @var string
2121
*/
22-
protected $listId;
22+
protected string $listId;
2323

2424
/**
2525
* @var string
2626
*/
27-
protected $action;
27+
protected string $action;
2828

2929
/**
3030
* @var array
3131
*/
32-
protected $contacts;
32+
protected array $contacts;
3333

34+
/**
35+
* @param string $listId
36+
* @param string $action
37+
* @param array $contacts
38+
*/
3439
public function __construct(string $listId, string $action, array $contacts)
3540
{
3641
if (! $this->validateAction($action)) {
@@ -62,6 +67,7 @@ public function format(): array
6267

6368
/**
6469
* Get list id
70+
* @return string
6571
*/
6672
public function getListId(): string
6773
{
@@ -70,6 +76,7 @@ public function getListId(): string
7076

7177
/**
7278
* Get action.
79+
* @return string
7380
*/
7481
public function getAction(): string
7582
{
@@ -78,10 +85,10 @@ public function getAction(): string
7885

7986
/**
8087
* Set action.
81-
*
8288
* @param string $action
89+
* @return ContactsList
8390
*/
84-
public function setAction($action): ContactsList
91+
public function setAction(string $action): ContactsList
8592
{
8693
if (! $this->validateAction($action)) {
8794
throw new RuntimeException("$action: is not a valid Action.");
@@ -94,6 +101,7 @@ public function setAction($action): ContactsList
94101

95102
/**
96103
* Get contacts.
104+
* @return array
97105
*/
98106
public function getContacts(): array
99107
{
@@ -107,7 +115,7 @@ public function getContacts(): array
107115
*
108116
* @return bool
109117
*/
110-
protected function validateAction($action): bool
118+
protected function validateAction(string $action): bool
111119
{
112120
$actionsAvailable = [self::ACTION_ADDFORCE, self::ACTION_ADDNOFORCE, self::ACTION_REMOVE, self::ACTION_UNSUB];
113121

src/Model/EventCallbackUrl.php

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,51 +25,61 @@ class EventCallbackUrl implements Requestable
2525
/**
2626
* @var string|null
2727
*/
28-
protected $apiKeyId;
28+
protected ?string $apiKeyId;
2929

3030
/**
3131
* @var string
3232
*/
33-
protected $url;
33+
protected string $url;
3434

3535
/**
3636
* @var string
3737
*/
38-
protected $type;
38+
protected string $type;
3939

4040
/**
4141
* @var string
4242
*/
43-
protected $status;
43+
protected string $status;
4444

4545
/**
4646
* @var bool
4747
*/
48-
protected $isBackup;
48+
protected bool $isBackup;
4949

5050
/**
5151
* @var int
5252
*/
53-
protected $version;
53+
protected int $version;
5454

5555
/**
5656
* @var bool
5757
*/
58-
protected $groupEvent;
59-
60-
public function __construct($url,
61-
$type = self::EVENT_TYPE_OPEN,
62-
$groupEvent = false,
63-
$isBackup = false,
64-
$status = self::EVENT_STATUS_ALIVE,
65-
$version = 1,
66-
$apiKeyId = null
58+
protected bool $groupEvent;
59+
60+
/**
61+
* @param string $url
62+
* @param string $type
63+
* @param bool $groupEvent
64+
* @param bool $isBackup
65+
* @param string $status
66+
* @param int $version
67+
* @param $apiKeyId
68+
*/
69+
public function __construct(
70+
string $url,
71+
string $type = self::EVENT_TYPE_OPEN,
72+
bool $groupEvent = false,
73+
bool $isBackup = false,
74+
string $status = self::EVENT_STATUS_ALIVE,
75+
int $version = 1,
76+
$apiKeyId = null
6777
) {
68-
if (! $this->validateType($type)) {
78+
if (!$this->validateType($type)) {
6979
throw new RuntimeException("$type: is not a valid event type.");
7080
}
7181

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

src/Model/Model.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ abstract class Model implements Requestable
99
/**
1010
* @var array
1111
*/
12-
protected $optionalProperties;
12+
protected array $optionalProperties;
1313

1414
/**
1515
* Format MailJet API request.

0 commit comments

Comments
 (0)