Skip to content

Commit 6e76b35

Browse files
committed
Method return and argument types added #212
1 parent f565c3b commit 6e76b35

23 files changed

+481
-474
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
66

77
## [UNRELEASED]
88
### Fixed
9-
- NaN
9+
- PHP dependency updated to support php v8.0 #212 #214 (thanks @freescout-helpdesk)
10+
- Method return and argument types added
1011

1112
### Added
1213
- NaN
@@ -15,7 +16,7 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip
1516
- NaN
1617

1718
### Breaking changes
18-
- NaN
19+
- No longer supports php >=5.5.9 but instead requires at least php v7.0.0
1920

2021

2122
## [3.2.0] - 2022-03-07

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
}
2020
],
2121
"require": {
22-
"php": ">=5.5.9",
22+
"php": ">=7.0.0",
2323
"ext-openssl": "*",
2424
"ext-json": "*",
2525
"ext-mbstring": "*",

src/Address.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function __construct($object) {
5252
* @return string
5353
*/
5454
public function __toString() {
55-
return $this->full ? $this->full : "";
55+
return $this->full ?: "";
5656
}
5757

5858
/**
@@ -75,7 +75,7 @@ public function __serialize(){
7575
*
7676
* @return array
7777
*/
78-
public function toArray(){
78+
public function toArray(): array {
7979
return $this->__serialize();
8080
}
8181

@@ -84,7 +84,7 @@ public function toArray(){
8484
*
8585
* @return string
8686
*/
87-
public function toString(){
87+
public function toString(): string {
8888
return $this->__toString();
8989
}
9090
}

src/Attachment.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public function __construct(Message $oMessage, Part $part) {
119119
* @return mixed
120120
* @throws MethodNotFoundException
121121
*/
122-
public function __call($method, $arguments) {
122+
public function __call(string $method, array $arguments) {
123123
if(strtolower(substr($method, 0, 3)) === 'get') {
124124
$name = Str::snake(substr($method, 3));
125125

@@ -242,8 +242,8 @@ protected function fetch() {
242242
*
243243
* @return boolean
244244
*/
245-
public function save($path, $filename = null) {
246-
$filename = $filename ? $filename : $this->getName();
245+
public function save(string $path, $filename = null): bool {
246+
$filename = $filename ?: $this->getName();
247247

248248
return file_put_contents($path.$filename, $this->getContent()) !== false;
249249
}
@@ -280,26 +280,28 @@ public function getMimeType(){
280280
public function getExtension(){
281281
$deprecated_guesser = "\Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser";
282282
if (class_exists($deprecated_guesser) !== false){
283+
/** @var \Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser $deprecated_guesser */
283284
return $deprecated_guesser::getInstance()->guess($this->getMimeType());
284285
}
285286
$guesser = "\Symfony\Component\Mime\MimeTypes";
287+
/** @var Symfony\Component\Mime\MimeTypes $guesser */
286288
$extensions = $guesser::getDefault()->getExtensions($this->getMimeType());
287-
return isset($extensions[0]) ? $extensions[0] : null;
289+
return $extensions[0] ?? null;
288290
}
289291

290292
/**
291293
* Get all attributes
292294
*
293295
* @return array
294296
*/
295-
public function getAttributes(){
297+
public function getAttributes(): array {
296298
return $this->attributes;
297299
}
298300

299301
/**
300302
* @return Message
301303
*/
302-
public function getMessage(){
304+
public function getMessage(): Message {
303305
return $this->oMessage;
304306
}
305307

@@ -309,7 +311,7 @@ public function getMessage(){
309311
*
310312
* @return $this
311313
*/
312-
public function setMask($mask){
314+
public function setMask($mask): Attachment {
313315
if(class_exists($mask)){
314316
$this->mask = $mask;
315317
}
@@ -322,7 +324,7 @@ public function setMask($mask){
322324
*
323325
* @return string
324326
*/
325-
public function getMask(){
327+
public function getMask(): string {
326328
return $this->mask;
327329
}
328330

src/Attribute.php

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
use ArrayAccess;
1616
use Carbon\Carbon;
17+
use ReturnTypeWillChange;
1718

1819
/**
1920
* Class Attribute
@@ -34,10 +35,10 @@ class Attribute implements ArrayAccess {
3435

3536
/**
3637
* Attribute constructor.
37-
* @param string $name
38+
* @param string $name
3839
* @param array|mixed $value
3940
*/
40-
public function __construct($name, $value = null) {
41+
public function __construct(string $name, $value = null) {
4142
$this->setName($name);
4243
$this->add($value);
4344
}
@@ -57,7 +58,7 @@ public function __toString() {
5758
*
5859
* @return string
5960
*/
60-
public function toString(){
61+
public function toString(): string {
6162
return $this->__toString();
6263
}
6364

@@ -66,16 +67,16 @@ public function toString(){
6667
*
6768
* @return array
6869
*/
69-
public function toArray(){
70+
public function toArray(): array {
7071
return $this->values;
7172
}
7273

7374
/**
7475
* Convert first value to a date object
7576
*
76-
* @return Carbon|null
77+
* @return Carbon
7778
*/
78-
public function toDate(){
79+
public function toDate(): Carbon {
7980
$date = $this->first();
8081
if ($date instanceof Carbon) return $date;
8182

@@ -85,47 +86,49 @@ public function toDate(){
8586
/**
8687
* Determine if a value exists at an offset.
8788
*
88-
* @param mixed $key
89+
* @param mixed $offset
8990
* @return bool
9091
*/
91-
public function offsetExists($key): bool {
92-
return array_key_exists($key, $this->values);
92+
public function offsetExists($offset): bool {
93+
return array_key_exists($offset, $this->values);
9394
}
9495

9596
/**
9697
* Get a value at a given offset.
9798
*
98-
* @param mixed $key
99+
* @param mixed $offset
99100
* @return mixed
100101
*/
101-
#[\ReturnTypeWillChange]
102-
public function offsetGet($key) {
103-
return $this->values[$key];
102+
#[ReturnTypeWillChange]
103+
public function offsetGet($offset) {
104+
return $this->values[$offset];
104105
}
105106

106107
/**
107108
* Set the value at a given offset.
108109
*
109-
* @param mixed $key
110+
* @param mixed $offset
110111
* @param mixed $value
111112
* @return void
112113
*/
113-
public function offsetSet($key, $value): void {
114-
if (is_null($key)) {
114+
#[ReturnTypeWillChange]
115+
public function offsetSet($offset, $value) {
116+
if (is_null($offset)) {
115117
$this->values[] = $value;
116118
} else {
117-
$this->values[$key] = $value;
119+
$this->values[$offset] = $value;
118120
}
119121
}
120122

121123
/**
122124
* Unset the value at a given offset.
123125
*
124-
* @param string $key
126+
* @param string $offset
125127
* @return void
126128
*/
127-
public function offsetUnset($key): void {
128-
unset($this->values[$key]);
129+
#[ReturnTypeWillChange]
130+
public function offsetUnset($offset) {
131+
unset($this->values[$offset]);
129132
}
130133

131134
/**
@@ -135,7 +138,7 @@ public function offsetUnset($key): void {
135138
*
136139
* @return Attribute
137140
*/
138-
public function add($value, $strict = false) {
141+
public function add($value, bool $strict = false): Attribute {
139142
if (is_array($value)) {
140143
return $this->merge($value, $strict);
141144
}elseif ($value !== null) {
@@ -152,11 +155,9 @@ public function add($value, $strict = false) {
152155
*
153156
* @return Attribute
154157
*/
155-
public function merge($values, $strict = false) {
156-
if (is_array($values)) {
157-
foreach ($values as $value) {
158-
$this->attach($value, $strict);
159-
}
158+
public function merge(array $values, bool $strict = false): Attribute {
159+
foreach ($values as $value) {
160+
$this->attach($value, $strict);
160161
}
161162

162163
return $this;
@@ -168,7 +169,7 @@ public function merge($values, $strict = false) {
168169
*
169170
* @return bool
170171
*/
171-
public function contains($value) {
172+
public function contains($value): bool {
172173
foreach ($this->values as $v) {
173174
if ($v === $value) {
174175
return true;
@@ -182,7 +183,7 @@ public function contains($value) {
182183
* @param $value
183184
* @param bool $strict
184185
*/
185-
public function attach($value, $strict = false) {
186+
public function attach($value, bool $strict = false) {
186187
if ($strict === true) {
187188
if ($this->contains($value) === false) {
188189
$this->values[] = $value;
@@ -198,7 +199,7 @@ public function attach($value, $strict = false) {
198199
*
199200
* @return Attribute
200201
*/
201-
public function setName($name){
202+
public function setName($name): Attribute {
202203
$this->name = $name;
203204

204205
return $this;
@@ -209,7 +210,7 @@ public function setName($name){
209210
*
210211
* @return string
211212
*/
212-
public function getName(){
213+
public function getName(): string {
213214
return $this->name;
214215
}
215216

@@ -218,7 +219,7 @@ public function getName(){
218219
*
219220
* @return array
220221
*/
221-
public function get(){
222+
public function get(): array {
222223
return $this->values;
223224
}
224225

@@ -227,7 +228,7 @@ public function get(){
227228
*
228229
* @return array
229230
*/
230-
public function all(){
231+
public function all(): array {
231232
return $this->get();
232233
}
233234

@@ -260,7 +261,7 @@ public function last(){
260261
*
261262
* @return int
262263
*/
263-
public function count(){
264+
public function count(): int {
264265
return count($this->values);
265266
}
266267
}

0 commit comments

Comments
 (0)