for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Defines Ingenerator\Mailhook\EmailParser
*
* @copyright 2014 inGenerator Ltd
* @licence BSD
*/
namespace Ingenerator\Mailhook;
* Parses a single email into an Email object
* @package Ingenerator\Mailhook
* @see spec\Ingenerator\Mailhook\EmailParserSpec
class EmailParser {
* @param string $raw_message
* @return Email
public function parse($raw_message)
{
list($headers, $content) = \explode("\n\n", $raw_message, 2);
$data = array(
'to' => NULL,
'subject' => NULL,
'content' => \quoted_printable_decode($content)
);
$data['links'] = $this->parseLinksFromContent($data['content']);
$data['to'] = $this->parseRecipient($headers);
if (\preg_match('/^Subject:\s+(.+?)$/m', $headers, $matches))
$data['subject'] = $matches[1];
}
return new Email($data);
$data
array<string,null|string|array<integer,string>>
array<integer,string>
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example:
function acceptsInteger($int) { } $x = '123'; // string "123" // Instead of acceptsInteger($x); // we recommend to use acceptsInteger((integer) $x);
* @param string $content
* @return string[]
protected function parseLinksFromContent($content)
if (\preg_match_all('_https?://[^\s^"^<]+_', $content, $matches))
$links = $matches[0];
return \array_values(\array_unique($links));
else
return array();
* @param string $headers
* @return string
protected function parseRecipient($headers)
if ( ! \preg_match('/^To:\s+([^<]*?)(<[^>]+>)?$/m', $headers, $matches))
return NULL;
if (isset($matches[2]) && $matches[2])
return \trim($matches[2], '<>');
return $matches[1];
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: