Passed
Pull Request — master (#9)
by Julien
10:45
created

ValidationError::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 3
c 1
b 0
f 1
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
cc 1
nc 1
nop 3
crap 1
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