Skip to content

Commit 0c50103

Browse files
authored
Add returntypes where possible (#48)
* In case the exact returntype is not yet possible, add it in docblock with a ReturnTypeWillChange-attribute. * Changed some instances of "static public function foo()" to "public static function foo()". * Added "public" to all constants which were public implicitly
1 parent 122fd5f commit 0c50103

24 files changed

+118
-95
lines changed

Diff for: composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
},
1414
"require-dev": {
1515
"swiftmailer/swiftmailer": "^6.1",
16-
"phpunit/phpunit": "^8.3"
16+
"phpunit/phpunit": "^8.3",
17+
"pear/pear-core-minimal": "^1.10"
1718
},
1819
"suggest": {
1920
"swiftmailer/swiftmailer": "Conversion to MIME (eml file) message format"

Diff for: src/MAPI/Item/Attachment.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function copyToStream($stream)
2525
fwrite($stream, $this->getData() ?? '');
2626
}
2727

28-
protected function storeEmbeddedOle($stream)
28+
protected function storeEmbeddedOle($stream): void
2929
{
3030
// this is very untested...
3131
//throw new \RuntimeException('Saving an OLE Compound Document is not supported');

Diff for: src/MAPI/Message/Attachment.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function getContentId(): ?string
9797
return $this->properties['attach_content_id'] ?? null;
9898
}
9999

100-
public function getEmbeddedOleData()
100+
public function getEmbeddedOleData(): ?string
101101
{
102102
$compobj = $this->properties["\01CompObj"];
103103
if (is_null($compobj)) {
@@ -106,7 +106,7 @@ public function getEmbeddedOleData()
106106
return substr($compobj, 32);
107107
}
108108

109-
public function isValid()
109+
public function isValid(): bool
110110
{
111111
return $this->properties !== null;
112112
}

Diff for: src/MAPI/Message/Message.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,18 @@ protected function buildRecipients()
8888
}
8989

9090
/** @return Attachment[] */
91-
public function getAttachments()
91+
public function getAttachments(): array
9292
{
9393
return $this->attachments;
9494
}
9595

9696
/** @return Recipient[] */
97-
public function getRecipients()
97+
public function getRecipients(): array
9898
{
9999
return $this->recipients;
100100
}
101101

