Skip to content

Commit 254ea50

Browse files
committed
add return types
1 parent 580759e commit 254ea50

File tree

6 files changed

+116
-71
lines changed

6 files changed

+116
-71
lines changed

src/Ubiquity/mailer/AbstractMail.php

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
abstract class AbstractMail {
1717

18-
private $swapMethods = [
18+
private array $swapMethods = [
1919
'to' => 'addAddress',
2020
'cc' => 'addCC',
2121
'bcc' => 'addBCC',
@@ -28,56 +28,56 @@ abstract class AbstractMail {
2828
*
2929
* @var array
3030
*/
31-
public $from = [];
31+
public array $from = [];
3232

3333
/**
3434
* The "to" recipients of the message.
3535
*
3636
* @var array
3737
*/
38-
public $to = [];
38+
public array $to = [];
3939

4040
/**
4141
* The "cc" recipients of the message.
4242
*
4343
* @var array
4444
*/
45-
public $cc = [];
45+
public array $cc = [];
4646

4747
/**
4848
* The "bcc" recipients of the message.
4949
*
5050
* @var array
5151
*/
52-
public $bcc = [];
52+
public array $bcc = [];
5353

5454
/**
5555
* The "reply to" recipients of the message.
5656
*
5757
* @var array
5858
*/
59-
public $replyTo = [];
59+
public array $replyTo = [];
6060

6161
/**
6262
* The subject of the message.
6363
*
6464
* @var string
6565
*/
66-
public $subject;
66+
public string $subject;
6767

6868
/**
6969
* The attachments for the message.
7070
*
7171
* @var array
7272
*/
73-
public $attachments = [];
73+
public array $attachments = [];
7474

7575
/**
7676
* The raw attachments for the message.
7777
*
7878
* @var array
7979
*/
80-
public $rawAttachments = [];
80+
public array $rawAttachments = [];
8181

8282
/**
8383
* The callback for the message.
@@ -93,7 +93,7 @@ abstract class AbstractMail {
9393
* @param string|null $name
9494
* @return $this
9595
*/
96-
public function from($address, $name = null) {
96+
public function from($address, $name = null): self {
9797
return $this->setAddress($address, $name??$address, 'from');
9898
}
9999

@@ -104,7 +104,7 @@ public function from($address, $name = null) {
104104
* @param string|null $name
105105
* @return $this
106106
*/
107-
public function to($address, $name = null) {
107+
public function to($address, $name = null): self {
108108
return $this->setAddress($address, $name??$address, 'to');
109109
}
110110

@@ -115,7 +115,7 @@ public function to($address, $name = null) {
115115
* @param string|null $name
116116
* @return $this
117117
*/
118-
public function cc($address, $name = null) {
118+
public function cc($address, $name = null): self {
119119
return $this->setAddress($address, $name??$address, 'cc');
120120
}
121121

@@ -126,7 +126,7 @@ public function cc($address, $name = null) {
126126
* @param string|null $name
127127
* @return $this
128128
*/
129-
public function bcc($address, $name = null) {
129+
public function bcc($address, $name = null): self {
130130
return $this->setAddress($address, $name??$address, 'bcc');
131131
}
132132

@@ -137,7 +137,7 @@ public function bcc($address, $name = null) {
137137
* @param string|null $name
138138
* @return $this
139139
*/
140-
public function replyTo($address, $name = null) {
140+
public function replyTo($address, $name = null):self {
141141
return $this->setAddress($address, $name??$address, 'replyTo');
142142
}
143143

@@ -148,7 +148,7 @@ public function replyTo($address, $name = null) {
148148
* @param array $options
149149
* @return $this
150150
*/
151-
public function attachFile($file, array $options = []) {
151+
public function attachFile($file, array $options = []): self {
152152
$this->attachments[] = compact('file', 'options');
153153
return $this;
154154
}
@@ -161,7 +161,7 @@ public function attachFile($file, array $options = []) {
161161
* @param array $options
162162
* @return $this
163163
*/
164-
public function attachData($data, $name, array $options = []) {
164+
public function attachData($data, $name, array $options = []):self {
165165
$this->rawAttachments[] = compact('data', 'name', 'options');
166166
return $this;
167167
}
@@ -184,7 +184,7 @@ protected function buildRowAttachments(PHPMailer $mailer) {
184184
}
185185
}
186186

187-
public function getSubject() {
187+
public function getSubject():string {
188188
return $this->subject ?? \get_class();
189189
}
190190

@@ -196,7 +196,7 @@ public function getSubject() {
196196
* @param string $property
197197
* @return $this
198198
*/
199-
protected function setAddress($address, $name = null, $property = 'to') {
199+
protected function setAddress($address, $name = null, $property = 'to'):self {
200200
if (\is_object($address)) {
201201
$address = [
202202
$address
@@ -257,7 +257,7 @@ public function __construct() {
257257
* Define the message body
258258
* To override
259259
*/
260-
abstract public function body();
260+
abstract public function body():string ;
261261

262262
/**
263263
* Initialize the mail, before buiding
@@ -271,7 +271,7 @@ abstract protected function initialize();
271271
*/
272272
protected function beforeBuild() {}
273273

274-
public function bodyText() {}
274+
public function bodyText():?string {}
275275

276276
public function build(PHPMailer $mailer) {
277277
$this->beforeBuild();
@@ -316,7 +316,7 @@ protected function loadView($viewName, $pData = NULL) {
316316
return $this->view->render($viewName, TRUE);
317317
}
318318

319-
public function hasRecipients() {
319+
public function hasRecipients():bool {
320320
$res = 0;
321321
if (\is_array($this->to)) {
322322
$res += \sizeof($this->to);
@@ -330,12 +330,12 @@ public function hasRecipients() {
330330
return $res > 0;
331331
}
332332

333-
private function getMailerDir() {
333+
private function getMailerDir():string {
334334
$rc = new \ReflectionClass(\get_class($this));
335335
return \dirname($rc->getFileName()) . DIRECTORY_SEPARATOR;
336336
}
337337

338-
public function getAttachmentsDir() {
338+
public function getAttachmentsDir():string {
339339
return $this->getMailerDir() . 'attachments' . DIRECTORY_SEPARATOR;
340340
}
341341
}

src/Ubiquity/mailer/ArrayMail.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ArrayMail extends AbstractMail {
1515
*
1616
* @return array
1717
*/
18-
public function getArrayInfos() {
18+
public function getArrayInfos(): array {
1919
return $this->arrayInfos;
2020
}
2121

@@ -34,15 +34,15 @@ public function addArrayInfos(array $arrayInfos) {
3434
}
3535
}
3636

37-
public function body() {
37+
public function body():string {
3838
return $this->arrayInfos['body'] ?? '';
3939
}
4040

41-
public function bodyText() {
41+
public function bodyText():string {
4242
return $this->arrayInfos['bodyText'] ?? '';
4343
}
4444

45-
public function getSubject() {
45+
public function getSubject():string {
4646
return $this->arrayInfos['subject'] ?? '';
4747
}
4848

@@ -72,7 +72,7 @@ public static function copyFrom(AbstractMail $mail) {
7272
return $newMail;
7373
}
7474

75-
public function getAttachmentsDir() {
75+
public function getAttachmentsDir():string {
7676
return $this->arrayInfos['attachmentsDir'] ?? parent::getAttachmentsDir();
7777
}
7878

src/Ubiquity/mailer/MailerManager.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ class MailerManager {
2020
*
2121
* @var PHPMailer
2222
*/
23-
private static $mailer;
23+
private static PHPMailer $mailer;
2424

2525
/**
2626
*
2727
* @var MailerQueue
2828
*/
29-
private static $queue;
29+
private static MailerQueue $queue;
3030

31-
private static $config;
31+
private static array $config;
3232

33-
private static $dConfig = [
33+
private static array $dConfig = [
3434
'host' => '127.0.0.1',
3535
'port' => 587,
3636
'auth' => false,
@@ -41,7 +41,7 @@ class MailerManager {
4141
'ns' => 'mail'
4242
];
4343

44-
private static function getConfigPath() {
44+
private static function getConfigPath():string {
4545
return \ROOT . 'config' . \DS . 'mailer.php';
4646
}
4747

@@ -89,7 +89,7 @@ public static function saveConfig($config) {
8989
}
9090
}
9191

92-
public static function loadConfig() {
92+
public static function loadConfig():array {
9393
$path = self::getConfigPath();
9494
$config = [];
9595
if (\file_exists($path)) {
@@ -111,15 +111,15 @@ public static function getErrorInfo() {
111111
return self::$mailer->ErrorInfo;
112112
}
113113

114-
public static function getNamespace() {
114+
public static function getNamespace():string {
115115
return self::$config['ns'] ?? 'mail';
116116
}
117117

118118
/**
119119
*
120120
* @return \PHPMailer\PHPMailer\PHPMailer
121121
*/
122-
public static function getMailer() {
122+
public static function getMailer():PHPMailer {
123123
return MailerManager::$mailer;
124124
}
125125

@@ -134,7 +134,7 @@ public static function sendQueue($limit = NULL): int {
134134
return $i;
135135
}
136136

137-
public static function sendQueuedMail($index): bool {
137+
public static function sendQueuedMail(int $index): bool {
138138
return self::$queue->send($index);
139139
}
140140

@@ -144,7 +144,7 @@ public static function sendQueuedMail($index): bool {
144144
* @param int $index
145145
* @return bool
146146
*/
147-
public static function sendAgain($index): bool {
147+
public static function sendAgain(int $index): bool {
148148
return self::$queue->sendAgain($index);
149149
}
150150

@@ -154,7 +154,7 @@ public static function sendAgain($index): bool {
154154
* @param boolean $silent
155155
* @return array
156156
*/
157-
protected static function _getFiles($silent = false) {
157+
protected static function _getFiles(bool $silent = false):array {
158158
$typeDir = \ROOT . \DS . \str_replace("\\", \DS, self::getNamespace());
159159
if (! $silent) {
160160
echo 'Mail directory is ' . $typeDir . "\n";
@@ -190,7 +190,7 @@ protected static function applyConfig($config) {
190190
* @param boolean $silent
191191
* @return string[]
192192
*/
193-
public static function getMailClasses($silent = false) {
193+
public static function getMailClasses($silent = false):array {
194194
$result = [];
195195
$files = self::_getFiles($silent);
196196
foreach ($files as $file) {
@@ -199,11 +199,11 @@ public static function getMailClasses($silent = false) {
199199
return $result;
200200
}
201201

202-
public static function allInQueue() {
202+
public static function allInQueue():array {
203203
return self::$queue->all();
204204
}
205205

206-
public static function allInDequeue() {
206+
public static function allInDequeue():array {
207207
return self::$queue->allSent();
208208
}
209209

@@ -219,7 +219,7 @@ public static function sendBetween($class, \DateTime $startDate, \DateTime $endD
219219
self::$queue->sendBetween($class, $startDate, $endDate);
220220
}
221221

222-
public static function inQueue($class) {
222+
public static function inQueue($class):bool {
223223
return self::$queue->search($class);
224224
}
225225

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
namespace Ubiquity\mailer\models;
3+
4+
/**
5+
* Mailer AbstractAuthUrlExpireMail
6+
*/
7+
abstract class AbstractAuthUrlExpireMail extends \Ubiquity\mailer\AbstractMail {
8+
9+
protected string $url='';
10+
11+
protected $expire;
12+
13+
/**
14+
* @param string $url
15+
*/
16+
public function setUrl(string $url): void {
17+
$this->url = $url;
18+
}
19+
20+
/**
21+
* @return mixed
22+
*/
23+
public function getExpire() {
24+
return $this->expire;
25+
}
26+
27+
/**
28+
* @param mixed $expire
29+
*/
30+
public function setExpire($expire): void {
31+
$this->expire = $expire;
32+
}
33+
34+
}

0 commit comments

Comments
 (0)