33
2
mirror of https://github.com/joomla-extensions/jedchecker.git synced 2025-01-30 16:58:28 +00:00

optionally store code line in the report

This commit is contained in:
Denis Ryabov 2021-02-23 22:38:42 +03:00
parent 6dbc83f782
commit 694741bdf5

View File

@ -84,15 +84,17 @@ class JEDcheckerReport extends JObject
* @param string $text - An optional description of the error. * @param string $text - An optional description of the error.
* @param integer $line - If $location is a file, you may specify the line where the * @param integer $line - If $location is a file, you may specify the line where the
* error occurred. * error occurred.
* @param string $code - Code at that location (to be displayed below the description)
* *
* @return void * @return void
*/ */
public function addError($location, $text = null, $line = 0) public function addError($location, $text = null, $line = 0, $code = null)
{ {
$item = new stdClass; $item = new stdClass;
$item->location = $location; $item->location = $location;
$item->line = $line; $item->line = $line;
$item->text = $text; $item->text = $text;
$item->code = $code;
$this->addItem($item, 'errors'); $this->addItem($item, 'errors');
} }
@ -104,15 +106,17 @@ class JEDcheckerReport extends JObject
* @param string $text - An optional description of the error. * @param string $text - An optional description of the error.
* @param integer $line - If $location is a file, you may specify the line where the * @param integer $line - If $location is a file, you may specify the line where the
* error occurred. * error occurred.
* @param string $code - Code at that location (to be displayed below the description)
* *
* @return void * @return void
*/ */
public function addInfo($location, $text = null, $line = 0) public function addInfo($location, $text = null, $line = 0, $code = null)
{ {
$item = new stdClass; $item = new stdClass;
$item->location = $location; $item->location = $location;
$item->line = $line; $item->line = $line;
$item->text = $text; $item->text = $text;
$item->code = $code;
$this->addItem($item, 'info'); $this->addItem($item, 'info');
} }
@ -124,15 +128,17 @@ class JEDcheckerReport extends JObject
* @param string $text - An optional description of the issue * @param string $text - An optional description of the issue
* @param integer $line - If $location is a file, you may specify the line where the * @param integer $line - If $location is a file, you may specify the line where the
* issue occurred. * issue occurred.
* @param string $code - Code at that location (to be displayed below the description)
* *
* @return void * @return void
*/ */
public function addCompat($location, $text = null, $line = 0) public function addCompat($location, $text = null, $line = 0, $code = null)
{ {
$item = new stdClass; $item = new stdClass;
$item->location = $location; $item->location = $location;
$item->line = $line; $item->line = $line;
$item->text = $text; $item->text = $text;
$item->code = $code;
$this->addItem($item, 'compat'); $this->addItem($item, 'compat');
} }
@ -144,15 +150,17 @@ class JEDcheckerReport extends JObject
* @param string $text - An optional description of the issue * @param string $text - An optional description of the issue
* @param integer $line - If $location is a file, you may specify the line where the * @param integer $line - If $location is a file, you may specify the line where the
* issue occurred. * issue occurred.
* @param string $code - Code at that location (to be displayed below the description)
* *
* @return void * @return void
*/ */
public function addWarning($location, $text = null, $line = 0) public function addWarning($location, $text = null, $line = 0, $code = null)
{ {
$item = new stdClass; $item = new stdClass;
$item->location = $location; $item->location = $location;
$item->line = $line; $item->line = $line;
$item->text = $text; $item->text = $text;
$item->code = $code;
$this->addItem($item, 'warning'); $this->addItem($item, 'warning');
} }
@ -297,7 +305,15 @@ class JEDcheckerReport extends JObject
// Add text if given // Add text if given
if (!empty($item->text)) if (!empty($item->text))
{ {
$html[] = '<small>' . $item->text . '</small>'; $html[] = '<small>' . $item->text;
// Add code if given
if (!empty($item->code))
{
$html[] = '<pre>' . htmlspecialchars(rtrim($item->code)) . '</pre>';
}
$html[] = '</small>';
} }
$html[] = '</li>'; $html[] = '</li>';