Completed
Push — master ( 6aef24...286712 )
by Márk
06:17
created

UnexpectedTagException   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 31
ccs 0
cts 19
cp 0
rs 10

1 Method

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