mirror of
https://github.com/joomla-extensions/jedchecker.git
synced 2025-01-12 09:51:07 +00:00
phpcs
This commit is contained in:
parent
12169b03eb
commit
dac3bf2429
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* @author eaxs
|
* @author eaxs <support@projectfork.net>
|
||||||
|
* @author Daniel Dimitrov <daniel@compojoom.com>
|
||||||
* @date 07/06/2012
|
* @date 07/06/2012
|
||||||
* @copyright Copyright (C) 2008 - 2012 compojoom.com . All rights reserved.
|
* @copyright Copyright (C) 2008 - 2012 compojoom.com . All rights reserved.
|
||||||
* @license GNU General Public License version 2 or later; see LICENSE
|
* @license GNU General Public License version 2 or later; see LICENSE
|
||||||
@ -8,11 +9,13 @@
|
|||||||
|
|
||||||
defined('_JEXEC') or die('Restricted access');
|
defined('_JEXEC') or die('Restricted access');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Class JEDcheckerReport
|
||||||
|
*
|
||||||
* This class is meant to be used by JED rules to
|
* This class is meant to be used by JED rules to
|
||||||
* create a report.
|
* create a report.
|
||||||
*
|
*
|
||||||
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
class JEDcheckerReport extends JObject
|
class JEDcheckerReport extends JObject
|
||||||
{
|
{
|
||||||
@ -31,13 +34,11 @@ class JEDcheckerReport extends JObject
|
|||||||
*/
|
*/
|
||||||
protected $basedir;
|
protected $basedir;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor. Initialises variables.
|
* Constructor. Initialises variables.
|
||||||
*
|
*
|
||||||
* @param mixed $properties See JObject::__construct
|
* @param mixed $properties Either and associative array or another
|
||||||
*
|
* object to set the initial properties of the object.
|
||||||
* @return \JEDcheckerReport
|
|
||||||
*/
|
*/
|
||||||
public function __construct($properties = null)
|
public function __construct($properties = null)
|
||||||
{
|
{
|
||||||
@ -45,9 +46,11 @@ class JEDcheckerReport extends JObject
|
|||||||
parent::__construct($properties);
|
parent::__construct($properties);
|
||||||
|
|
||||||
// Initialise vars
|
// Initialise vars
|
||||||
if(empty($this->data)) $this->reset();
|
if (empty($this->data))
|
||||||
|
{
|
||||||
|
$this->reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets the report data.
|
* Resets the report data.
|
||||||
@ -62,27 +65,26 @@ class JEDcheckerReport extends JObject
|
|||||||
$this->data['compat'] = array();
|
$this->data['compat'] = array();
|
||||||
$this->data['info'] = array();
|
$this->data['info'] = array();
|
||||||
|
|
||||||
$this->data['count'] = new stdClass();
|
$this->data['count'] = new stdClass;
|
||||||
$this->data['count']->total = 0;
|
$this->data['count']->total = 0;
|
||||||
$this->data['count']->errors = 0;
|
$this->data['count']->errors = 0;
|
||||||
$this->data['count']->compat = 0;
|
$this->data['count']->compat = 0;
|
||||||
$this->data['count']->info = 0;
|
$this->data['count']->info = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an error to the report.
|
* Adds an error to the report.
|
||||||
*
|
*
|
||||||
* @param string $location The location of the error. Can be a path to a file or dir.
|
* @param string $location - The location of the error. Can be a path to a file or dir.
|
||||||
* @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.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function addError($location, $text = NULL, $line = 0)
|
public function addError($location, $text = null, $line = 0)
|
||||||
{
|
{
|
||||||
$item = new stdClass();
|
$item = new stdClass;
|
||||||
$item->location = $location;
|
$item->location = $location;
|
||||||
$item->line = $line;
|
$item->line = $line;
|
||||||
$item->text = $text;
|
$item->text = $text;
|
||||||
@ -93,16 +95,16 @@ class JEDcheckerReport extends JObject
|
|||||||
/**
|
/**
|
||||||
* Adds an error to the report.
|
* Adds an error to the report.
|
||||||
*
|
*
|
||||||
* @param string $location The location of the error. Can be a path to a file or dir.
|
* @param string $location - The location of the error. Can be a path to a file or dir.
|
||||||
* @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.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function addInfo($location, $text = NULL, $line = 0)
|
public function addInfo($location, $text = null, $line = 0)
|
||||||
{
|
{
|
||||||
$item = new stdClass();
|
$item = new stdClass;
|
||||||
$item->location = $location;
|
$item->location = $location;
|
||||||
$item->line = $line;
|
$item->line = $line;
|
||||||
$item->text = $text;
|
$item->text = $text;
|
||||||
@ -110,20 +112,19 @@ class JEDcheckerReport extends JObject
|
|||||||
$this->addItem($item, 'info');
|
$this->addItem($item, 'info');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a compatibility issue to the report.
|
* Adds a compatibility issue to the report.
|
||||||
*
|
*
|
||||||
* @param string $location The location of the issue. Can be a path to a file or dir.
|
* @param string $location - The location of the issue. Can be a path to a file or dir.
|
||||||
* @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.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function addCompat($location, $text = NULL, $line = 0)
|
public function addCompat($location, $text = null, $line = 0)
|
||||||
{
|
{
|
||||||
$item = new stdClass();
|
$item = new stdClass;
|
||||||
$item->location = $location;
|
$item->location = $location;
|
||||||
$item->line = $line;
|
$item->line = $line;
|
||||||
$item->text = $text;
|
$item->text = $text;
|
||||||
@ -131,7 +132,6 @@ class JEDcheckerReport extends JObject
|
|||||||
$this->addItem($item, 'compat');
|
$this->addItem($item, 'compat');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats the existing report data into HTML and returns it.
|
* Formats the existing report data into HTML and returns it.
|
||||||
*
|
*
|
||||||
@ -141,38 +141,43 @@ class JEDcheckerReport extends JObject
|
|||||||
{
|
{
|
||||||
$html = array();
|
$html = array();
|
||||||
|
|
||||||
if($this->data['count']->total == 0) {
|
if ($this->data['count']->total == 0)
|
||||||
|
{
|
||||||
// No errors or compatibility issues found
|
// No errors or compatibility issues found
|
||||||
$html[] = '<span class="success">';
|
$html[] = '<span class="success">';
|
||||||
$html[] = JText::_('COM_JEDCHECKER_EVERYTHING_SEEMS_TO_BE_FINE_WITH_THAT_RULE');
|
$html[] = JText::_('COM_JEDCHECKER_EVERYTHING_SEEMS_TO_BE_FINE_WITH_THAT_RULE');
|
||||||
$html[] = '</span>';
|
$html[] = '</span>';
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
$error_count = $this->data['count']->errors;
|
$error_count = $this->data['count']->errors;
|
||||||
$compat_count = $this->data['count']->compat;
|
$compat_count = $this->data['count']->compat;
|
||||||
$info_count = $this->data['count']->info;
|
$info_count = $this->data['count']->info;
|
||||||
|
|
||||||
// Go through the error list
|
// Go through the error list
|
||||||
if($error_count > 0) {
|
if ($error_count > 0)
|
||||||
$html[] = '<strong>'.$error_count. ' '.JText::_('COM_JEDCHECKER_ERRORS').'</strong>';
|
{
|
||||||
|
$html[] = '<strong>' . $error_count . ' ' . JText::_('COM_JEDCHECKER_ERRORS') . '</strong>';
|
||||||
$html[] = '<ul class="jedchecker-rule-errors">';
|
$html[] = '<ul class="jedchecker-rule-errors">';
|
||||||
|
|
||||||
foreach($this->data['errors'] AS $i => $item)
|
foreach ($this->data['errors'] AS $i => $item)
|
||||||
{
|
{
|
||||||
$num = $i + 1;
|
$num = $i + 1;
|
||||||
|
|
||||||
// Add the error count number
|
// Add the error count number
|
||||||
$html[] = '<li><strong>#'.str_pad($num, 3, '0', STR_PAD_LEFT).':</strong> ';
|
$html[] = '<li><strong>#' . str_pad($num, 3, '0', STR_PAD_LEFT) . ':</strong> ';
|
||||||
$html[] = $item->location;
|
$html[] = $item->location;
|
||||||
|
|
||||||
// Add line information if given
|
// Add line information if given
|
||||||
if($item->line > 0) {
|
if ($item->line > 0)
|
||||||
$html[] = ' '.JText::_('COM_JEDCHECKER_IN_LINE').': <strong>'.$item->line.'</strong>';
|
{
|
||||||
|
$html[] = ' ' . JText::_('COM_JEDCHECKER_IN_LINE') . ': <strong>' . $item->line . '</strong>';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add text if given
|
// Add text if given
|
||||||
if(!empty($item->text)) {
|
if (!empty($item->text))
|
||||||
$html[] = '<br /><small>'.$item->text.'</small>';
|
{
|
||||||
|
$html[] = '<br /><small>' . $item->text . '</small>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$html[] = '</li>';
|
$html[] = '</li>';
|
||||||
@ -182,28 +187,31 @@ class JEDcheckerReport extends JObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Go through the compat list
|
// Go through the compat list
|
||||||
if($compat_count > 0) {
|
if ($compat_count > 0)
|
||||||
$html[] = '<strong>'.$error_count. ' '.JText::_('COM_JEDCHECKER_COMPAT_ISSUES').'</strong>';
|
{
|
||||||
|
$html[] = '<strong>' . $error_count . ' ' . JText::_('COM_JEDCHECKER_COMPAT_ISSUES') . '</strong>';
|
||||||
$html[] = '<ul class="jedchecker-rule-compat">';
|
$html[] = '<ul class="jedchecker-rule-compat">';
|
||||||
|
|
||||||
foreach($this->data['compat'] AS $i => $item)
|
foreach ($this->data['compat'] AS $i => $item)
|
||||||
{
|
{
|
||||||
$num = $i + 1;
|
$num = $i + 1;
|
||||||
|
|
||||||
// Add the error count number
|
// Add the error count number
|
||||||
$html[] = '<li><p><strong>#'.str_pad($num, 3, '0', STR_PAD_LEFT).'</strong> ';
|
$html[] = '<li><p><strong>#' . str_pad($num, 3, '0', STR_PAD_LEFT) . '</strong> ';
|
||||||
$html[] = $item->location;
|
$html[] = $item->location;
|
||||||
|
|
||||||
// Add line information if given
|
// Add line information if given
|
||||||
if($item->line > 0) {
|
if ($item->line > 0)
|
||||||
$html[] = ' '.JText::_('COM_JEDCHECKER_IN_LINE').': <strong>'.$item->line.'</strong>';
|
{
|
||||||
|
$html[] = ' ' . JText::_('COM_JEDCHECKER_IN_LINE') . ': <strong>' . $item->line . '</strong>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$html[] = '</p>';
|
$html[] = '</p>';
|
||||||
|
|
||||||
// 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 . '</small>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$html[] = '</li>';
|
$html[] = '</li>';
|
||||||
@ -213,29 +221,31 @@ class JEDcheckerReport extends JObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Go through the compat list
|
// Go through the compat list
|
||||||
if($info_count > 0) {
|
if ($info_count > 0)
|
||||||
$html[] = '<strong>'.$info_count. ' '.JText::_('COM_JEDCHECKER_INFO').'</strong>';
|
{
|
||||||
|
$html[] = '<strong>' . $info_count . ' ' . JText::_('COM_JEDCHECKER_INFO') . '</strong>';
|
||||||
$html[] = '<ul class="jedchecker-info-message">';
|
$html[] = '<ul class="jedchecker-info-message">';
|
||||||
|
|
||||||
foreach($this->data['info'] AS $i => $item)
|
foreach ($this->data['info'] AS $i => $item)
|
||||||
{
|
{
|
||||||
$num = $i + 1;
|
$num = $i + 1;
|
||||||
|
|
||||||
// Add the error count number
|
// Add the error count number
|
||||||
$html[] = '<li><p><strong>#'.str_pad($num, 3, '0', STR_PAD_LEFT).'</strong> ';
|
$html[] = '<li><p><strong>#' . str_pad($num, 3, '0', STR_PAD_LEFT) . '</strong> ';
|
||||||
$html[] = $item->location;
|
$html[] = $item->location;
|
||||||
|
|
||||||
|
|
||||||
// Add line information if given
|
// Add line information if given
|
||||||
if($item->line > 0) {
|
if ($item->line > 0)
|
||||||
$html[] = ' '.JText::_('COM_JEDCHECKER_IN_LINE').': <strong>'.$item->line.'</strong>';
|
{
|
||||||
|
$html[] = ' ' . JText::_('COM_JEDCHECKER_IN_LINE') . ': <strong>' . $item->line . '</strong>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$html[] = '</p>';
|
$html[] = '</p>';
|
||||||
|
|
||||||
// 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 . '</small>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$html[] = '</li>';
|
$html[] = '</li>';
|
||||||
@ -245,16 +255,14 @@ class JEDcheckerReport extends JObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return implode('', $html);
|
return implode('', $html);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an item to the report data
|
* Adds an item to the report data
|
||||||
*
|
*
|
||||||
* @param object $item The item to add.
|
* @param object $item - The item to add.
|
||||||
* @param string $type Optional item type. Can be 'errors' or 'compat'.
|
* @param string $type - Optional item type. Can be 'errors' or 'compat'.
|
||||||
* Defaults to 'errors'.
|
* Defaults to 'errors'.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
@ -262,10 +270,14 @@ class JEDcheckerReport extends JObject
|
|||||||
protected function addItem($item, $type = 'errors')
|
protected function addItem($item, $type = 'errors')
|
||||||
{
|
{
|
||||||
// Remove the base dir from the location
|
// Remove the base dir from the location
|
||||||
if(!empty($this->basedir)) {
|
if (!empty($this->basedir))
|
||||||
|
{
|
||||||
$item->location = str_replace($this->basedir, '', $item->location);
|
$item->location = str_replace($this->basedir, '', $item->location);
|
||||||
|
|
||||||
if($item->location == '') $item->location = '/';
|
if ($item->location == '')
|
||||||
|
{
|
||||||
|
$item->location = '/';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the item to the report data
|
// Add the item to the report data
|
||||||
|
Loading…
Reference in New Issue
Block a user