Test Failed
Pull Request — master (#171)
by Zaahid
04:32
created

MessageParser::readLine()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 8
rs 10
1
<?php
2
/**
3
 * This file is part of the ZBateson\MailMimeParser project.
4
 *
5
 * @license http://opensource.org/licenses/bsd-license.php BSD
6
 */
7
namespace ZBateson\MailMimeParser\Parser;
8
9
use ZBateson\MailMimeParser\Message\Factory\PartHeaderContainerFactory;
10
use ZBateson\MailMimeParser\Parser\Proxy\ParserMessageFactory;
0 ignored issues
show
Bug introduced by
The type ZBateson\MailMimeParser\...xy\ParserMessageFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Psr\Http\Message\StreamInterface;
12
13
/**
14
 * Parses a mail mime message into its component parts.  To invoke, call
15
 * {@see MailMimeParser::parse()}.
16
 *
17
 * @author Zaahid Bateson
18
 */
19
class MessageParser
20
{
21
    /**
22
     * @var PartHeaderContainerFactory
23
     */
24
    protected $partHeaderContainerFactory;
25
26
    /**
27
     * @var ParserManager
28
     */
29
    protected $parserManager;
30
31
    /**
32
     * @var PartBuilderFactory
33
     */
34
    protected $partBuilderFactory;
35
36
    /**
37
     * @var HeaderParser
38
     */
39
    protected $headerParser;
40
41
    public function __construct(
42
        PartBuilderFactory $pbf,
43
        PartHeaderContainerFactory $phcf,
44
        ParserManager $pm,
45
        HeaderParser $hp
46
    ) {
47
        $this->partBuilderFactory = $pbf;
48
        $this->partHeaderContainerFactory = $phcf;
49
        $this->parserManager = $pm;
50
        $this->headerParser = $hp;
51
    }
52
53
    /**
54
     * Convenience method to read a line of up to 4096 characters from the
55
     * passed resource handle.
56
     *
57
     * If the line is larger than 4096 characters, the remaining characters in
58
     * the line are read and discarded, and only the first 4096 characters are
59
     * returned.
60
     *
61
     * @param resource $handle
62
     * @return string|bool the read line or false on EOF or on error.
63
     */
64
    public static function readLine($handle)
65
    {
66
        $size = 4096;
67
        $ret = $line = fgets($handle, $size);
68
        while (strlen($line) === $size - 1 && substr($line, -1) !== "\n") {
69
            $line = fgets($handle, $size);
70
        }
71
        return $ret;
72
    }
73
    
74
    /**
75
     * Parses the passed stream into a {@see ZBateson\MailMimeParser\IMessage}
76
     * object and returns it.
77
     * 
78
     * @param StreamInterface $stream the stream to parse the message from
79
     * @return \ZBateson\MailMimeParser\IMessage
80
     */
81
    public function parse(StreamInterface $stream)
82
    {
83
        $headerContainer = $this->partHeaderContainerFactory->newInstance();
84
        $partBuilder = $this->partBuilderFactory->newPartBuilder($headerContainer, $stream);
85
        $this->headerParser->parse(
86
            $partBuilder->getMessageResourceHandle(),
0 ignored issues
show
Bug introduced by
It seems like $partBuilder->getMessageResourceHandle() can also be of type mixed; however, parameter $handle of ZBateson\MailMimeParser\...r\HeaderParser::parse() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

86
            /** @scrutinizer ignore-type */ $partBuilder->getMessageResourceHandle(),
Loading history...
87
            $headerContainer
88
        );
89
        $proxy = $this->parserManager->createParserProxyFor($partBuilder);
90
        return $proxy->getPart();
0 ignored issues
show
Bug introduced by
The method getPart() does not exist on ZBateson\MailMimeParser\Parser\IParser. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

90
        return $proxy->/** @scrutinizer ignore-call */ getPart();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
91
    }
92
}
93