BestParserDelegate::parse()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 6
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