You are here

public function W3CProcessor::saveResult in W3C Validator 8

Save a validation result in the database.

Parameters

\HtmlValidator\Response $result: The validation result to store in DB.

string $key: The unique key used for storage in DB. This is basically the page relative URL. pages to validate.

1 call to W3CProcessor::saveResult()
W3CProcessor::validatePage in src/W3CProcessor.php
This method is responsible for the validation of a single page.

File

src/W3CProcessor.php, line 257

Class

W3CProcessor
Processor for page validation.

Namespace

Drupal\w3c_validator

Code

public function saveResult(Response $result, $key) {

  // Only if result is defined.
  if (isset($result) && isset($key)) {

    // Merge the result with eventual previous result for the same URI.
    $this->connection
      ->merge("w3c_validator")
      ->key('uri', rtrim($key, "/"))
      ->fields([
      'uri' => rtrim($key, "/"),
      'error_count' => count($result
        ->getErrors()),
      'errors' => serialize($result
        ->getErrors()),
      'warning_count' => count($result
        ->getWarnings()),
      'warnings' => serialize($result
        ->getWarnings()),
      'info_count' => count($result
        ->getMessages()),
      'infos' => serialize($result
        ->getMessages()),
      'need_validation' => 0,
      // @todo make it better
      'doctype' => '',
      'validity' => $result
        ->hasErrors() ? 0 : 1,
      // @todo make it better
      'charset' => '',
    ])
      ->execute();
  }
  else {

    // Merge the result with eventual previous result for the same URI.
    $this->connection
      ->merge("w3c_validator")
      ->key('uri', rtrim($key, "/"))
      ->fields([
      'need_validation' => TRUE,
    ])
      ->execute();
  }
}