Skip to content

Commit

Permalink
[TASK] Fix phpstan checkFunctionArgumentTypes errors in ext:core Mail
Browse files Browse the repository at this point in the history
This patch fixes incompatible type usage in function arguments
and is preparatory work for introducing native type hints and
strict mode in all core files.

Releases: master, 10.4
Resolves: #92282
Change-Id: I7eac7f91fe1461a73f2f3dc5cf6988fb91274de1
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/66037
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
  • Loading branch information
alexanderschnitzler authored and ervaude committed Oct 6, 2020
1 parent f78c9a7 commit fa109a5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions typo3/sysext/core/Classes/Mail/FileSpool.php
Expand Up @@ -123,7 +123,7 @@ public function setRetryLimit(int $limit): void
public function recover(int $timeout = 900): void
{
foreach (new DirectoryIterator($this->path) as $file) {
$file = $file->getRealPath();
$file = (string)$file->getRealPath();

if (substr($file, -16) == '.message.sending') {
$lockedtime = filectime($file);
Expand All @@ -144,15 +144,15 @@ public function flushQueue(TransportInterface $transport): int
$count = 0;
$time = time();
foreach ($directoryIterator as $file) {
$file = $file->getRealPath();
$file = (string)$file->getRealPath();

if (substr($file, -8) != '.message') {
continue;
}

/* We try a rename, it's an atomic operation, and avoid locking the file */
if (rename($file, $file . '.sending')) {
$message = unserialize(file_get_contents($file . '.sending'), [
$message = unserialize((string)file_get_contents($file . '.sending'), [
'allowedClasses' => [
RawMessage::class,
Message::class,
Expand Down Expand Up @@ -247,13 +247,13 @@ public function __toString(): string
$result = '';
$directoryIterator = new DirectoryIterator($this->path);
foreach ($directoryIterator as $file) {
$file = $file->getRealPath();
$file = (string)$file->getRealPath();

if (substr($file, -8) != '.message') {
continue;
}

$result .= file_get_contents($file) . "\n";
$result .= (string)file_get_contents($file) . "\n";
}
return $result;
}
Expand Down
2 changes: 1 addition & 1 deletion typo3/sysext/core/Classes/Mail/MailMessage.php
Expand Up @@ -241,7 +241,7 @@ public function setReadReceiptTo(string $address): self
/**
* Converts address from [email, name] into Address objects.
*
* @param array<int,mixed> $args
* @param mixed ...$args
* @return Address[]
*/
protected function convertNamedAddress(...$args): array
Expand Down
2 changes: 1 addition & 1 deletion typo3/sysext/core/Classes/Mail/Mailer.php
Expand Up @@ -114,7 +114,7 @@ public function send(RawMessage $message, Envelope $envelope = null): void
if ($address === 0) {
$replyTo = new Address($replyTo[$address]);
} else {
$replyTo = new Address($address, reset($replyTo));
$replyTo = new Address((string)$address, reset($replyTo));
}
$message->replyTo($replyTo);
}
Expand Down
16 changes: 8 additions & 8 deletions typo3/sysext/core/Classes/Mail/Rfc822AddressesParser.php
Expand Up @@ -179,20 +179,20 @@ public function parseAddressList($address = null, $default_domain = null, $valid
$this->error = null;
$this->index = null;
// Unfold any long lines in $this->address.
$this->address = preg_replace('/\\r?\\n/', '
$this->address = (string)preg_replace('/\\r?\\n/', '
', $this->address);
$this->address = preg_replace('/\\r\\n(\\t| )+/', ' ', $this->address);
$this->address = (string)preg_replace('/\\r\\n(\\t| )+/', ' ', $this->address);
while ($this->address = $this->_splitAddresses($this->address)) {
}
if ($this->address === false || isset($this->error)) {
throw new \InvalidArgumentException($this->error, 1294681466);
throw new \InvalidArgumentException((string)$this->error, 1294681466);
}
// Validate each address individually. If we encounter an invalid
// address, stop iterating and return an error immediately.
foreach ($this->addresses as $address) {
$valid = $this->_validateAddress($address);
if ($valid === false || isset($this->error)) {
throw new \InvalidArgumentException($this->error, 1294681467);
throw new \InvalidArgumentException((string)$this->error, 1294681467);
}
$this->structure = array_merge($this->structure, $valid);
}
Expand Down Expand Up @@ -223,7 +223,7 @@ protected function _splitAddresses($address)
return false;
}
// Split the string based on the above ten or so lines.
$parts = explode($split_char, $address);
$parts = explode($split_char, $address) ?: [];
$string = $this->_splitCheck($parts, $split_char);
// If a group...
if ($is_group) {
Expand Down Expand Up @@ -376,7 +376,7 @@ protected function _hasUnclosedBrackets($string, $chars)
*/
protected function _hasUnclosedBracketsSub($string, &$num, $char)
{
$parts = explode($char, $string);
$parts = explode($char, $string) ?: [];
$partsCounter = count($parts);
for ($i = 0; $i < $partsCounter; $i++) {
if (substr($parts[$i], -1) === '\\' || $this->_hasUnclosedQuotes($parts[$i])) {
Expand Down Expand Up @@ -535,9 +535,9 @@ protected function _validateAtom($atom)
protected function _validateQuotedString($qstring)
{
// Leading and trailing "
$qstring = substr($qstring, 1, -1);
$qstring = (string)substr($qstring, 1, -1);
// Perform check, removing quoted characters first.
return !preg_match('/[\\x0D\\\\"]/', preg_replace('/\\\\./', '', $qstring));
return !preg_match('/[\\x0D\\\\"]/', (string)preg_replace('/\\\\./', '', $qstring));
}

/**
Expand Down

0 comments on commit fa109a5

Please sign in to comment.