Test Failed
Pull Request — main (#19)
by Anatoly
11:30
created

InvalidValueException::getPropertyPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
ccs 0
cts 0
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php declare(strict_types=1);
2
3
/**
4
 * It's free open-source software released under the MIT License.
5
 *
6
 * @author Anatoly Fenric <[email protected]>
7
 * @copyright Copyright (c) 2021, Anatoly Fenric
8
 * @license https://github.com/sunrise-php/hydrator/blob/master/LICENSE
9
 * @link https://github.com/sunrise-php/hydrator
10
 */
11
12
namespace Sunrise\Hydrator\Exception;
13
14
/**
15
 * Import classes
16
 */
17
use ReflectionProperty;
18
use Throwable;
19
20
/**
21
 * Import functions
22
 */
23
use function sprintf;
24
25
/**
26
 * InvalidValueException
27
 */
28
class InvalidValueException extends HydrationException
29
{
30
31
    /**
32
     * The problem property
33
     *
34
     * @var ReflectionProperty
35
     */
36
    private $property;
37
38
    /**
39
     * Constructor of the class
40
     *
41 14
     * @param ReflectionProperty $property
42
     * @param string             $message
43
     * @param int                $code
44
     * @param Throwable|null     $previous
45
     */
46
    public function __construct(
47 14
        ReflectionProperty $property,
48
        string $message,
49 14
        int $code = 0,
50
        ?Throwable $previous = null
51 14
    ) {
52
        parent::__construct($message, $code, $previous);
53
54
        $property->setAccessible(false);
55
        $this->property = $property;
56
    }
57
58
    /**
59 1
     * Gets the problem property
60
     *
61 1
     * @return ReflectionProperty
62
     */
63
    final public function getProperty() : ReflectionProperty
64
    {
65
        return $this->property;
66
    }
67
68
    /**
69
     * Gets the problem property path
70
     *
71
     * @return string
72
     */
73
    final public function getPropertyPath() : string
74
    {
75
        return sprintf('%s.%s', $this->property->getDeclaringClass()->getShortName(), $this->property->getName());
76
    }
77
}
78