InvalidAttributeException::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.584
c 0
b 0
f 0
cc 3
nc 3
nop 4
ccs 10
cts 10
cp 1
crap 3
1
<?php
2
3
namespace Deserializers\Exceptions;
4
5
use Exception;
6
7
/**
8
 * A deserialization exception that is thrown when an expected array key is present, but it's value
9
 * is not in the expected format.
10
 *
11
 * @since 1.0
12
 *
13
 * @license GPL-2.0-or-later
14
 * @author Jeroen De Dauw < [email protected] >
15
 * @author Thiemo Kreuz
16
 */
17
class InvalidAttributeException extends DeserializationException {
18
19
	private $attributeName;
20
	private $attributeValue;
21
22
	/**
23
	 * @param string $attributeName
24
	 * @param mixed $attributeValue
25
	 * @param string $message
26
	 * @param Exception|null $previous
27
	 */
28 2
	public function __construct(
29
		$attributeName,
30
		$attributeValue,
31
		$message = '',
32
		Exception $previous = null
33
	) {
34 2
		$this->attributeName = $attributeName;
35 2
		$this->attributeValue = $attributeValue;
36
37 2
		if ( $message === '' ) {
38 1
			$message = 'Attribute "' . $attributeName . '"';
39
40 1
			if ( is_scalar( $attributeValue ) ) {
41 1
				$message .= ' with value "' . $attributeValue . '"';
42
			}
43
44 1
			$message .= ' is invalid';
45
		}
46
47 2
		parent::__construct( $message, $previous );
48 2
	}
49
50
	/**
51
	 * @return string
52
	 */
53 2
	public function getAttributeName() {
54 2
		return $this->attributeName;
55
	}
56
57
	/**
58
	 * @return string
59
	 */
60 2
	public function getAttributeValue() {
61 2
		return $this->attributeValue;
62
	}
63
64
}
65