UnexpectedTagException::__construct()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 16
cts 16
cp 1
rs 9.0534
c 0
b 0
f 0
cc 4
eloc 13
nc 4
nop 5
crap 4
1
<?php
2
3
namespace Fxmlrpc\Serialization\Exception;
4
5
/**
6
 * @author Lars Strojny <[email protected]>
7
 */
8
final class UnexpectedTagException extends ParserException
9
{
10
    /**
11
     * @param string $tagName
12
     * @param mixed  $elements
13
     * @param array  $definedVariables
14
     * @param int    $depth
15
     * @param string $xml
16
     */
17 3
    public function __construct($tagName, $elements, array $definedVariables, $depth, $xml)
18
    {
19 3
        $expectedElements = [];
20 3
        foreach ($definedVariables as $variableName => $variable) {
21 3
            if (substr($variableName, 0, 4) !== 'flag') {
22 3
                continue;
23
            }
24
25 3
            if (($elements & $variable) === $variable) {
26 3
                $expectedElements[] = substr($variableName, 4);
27 3
            }
28 3
        }
29
30 3
        $this->message = sprintf(
31 3
            'Invalid XML. Expected one of "%s", got "%s" on depth %d (context: "%s")',
32 3
            implode('", "', $expectedElements),
33 3
            $tagName,
34 3
            $depth,
35
            $xml
36 3
        );
37 3
    }
38
}
39