Passed
Push — master ( f8574f...0e1b55 )
by Julien
08:17 queued 05:08
created

ValidationError   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
eloc 15
c 1
b 0
f 1
dl 0
loc 48
ccs 14
cts 14
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getMessage() 0 3 1
A emptyXml() 0 3 1
A fromLibXmlError() 0 6 2
1
<?php declare(strict_types=1);
2
3
4
namespace Pitchart\Phlunit\Validator;
5
6
/**
7
 * Class ValidationError
8
 *
9
 * @package Pitchart\Phlunit\Validator
10
 *
11
 * @author Julien VITTE <[email protected]>
12
 *
13
 * @internal
14
 */
15
class ValidationError
16
{
17
    const ERROR = 'ERROR';
18
19
    const WARNING = 'WARNING';
20
21
    /**
22
     * @var string
23
     */
24
    private $level;
25
26
    /**
27
     * @var int
28
     */
29
    private $code;
30
31
    /**
32
     * @var string
33
     */
34
    private $message;
35
36 7
    private function __construct($level, $code, $message)
37
    {
38 7
        $this->level = $level;
39 7
        $this->code = $code;
40 7
        $this->message = $message;
41 7
    }
42
43 2
    public static function emptyXml()
44
    {
45 2
        return new self(self::ERROR, "", "Provided content is not valid XML.");
46
    }
47
48 5
    public static function fromLibXmlError(\LibXMLError $error)
49
    {
50 5
        return new ValidationError(
51 5
            \LIBXML_ERR_WARNING == $error->level ? self::WARNING : self::ERROR,
52 5
            $error->code,
53 5
            \trim($error->message)
54
        );
55
    }
56
57
    /**
58
     * @return mixed
59
     */
60 4
    public function getMessage()
61
    {
62 4
        return $this->message;
63
    }
64
}
65