class-validation-result.php
1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/**
* @package WPSEO\Premium\Classes
*/
/**
* Abstract class for different possible validation results.
*/
abstract class WPSEO_Validation_Result {
/**
* @var string The validation message contained by the result.
*/
protected $message;
/**
* @var string The type of result (error|warning)
*/
protected $type;
/**
* @var array The field that has the error.
*/
private $fields = array();
/**
* Constructing the object
*
* @param string $message The validation message contained by the result.
* @param string|array $fields The fields that errored.
*/
public function __construct( $message, $fields = array() ) {
$this->message = $message;
$this->set_fields( $fields );
}
/**
* Gets the validation result message.
*
* @return string
*/
public function get_message() {
return $this->message;
}
/**
* Gets the validation result type.
*
* @return string
*/
public function get_type() {
return $this->type;
}
/**
* Returns an Array representation of the validation result.
*
* @return array
*/
public function to_array() {
return array(
'type' => $this->type,
'message' => $this->message,
'fields' => $this->fields,
);
}
/**
* Setting the fields with errors.
*
* @param string $fields The fields with errors on it.
*/
protected function set_fields( $fields = '' ) {
if ( ! is_array( $fields ) && is_string( $fields ) ) {
$fields = array( $fields );
}
$this->fields = $fields;
}
}