102-
public function getRecipientsOfType($type)
102+
public function getRecipientsOfType($type): array
103103
{
104104
$response = [];
105105
foreach ($this->recipients as $r) {

Diff for: src/MAPI/Mime/HeaderCollection.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ class HeaderCollection implements \IteratorAggregate
66
{
77
protected $rawHeaders = [];
88

9-
public function getIterator()
9+
public function getIterator(): \ArrayIterator
1010
{
1111
return new \ArrayIterator($this->rawHeaders);
1212
}
1313

14-
public function add($header, $value = null)
14+
public function add($header, $value = null): void
1515
{
1616
if (is_null($value)) {
1717
//echo $header . "\n";
@@ -40,7 +40,7 @@ public function add($header, $value = null)
4040
}
4141
}
4242

43-
public function set($header, $value)
43+
public function set($header, $value): void
4444
{
4545
$key = strtolower($header);
4646
$val = [
@@ -77,13 +77,13 @@ public function getValue($header)
7777

7878
}
7979

80-
public function has($header)
80+
public function has($header): bool
8181
{
8282
$key = strtolower($header);
8383
return isset($this->rawHeaders[$key]);
8484
}
8585

86-
public function unset($header)
86+
public function unset($header): void
8787
{
8888
$key = strtolower($header);
8989
unset($this->rawHeaders[$key]);

Diff for: src/MAPI/Mime/Swiftmailer/Adapter/DependencySet.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class DependencySet {
99

1010
// override the HeaderFactory registration in the DI container
11-
public static function register($force = false)
11+
public static function register($force = false): void
1212
{
1313
static $registered = false;
1414

Diff for: src/MAPI/Mime/Swiftmailer/Adapter/HeaderFactory.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function __construct(Swift_Mime_HeaderEncoder $encoder, Swift_Encoder $pa
2222
$this->charset = $charset;
2323
}
2424

25-
public function createTextHeader($name, $value = null)
25+
public function createTextHeader($name, $value = null): UnstructuredHeader
2626
{
2727
$header = new UnstructuredHeader($name, $this->encoder);
2828
if (isset($value)) {
@@ -33,7 +33,7 @@ public function createTextHeader($name, $value = null)
3333
return $header;
3434
}
3535

36-
protected function setHeaderCharset(Swift_Mime_Header $header)
36+
protected function setHeaderCharset(Swift_Mime_Header $header): void
3737
{
3838
if (isset($this->charset)) {
3939
$header->setCharset($this->charset);

Diff for: src/MAPI/Mime/Swiftmailer/Adapter/UnstructuredHeader.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class UnstructuredHeader extends Swift_Mime_Headers_UnstructuredHeader
1818
*
1919
* @return bool
2020
*/
21-
protected function tokenNeedsEncoding($token)
21+
protected function tokenNeedsEncoding($token): bool
2222
{
2323
static $prevToken = '';
2424

Diff for: src/MAPI/Mime/Swiftmailer/Attachment.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static function wrap(BaseAttachment $attachment)
1717
return new self($attachment->obj, $attachment->parent);
1818
}
1919

20-
public function toMime()
20+
public function toMime(): \Swift_Attachment
2121
{
2222
DependencySet::register();
2323

@@ -67,7 +67,7 @@ public function toMimeString(): string
6767
return (string)$this->toMime();
6868
}
6969

70-
public function copyMimeToStream($stream)
70+
public function copyMimeToStream($stream): void
7171
{
7272
fwrite($stream, $this->toMimeString());
7373
}

Diff for: src/MAPI/Mime/Swiftmailer/Factory.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ public function __construct(bool $muteConversionExceptions = false)
1616
$this->muteConversionExceptions = $muteConversionExceptions;
1717
}
1818

19-
public function parseMessage(Element $root)
19+
public function parseMessage(Element $root): Message
2020
{
21-
$message = new \Hfig\MAPI\Mime\Swiftmailer\Message($root);
21+
$message = new Message($root);
2222
$message->setMuteConversionExceptions($this->muteConversionExceptions);
2323

2424
return $message;

Diff for: src/MAPI/Mime/Swiftmailer/Message.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static function wrap(BaseMessage $message)
2424
return new self($message->obj, $message->parent);
2525
}
2626

27-
public function toMime()
27+
public function toMime(): \Swift_Message
2828
{
2929
DependencySet::register();
3030

Diff for: src/MAPI/OLE/Guid/OleGuid.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class OleGuid
1111
/** @var UuidFactory */
1212
private static $factory = null;
1313

14-
protected static function getFactory()
14+
protected static function getFactory(): UuidFactory
1515
{
1616
if (!self::$factory) {
1717
self::$factory = new UuidFactory();

Diff for: src/MAPI/OLE/Pear/DocumentElement.php

+15-18
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function getIndex()
3232
return $this->pps->No;
3333
}
3434

35-
public function setIndex($index)
35+
public function setIndex($index): void
3636
{
3737
$this->pps->No = $index;
3838
}
@@ -42,12 +42,12 @@ public function getName()
4242
return $this->pps->Name;
4343
}
4444

45-
public function setName($name)
45+
public function setName($name): void
4646
{
4747
$this->pps->Name = $name;
4848
}
4949

50-
public function getType()
50+
public function getType(): ?int
5151
{
5252
static $map = [
5353
OLE_PPS_TYPE_ROOT => CompoundDocumentElement::TYPE_ROOT,
@@ -58,7 +58,7 @@ public function getType()
5858
return $map[$this->pps->Type] ?? null;
5959
}
6060

61-
public function setType($type)
61+
public function setType($type): void
6262
{
6363
static $map = [
6464
CompoundDocumentElement::TYPE_ROOT => OLE_PPS_TYPE_ROOT,
@@ -73,17 +73,17 @@ public function setType($type)
7373
$this->pps->Type = $map[$type];
7474
}
7575

76-
public function isDirectory()
76+
public function isDirectory(): bool
7777
{
7878
return ($this->getType() == CompoundDocumentElement::TYPE_DIRECTORY);
7979
}
8080

81-
public function isFile()
81+
public function isFile(): bool
8282
{
8383
return ($this->getType() == CompoundDocumentElement::TYPE_FILE);
8484
}
8585

86-
public function isRoot()
86+
public function isRoot(): bool
8787
{
8888
return ($this->getType() == CompoundDocumentElement::TYPE_ROOT);
8989
}
@@ -93,7 +93,7 @@ public function getPreviousIndex()
9393
return $this->pps->PrevPps;
9494
}
9595

96-
public function setPreviousIndex($index)
96+
public function setPreviousIndex($index): void
9797
{
9898
$this->pps->PrevPps = $index;
9999
}
@@ -103,7 +103,7 @@ public function getNextIndex()
103103
return $this->pps->NextPps;
104104
}
105105

106-
public function setNextIndex($index)
106+
public function setNextIndex($index): void
107107
{
108108
$this->pps->NextPps = $index;
109109
}
@@ -113,7 +113,7 @@ public function getFirstChildIndex()
113113
return $this->pps->DirPps;
114114
}
115115

116-
public function setFirstChildIndex($index)
116+
public function setFirstChildIndex($index): void
117117
{
118118
$this->pps->DirPps = $index;
119119
}
@@ -123,7 +123,7 @@ public function getTimeCreated()
123123
return $this->pps->Time1st;
124124
}
125125

126-
public function setTimeCreated($time)
126+
public function setTimeCreated($time): void
127127
{
128128
$this->pps->Time1st = $time;
129129
}
@@ -133,7 +133,7 @@ public function getTimeModified()
133133
return $this->pps->Time2nd;
134134
}
135135

136-
public function setTimeModified($time)
136+
public function setTimeModified($time): void
137137
{
138138
$this->pps->Time2nd = $time;
139139
}
@@ -149,15 +149,12 @@ public function getSize()
149149
return $this->pps->Size;
150150
}
151151

152-
public function setSize($size)
152+
public function setSize($size): void
153153
{
154154
$this->pps->Size = $size;
155155
}
156156

157-
/**
158-
* @return DocumentElementCollection
159-
*/
160-
public function getChildren()
157+
public function getChildren(): DocumentElementCollection
161158
{
162159
//if (!$this->wrappedChildren) {
163160
// $this->wrappedChildren = new DocumentElementCollection($this->ole, $this->pps->Children);
@@ -179,7 +176,7 @@ public function unwrap()
179176
return $this->pps;
180177
}
181178

182-
public function saveToStream($stream)
179+
public function saveToStream($stream): void
183180
{
184181

185182

Diff for: src/MAPI/OLE/Pear/DocumentElementCollection.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,23 @@ public function __construct(OLE $ole, array &$collection = null)
2121
$this->ole = $ole;
2222
}
2323

24-
public function getIterator()
24+
public function getIterator(): \Traversable
2525
{
2626
foreach ($this->col as $k => $v)
2727
{
2828
yield $k => $this->offsetGet($k);
2929
}
3030
}
3131

32-
public function offsetExists($offset)
32+
public function offsetExists($offset): bool
3333
{
3434
return isset($this->col[$offset]);
3535
}
3636

37+
/**
38+
* @return mixed
39+
*/
40+
#[\ReturnTypeWillChange]
3741
public function offsetGet($offset)
3842
{
3943
if (!isset($this->col[$offset])) {
@@ -47,7 +51,7 @@ public function offsetGet($offset)
4751
return $this->proxy_col[$offset];
4852
}
4953

50-
public function offsetSet($offset, $value)
54+
public function offsetSet($offset, $value): void
5155
{
5256
if (!$value instanceof DocumentElement) {
5357
throw new \InvalidArgumentException('Collection must contain DocumentElement instances');
@@ -57,7 +61,7 @@ public function offsetSet($offset, $value)
5761
$this->col[$offset] = $value->unwrap();
5862
}
5963

60-
public function offsetUnset($offset)
64+
public function offsetUnset($offset): void
6165
{
6266
unset($this->proxy_col[$offset]);
6367
unset($this->col[$offset]);

0 commit comments

Comments
 (0)