Passed
Push — master ( 72441b...83a6b5 )
by adam
01:56
created

Error::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
cc 1
nc 1
nop 5
ccs 7
cts 7
cp 1
crap 1
rs 10
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace ValueValidators;
6
7
/**
8
 * @license GPL-2.0+
9
 * @author Jeroen De Dauw < [email protected] >
10
 */
11
class Error {
12
13
	public const SEVERITY_ERROR = 9;
14
	public const SEVERITY_WARNING = 4;
15
16
	private $text;
17
	private $severity;
18
	private $property;
19
20
	private $code;
21
	private $params;
22
23 8
	public static function newError( string $text = '', string $property = null, string $code = 'invalid', array $params = [] ): self {
24 8
		return new self( $text, self::SEVERITY_ERROR, $property, $code, $params );
25
	}
26
27 8
	protected function __construct( string $text, int $severity, ?string $property, string $code, array $params ) {
28 8
		$this->text = $text;
29 8
		$this->severity = $severity;
30 8
		$this->property = $property;
31 8
		$this->code = $code;
32 8
		$this->params = $params;
33 8
	}
34
35 7
	public function getText(): string {
36 7
		return $this->text;
37
	}
38
39
	/**
40
	 * @return integer, element of the ValueValidatorError::SEVERITY_ enum
0 ignored issues
show
Documentation introduced by
The doc-type integer, could not be parsed: Expected "|" or "end of type", but got "," at position 7. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
41
	 */
42
	public function getSeverity(): int {
43
		return $this->severity;
44
	}
45
46
	/**
47
	 * Returns the property of the value for which the error occurred, or null if it occurred for the value itself.
48
	 */
49 8
	public function getProperty(): ?string {
50 8
		return $this->property;
51
	}
52
53 1
	public function getParameters(): array {
54 1
		return $this->params;
55
	}
56
57 2
	public function getCode(): string {
58 2
		return $this->code;
59
	}
60
61
}
62