Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
LintError
100.00% covered (success)
100.00%
14 / 14
100.00% covered (success)
100.00%
3 / 3
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
2
 id
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getExtraParams
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21namespace MediaWiki\Linter;
22
23use FormatJson;
24
25/**
26 * Model to represent a LintError
27 */
28class LintError {
29    /**
30     * @var string
31     */
32    public $category;
33
34    /**
35     * @var int[] [ start, end ]
36     */
37    public $location;
38
39    /**
40     * @var int
41     */
42    public $lintId;
43
44    /**
45     * @var array
46     */
47    public $params;
48
49    /**
50     * @var array|null
51     */
52    public $templateInfo;
53
54    /**
55     * @var string|null
56     */
57    public $tagInfo;
58
59    /**
60     * Optional hint for the linter category ID.
61     * Passed through from Parsoid when a new category has been added
62     * that isn't known to PHP yet.
63     * @var int|null
64     */
65    public $catId;
66
67    /**
68     * @param string $category
69     * @param int[] $location [ start, end ]
70     * @param string|array $params JSON string or already decoded array
71     * @param int|null $catId Optional category ID hint
72     * @param int $lintId Optional linter_id
73     */
74    public function __construct( $category, $location, $params, $catId = null, $lintId = 0 ) {
75        $this->category = $category;
76        $this->catId = $catId;
77
78        if ( is_string( $params ) ) {
79            $params = FormatJson::decode( $params, true );
80        }
81        $this->params = $params;
82        $this->lintId = $lintId;
83        $this->location = $location;
84        // Convenient accessors for all errors
85        $this->templateInfo = $params['templateInfo'] ?? null;
86        $this->tagInfo = $params['name'] ?? null;
87    }
88
89    /**
90     * Unique id to identify this error, for internal
91     * purposes
92     *
93     * @return string
94     */
95    public function id() {
96        return $this->category . ",{$this->location[0]},{$this->location[1]},"
97            . FormatJson::encode( $this->params );
98    }
99
100    /**
101     * Get the params that are extra for this error,
102     * not part of the default set
103     *
104     * @return array
105     */
106    public function getExtraParams() {
107        $params = $this->params;
108        unset( $params['templateInfo'] );
109
110        return $params;
111    }
112}