Passed
Push — master ( 0ce3b5...f76703 )
by Dawid
03:41
created

ValidationViolation::getProperty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiechu\SymfonyCommonsBundle\Service;
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 1
    protected function __construct(string $message, ?string $property = null)
20
    {
21 1
        $this->message = $message;
22 1
        $this->property = $property;
23 1
    }
24
25
    public function __toString(): string
26
    {
27
        return sprintf('%s %s', $this->property ? ($this->property.': ') : '', $this->message);
28
    }
29
30 1
    public static function create(string $message, ?string $property = null): self
31
    {
32 1
        return new static($message, $property);
33
    }
34
35
    public function getMessage(): string
36
    {
37
        return $this->message;
38
    }
39
40
    public function getProperty(): ?string
41
    {
42
        return $this->property;
43
    }
44
}
45