mediawiki-extensions-Linter/includes/LintError.php
C. Scott Ananian 551a1fb398 Allow Parsoid to provide category ID hints
This eases deployment dependencies by allowing Parsoid to supply an
appropriate database category ID so that new lint categories can be
appropriately stored during the interval between adding a new lint
category to Parsoid and deploying an Extension:Linter patch to
describe it.

Change-Id: Ib7b2342168fa53ca2abac7d5f54fe313be341eb7
2019-12-03 23:26:34 -05:00

107 lines
2.4 KiB
PHP

<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
*/
namespace MediaWiki\Linter;
use FormatJson;
/**
* Model to represent a LintError
*/
class LintError {
/**
* @var string
*/
public $category;
/**
* @var int[] [ start, end ]
*/
public $location;
/**
* @var int
*/
public $lintId;
/**
* @var array
*/
public $params;
/**
* @var string[]|null
*/
public $templateInfo;
/*
* Optional hint for the linter category ID.
* Passed through from Parsoid when a new category has been added
* that isn't known to PHP yet.
* @var int|null
*/
public $catId;
/**
* @param string $category
* @param int[] $location [ start, end ]
* @param string|array $params JSON string or already decoded array
* @param int|null $catId Optional category ID hint
* @param int $lintId Optional linter_id
*/
public function __construct( $category, $location, $params, $catId = null, $lintId = 0 ) {
$this->category = $category;
$this->catId = $catId;
if ( is_string( $params ) ) {
$params = FormatJson::decode( $params, true );
}
$this->params = $params;
$this->lintId = $lintId;
$this->location = $location;
// Convenient accessors for all errors
$this->templateInfo = $params['templateInfo'] ?? null;
}
/**
* Unique id to identify this error, for internal
* purposes
*
* @return string
*/
public function id() {
return $this->category . ",{$this->location[0]},{$this->location[1]},"
. FormatJson::encode( $this->params );
}
/**
* Get the params that are extra for this error,
* not part of the default set
*
* @return array
*/
public function getExtraParams() {
$params = $this->params;
unset( $params['templateInfo'] );
return $params;
}
}