3 namespace Drupal\security_review;
6 * Used to define the result of a Check.
16 * Stores the parent Check.
18 * @var \Drupal\security_review\Check $check
23 * Stores the outcome of the check.
32 * @var array $findings
37 * Stores the timestamp of the check run.
44 * Whether the result should be shown on the UI.
51 * Constructs an immutable CheckResult.
53 * @param \Drupal\security_review\Check $check
54 * The Check that created this result.
56 * The result integer (see the constants defined above).
57 * @param array $findings
60 * The timestamp of the check run.
61 * @param bool $visible
62 * The visibility of the result.
64 public function __construct(Check $check, $result, array $findings, $visible = TRUE, $time = NULL) {
65 // Set the parent check.
66 $this->check = $check;
68 // Set the result value.
69 $result = intval($result);
70 if ($result < self::SUCCESS || $result > self::INFO) {
73 $this->result = $result;
76 $this->findings = $findings;
78 // Set the visibility.
79 $this->visible = $visible;
86 $this->time = intval($time);
91 * Combines two CheckResults.
93 * Combines two CheckResults and returns a new one with the old one's fields
94 * except for the findings which are copied from the fresh result.
96 * @param \Drupal\security_review\CheckResult $old
97 * The old result to clone.
98 * @param \Drupal\security_review\CheckResult $fresh
99 * The new result to copy the findings from.
101 * @return \Drupal\security_review\CheckResult
102 * The combined result.
104 public static function combine(CheckResult $old, CheckResult $fresh) {
105 return new CheckResult($old->check, $old->result, $fresh->findings, $old->visible, $old->time);
109 * Returns the parent Check.
111 * @return \Drupal\security_review\Check
112 * The Check that created this result.
114 public function check() {
119 * Returns the outcome of the check.
122 * The result integer.
124 public function result() {
125 return $this->result;
129 * Returns the findings.
132 * The findings. Contents of this depends on the actual check.
134 public function findings() {
135 return $this->findings;
139 * Returns the timestamp.
142 * The timestamp the result was created on.
144 public function time() {
149 * Returns the visibility of the result.
152 * Whether the result should be shown on the UI.
154 public function isVisible() {
155 return $this->visible;
159 * Returns the result message.
162 * The result message for this result.
164 public function resultMessage() {
165 return $this->check->getMessage($this->result);