Passed
Push — master ( db6a53...320901 )
by Dawid
03:03
created

ValidationViolation::__toString()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 2
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiechu\SymfonyCommonsBundle\Service\SchemaValidator;
6
7
class ValidationViolation
8
{
9
    /**
10
     * @var string
11
     */
12
    protected $message;
13
14
    /**
15
     * @var null|string
16
     */
17
    protected $property;
18
19
    /**
20
     * @param string      $message
21
     * @param null|string $property
22
     */
23 3
    protected function __construct(string $message, ?string $property = null)
24
    {
25 3
        $this->message = $message;
26 3
        $this->property = $property;
27 3
    }
28
29
    /**
30
     * @return string
31
     */
32 1
    public function __toString(): string
33
    {
34 1
        return sprintf('%s %s', $this->property ? ($this->property.': ') : '', $this->message);
35
    }
36
37
    /**
38
     * @param string      $message
39
     * @param null|string $property
40
     *
41
     * @return ValidationViolation
42
     */
43 3
    public static function create(string $message, ?string $property = null): self
44
    {
45 3
        return new static($message, $property);
46
    }
47
48
    /**
49
     * @return string
50
     */
51
    public function getMessage(): string
52
    {
53
        return $this->message;
54
    }
55
56
    /**
57
     * @return null|string
58
     */
59
    public function getProperty(): ?string
60
    {
61
        return $this->property;
62
    }
63
}
64