Skip to content

Commit

Permalink
Code review on com_cache component, doc blocks for Cache package
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Babker committed Oct 24, 2015
1 parent 00fd48e commit b720504
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 31 deletions.
8 changes: 6 additions & 2 deletions administrator/components/com_cache/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class CacheController extends JControllerLegacy
* @param boolean $cachable If true, the view output will be cached
* @param array $urlparams An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
*
* @return JController This object to support chaining.
* @return CacheController This object to support chaining.
*
* @since 1.5
*/
public function display($cachable = false, $urlparams = false)
public function display($cachable = false, $urlparams = array())
{
require_once JPATH_COMPONENT . '/helpers/cache.php';

Expand Down Expand Up @@ -62,6 +62,8 @@ public function display($cachable = false, $urlparams = false)

$view->display();
}

return $this;
}

/**
Expand All @@ -76,6 +78,7 @@ public function delete()

$cid = $this->input->post->get('cid', array(), 'array');

/** @var CacheModelCache $model */
$model = $this->getModel('cache');

if (empty($cid))
Expand All @@ -100,6 +103,7 @@ public function purge()
// Check for request forgeries
JSession::checkToken() or jexit(JText::_('JInvalid_Token'));

/** @var CacheModelCache $model */
$model = $this->getModel('cache');
$ret = $model->purge();

Expand Down
12 changes: 5 additions & 7 deletions administrator/components/com_cache/helpers/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@ class CacheHelper
/**
* Get a list of filter options for the application clients.
*
* @return array An array of JHtmlOption elements.
* @return stdClass[] An array of option elements.
*/
public static function getClientOptions()
{
// Build the filter options.
$options = array();
$options[] = JHtml::_('select.option', '0', JText::_('JSITE'));
$options[] = JHtml::_('select.option', '1', JText::_('JADMINISTRATOR'));

return $options;
return array(
JHtml::_('select.option', '0', JText::_('JSITE')),
JHtml::_('select.option', '1', JText::_('JADMINISTRATOR'))
);
}

/**
Expand Down
32 changes: 14 additions & 18 deletions administrator/components/com_cache/models/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

defined('_JEXEC') or die;

use Joomla\Utilities\ArrayHelper;

/**
* Cache Model
*
Expand All @@ -19,21 +21,21 @@ class CacheModelCache extends JModelList
/**
* An Array of CacheItems indexed by cache group ID
*
* @var Array
* @var array
*/
protected $_data = array();

/**
* Group total
*
* @var integer
* @var integer
*/
protected $_total = null;

/**
* Pagination object
*
* @var object
* @var JPagination
*/
protected $_pagination = null;

Expand Down Expand Up @@ -63,7 +65,7 @@ protected function populateState($ordering = null, $direction = null)
/**
* Method to get cache data
*
* @return array
* @return array
*/
public function getData()
{
Expand All @@ -83,8 +85,7 @@ public function getData()
$ordering = $this->getState('list.ordering');
$direction = ($this->getState('list.direction') == 'asc') ? 1 : (-1);

jimport('joomla.utilities.arrayhelper');
$this->_data = JArrayHelper::sortObjects($data, $ordering, $direction);
$this->_data = ArrayHelper::sortObjects($data, $ordering, $direction);

// Apply custom pagination.
if ($this->_total > $this->getState('list.limit') && $this->getState('list.limit'))
Expand All @@ -105,7 +106,7 @@ public function getData()
/**
* Method to get cache instance.
*
* @return object
* @return JCacheController
*/
public function getCache()
{
Expand All @@ -118,15 +119,13 @@ public function getCache()
'cachebase' => ($this->getState('clientId') == 1) ? JPATH_ADMINISTRATOR . '/cache' : $conf->get('cache_path', JPATH_SITE . '/cache')
);

$cache = JCache::getInstance('', $options);

return $cache;
return JCache::getInstance('', $options);
}

/**
* Method to get client data.
*
* @return array
* @return array
*/
public function getClient()
{
Expand All @@ -136,7 +135,7 @@ public function getClient()
/**
* Get the number of current Cache Groups.
*
* @return int
* @return integer
*/
public function getTotal()
{
Expand All @@ -151,7 +150,7 @@ public function getTotal()
/**
* Method to get a pagination object for the cache.
*
* @return integer
* @return JPagination
*/
public function getPagination()
{
Expand All @@ -173,8 +172,7 @@ public function getPagination()
*/
public function clean($group = '')
{
$cache = $this->getCache();
$cache->clean($group);
$this->getCache()->clean($group);
}

/**
Expand All @@ -199,8 +197,6 @@ public function cleanlist($array)
*/
public function purge()
{
$cache = JFactory::getCache('');

return $cache->gc();
return JFactory::getCache('')->gc();
}
}
23 changes: 22 additions & 1 deletion administrator/components/com_cache/views/cache/view.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,32 @@
*/
class CacheViewCache extends JViewLegacy
{
/**
* The client data
*
* @var object
*/
protected $client;

/**
* The cache data
*
* @var array
*/
protected $data;

/**
* The pagination object
*
* @var JPagination
*/
protected $pagination;

/**
* The model state
*
* @var object
*/
protected $state;

/**
Expand All @@ -48,7 +68,8 @@ public function display($tpl = null)

$this->addToolbar();
$this->sidebar = JHtmlSidebar::render();
parent::display($tpl);

return parent::display($tpl);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion administrator/components/com_cache/views/purge/view.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public function display($tpl = null)
{
$this->addToolbar();
$this->sidebar = JHtmlSidebar::render();
parent::display($tpl);

return parent::display($tpl);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion libraries/joomla/cache/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function __construct($options)
* @param string $type The cache object type to instantiate
* @param array $options The array of options
*
* @return JCache A JCache object
* @return JCacheController A JCacheController object
*
* @since 11.1
*/
Expand Down
2 changes: 1 addition & 1 deletion libraries/joomla/cache/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function __call($name, $arguments)
* @param string $type The cache object type to instantiate; default is output.
* @param array $options Array of options
*
* @return JCache A JCache object
* @return JCacheController A JCacheController object
*
* @since 11.1
* @throws RuntimeException
Expand Down

0 comments on commit b720504

Please sign in to comment.