Completed
Push — master ( 034d53...fa2497 )
by Márk
26:41 queued 16:42
created

BestParserDelegate::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Fxmlrpc\Serialization\Parser;
4
5
use Fxmlrpc\Serialization\Parser;
6
7
/**
8
 * Parser that selects the best available parser.
9
 *
10
 * @author Lars Strojny <[email protected]>
11
 */
12
final class BestParserDelegate implements Parser
13
{
14
    /**
15
     * @var NativeParser
16
     */
17
    private $nativeParser;
18
19
    /**
20
     * @var XmlReaderParser
21
     */
22
    private $xmlReaderParser;
23
24
    /**
25
     * @param bool $validateResponse
26
     */
27
    public function __construct($validateResponse = true)
28
    {
29
        $this->nativeParser = new NativeParser($validateResponse);
30
        $this->xmlReaderParser = new XmlReaderParser($validateResponse);
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function parse($xmlString)
37
    {
38
        return !NativeParser::isBiggerThanParseLimit($xmlString)
39
            ? $this->nativeParser->parse($xmlString)
40
            : $this->xmlReaderParser->parse($xmlString);
41
    }
42
}
43