Skip to content

Commit

Permalink
Php copy-paste detector fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vovayatsyuk committed Oct 23, 2017
1 parent f4693de commit a16f692
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

class TM_Core_Model_Resource_Module_Collection_Abstract extends Varien_Data_Collection
{
protected $_collectedModules = array();

/**
* Lauch data collecting
*
* @param bool $printQuery
* @param bool $logQuery
* @return TM_Core_Model_Resource_Module_Collection_Abstract
*/
public function loadData($printQuery = false, $logQuery = false)
{
if ($this->isLoaded()) {
return $this;
}

$this->_collectedModules = $this->_loadModules();

// calculate totals
$this->_totalRecords = count($this->_collectedModules);
$this->_setIsLoaded();

// paginate and add items
$from = ($this->getCurPage() - 1) * $this->getPageSize();
$to = $from + $this->getPageSize() - 1;
$isPaginated = $this->getPageSize() > 0;

$cnt = 0;
foreach ($this->_collectedModules as $row) {
$cnt++;
if ($isPaginated && ($cnt < $from || $cnt > $to)) {
continue;
}
$item = new $this->_itemObjectClass();
$this->addItem($item->addData($row));
if (!$item->hasId()) {
$item->setId($cnt);
}
}

return $this;
}

protected function _loadModules()
{
return array();
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
<?php

class TM_Core_Model_Resource_Module_LocalCollection extends Varien_Data_Collection
class TM_Core_Model_Resource_Module_LocalCollection extends TM_Core_Model_Resource_Module_Collection_Abstract
{
protected $_collectedModules = array();

/**
* Lauch data collecting
*
* @param bool $printQuery
* @param bool $logQuery
* @return Varien_Data_Collection_Filesystem
* @return array
*/
public function loadData($printQuery = false, $logQuery = false)
protected function _loadModules()
{
if ($this->isLoaded()) {
return $this;
}

$modules = array();
$nodes = Mage::getConfig()->getNode('modules')->children();
foreach ($nodes as $code => $info) {
Expand All @@ -39,30 +31,6 @@ public function loadData($printQuery = false, $logQuery = false)
}
}

$this->_collectedModules = $modules;

// calculate totals
$this->_totalRecords = count($this->_collectedModules);
$this->_setIsLoaded();

// paginate and add items
$from = ($this->getCurPage() - 1) * $this->getPageSize();
$to = $from + $this->getPageSize() - 1;
$isPaginated = $this->getPageSize() > 0;

$cnt = 0;
foreach ($this->_collectedModules as $row) {
$cnt++;
if ($isPaginated && ($cnt < $from || $cnt > $to)) {
continue;
}
$item = new $this->_itemObjectClass();
$this->addItem($item->addData($row));
if (!$item->hasId()) {
$item->setId($cnt);
}
}

return $this;
return $modules;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<?php

class TM_Core_Model_Resource_Module_RemoteCollection extends Varien_Data_Collection
class TM_Core_Model_Resource_Module_RemoteCollection extends TM_Core_Model_Resource_Module_Collection_Abstract
{
const XML_FEED_URL_PATH = 'tmcore/modules/feed_url';

const RESPONSE_CACHE_KEY = 'tm_components_remote_response';

protected $_collectedModules = array();

public function getMapping()
{
return array(
Expand All @@ -31,16 +29,10 @@ public function getMapping()
/**
* Lauch data collecting
*
* @param bool $printQuery
* @param bool $logQuery
* @return Varien_Data_Collection_Filesystem
* @return array
*/
public function loadData($printQuery = false, $logQuery = false)
protected function _loadModules()
{
if ($this->isLoaded()) {
return $this;
}

try {
if (!$responseBody = Mage::app()->loadCache(self::RESPONSE_CACHE_KEY)) {
$responseBody = $this->_fetch($this->_getFeedUri());
Expand Down Expand Up @@ -139,33 +131,10 @@ public function loadData($printQuery = false, $logQuery = false)
}

foreach ($result as $moduleName => $values) {
$values['id'] = $values['code'];
$this->_collectedModules[$values['code']] = $values;
}

// calculate totals
$this->_totalRecords = count($this->_collectedModules);
$this->_setIsLoaded();

// paginate and add items
$from = ($this->getCurPage() - 1) * $this->getPageSize();
$to = $from + $this->getPageSize() - 1;
$isPaginated = $this->getPageSize() > 0;

$cnt = 0;
foreach ($this->_collectedModules as $row) {
$cnt++;
if ($isPaginated && ($cnt < $from || $cnt > $to)) {
continue;
}
$item = new $this->_itemObjectClass();
$this->addItem($item->addData($row));
if (!$item->hasId()) {
$item->setId($cnt);
}
$result[$moduleName]['id'] = $moduleName;
}

return $this;
return $result;
}

/**
Expand Down

0 comments on commit a16f692

Please sign in to comment.