예제 #1
0
 /**
  * Casts JsonLint ParseException to ours.
  *
  * @param JsonParseException $exception
  *
  * @return ParseException
  */
 public static function castFromJson(JsonParseException $exception)
 {
     $details = $exception->getDetails();
     $message = $exception->getMessage();
     $line = isset($details['line']) ? $details['line'] : -1;
     $snippet = null;
     if (preg_match("/^Parse error on line (?<line>\\d+):\n(?<snippet>.+)\n.+\n(?<message>.+)\$/", $message, $matches)) {
         $line = (int) $matches[1];
         $snippet = $matches[2];
         $message = $matches[3];
     }
     $trailingComma = false;
     $pos = strpos($message, ' - It appears you have an extra trailing comma');
     if ($pos > 0) {
         $message = substr($message, 0, $pos);
         $trailingComma = true;
     }
     if (strpos($message, 'Expected') === 0 && $trailingComma) {
         $message = 'It appears you have an extra trailing comma';
     }
     return new static($message, $line, $snippet);
 }
예제 #2
0
 /**
  * @param SplFileInfo      $file
  * @param ParsingException $exception
  *
  * @return JsonLintError
  */
 public static function fromParsingException(SplFileInfo $file, ParsingException $exception)
 {
     return new JsonLintError(LintError::TYPE_ERROR, $exception->getMessage(), $file->getPathname(), 0);
 }