From 0d119b0436cde77124f813f18e2827081a2c8f37 Mon Sep 17 00:00:00 2001 From: Raul E Watson Date: Thu, 21 Oct 2021 22:25:42 +0100 Subject: [PATCH] Clean code --- Block/InfiniteScroll.php | 35 +++++++++------- Helper/Data.php | 40 ++++++++++++------ etc/acl.xml | 4 +- etc/adminhtml/system.xml | 3 +- etc/config.xml | 3 +- etc/module.xml | 9 ++-- view/frontend/layout/ajaxscroll.xml | 3 +- .../frontend/layout/catalog_category_view.xml | 5 ++- .../layout/catalogsearch_advanced_result.xml | 5 ++- .../layout/catalogsearch_result_index.xml | 5 ++- view/frontend/templates/infinitescroll.phtml | 42 ++++++++++--------- 11 files changed, 91 insertions(+), 63 deletions(-) diff --git a/Block/InfiniteScroll.php b/Block/InfiniteScroll.php index 739c6e5..3b07383 100644 --- a/Block/InfiniteScroll.php +++ b/Block/InfiniteScroll.php @@ -1,19 +1,20 @@ storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA); - if($img) return $urlMedia . $img; - return $urlMedia; - } + $urlMedia = ''; + try { + $urlMedia = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA); + } catch (NoSuchEntityException $e) { + } -} \ No newline at end of file + return $img ? $urlMedia . $img : $urlMedia; + } +} diff --git a/Helper/Data.php b/Helper/Data.php index 583f8b4..df072f8 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -1,5 +1,7 @@ configModule = $this->getConfig(strtolower($this->_getModuleName())); } - public function getConfig($cfg='') + /** + * @param string $cfg + * @return \Magento\Framework\App\Config\ScopeConfigInterface|mixed + */ + public function getConfig(string $cfg = '') { - if($cfg) return $this->scopeConfig->getValue( $cfg, \Magento\Store\Model\ScopeInterface::SCOPE_STORE ); + if ($cfg) { + return $this->scopeConfig->getValue($cfg, \Magento\Store\Model\ScopeInterface::SCOPE_STORE); + } return $this->scopeConfig; } - public function getConfigModule($cfg='', $value=null) + /** + * @param string $cfg + * @param null $value + * @return array|\Magento\Framework\App\Config\ScopeConfigInterface|mixed|null + */ + public function getConfigModule(string $cfg = '', $value = null) { $values = $this->configModule; - if( !$cfg ) return $values; - $config = explode('/', $cfg); - $end = count($config) - 1; + if (!$cfg) { + return $values; + } + $config = explode('/', $cfg); + $end = count($config) - 1; foreach ($config as $key => $vl) { - if( isset($values[$vl]) ){ - if( $key == $end ) { + if (isset($values[$vl])) { + if ($key === $end) { $value = $values[$vl]; - }else { + } else { $values = $values[$vl]; } - } + } } return $value; } -} \ No newline at end of file +} diff --git a/etc/acl.xml b/etc/acl.xml index b6bba1e..cce0314 100644 --- a/etc/acl.xml +++ b/etc/acl.xml @@ -1,5 +1,5 @@ - - + + diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 36fcb71..048ec4b 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -1,4 +1,5 @@ - + + diff --git a/etc/config.xml b/etc/config.xml index 2ed08a9..d750194 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -1,4 +1,5 @@ - + + diff --git a/etc/module.xml b/etc/module.xml index bd91b7f..07c0830 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,10 +1,11 @@ - + + - + - + - \ No newline at end of file + diff --git a/view/frontend/layout/ajaxscroll.xml b/view/frontend/layout/ajaxscroll.xml index 33863ea..658499b 100644 --- a/view/frontend/layout/ajaxscroll.xml +++ b/view/frontend/layout/ajaxscroll.xml @@ -1,4 +1,5 @@ - + + diff --git a/view/frontend/layout/catalog_category_view.xml b/view/frontend/layout/catalog_category_view.xml index ed4ea03..da096d2 100644 --- a/view/frontend/layout/catalog_category_view.xml +++ b/view/frontend/layout/catalog_category_view.xml @@ -1,4 +1,5 @@ - + + - \ No newline at end of file + diff --git a/view/frontend/layout/catalogsearch_advanced_result.xml b/view/frontend/layout/catalogsearch_advanced_result.xml index 508c83b..680b3b9 100644 --- a/view/frontend/layout/catalogsearch_advanced_result.xml +++ b/view/frontend/layout/catalogsearch_advanced_result.xml @@ -1,4 +1,5 @@ - + + - \ No newline at end of file + diff --git a/view/frontend/layout/catalogsearch_result_index.xml b/view/frontend/layout/catalogsearch_result_index.xml index 663b22f..bc0d73f 100644 --- a/view/frontend/layout/catalogsearch_result_index.xml +++ b/view/frontend/layout/catalogsearch_result_index.xml @@ -1,4 +1,5 @@ - + + - \ No newline at end of file + diff --git a/view/frontend/templates/infinitescroll.phtml b/view/frontend/templates/infinitescroll.phtml index 9328c4b..65d7e99 100644 --- a/view/frontend/templates/infinitescroll.phtml +++ b/view/frontend/templates/infinitescroll.phtml @@ -1,4 +1,8 @@ helper('Magepow\InfiniteScroll\Helper\Data'); $isEnabled = $helper->getConfigModule('general/enabled'); $delay = $helper->getConfigModule('general/delay'); @@ -11,12 +15,12 @@ $doneText = $helper->getConfigModule('general/done_text'); $loadMore = $helper->getConfigModule('general/load_more'); $loadMoreText = $helper->getConfigModule('general/load_more_text'); $loadingImage = $helper->getConfigModule('general/loading_image'); -$imgPath = 'magepow/infinitescroll/'.$loadingImage; +$imgPath = 'magepow/infinitescroll/'. $loadingImage; if ($loadingImage) { $loadingImage = $block->getMedia($imgPath); -}else{ +} else { $loadingImage = $this->getViewFileUrl('images/loader-1.gif'); -} +} ?> \ No newline at end of file +