Skip to content

Commit 3f7d9c1

Browse files
authored
Merge pull request #6 from diazwatson/CR
Clean code
2 parents be26b4a + 0d119b0 commit 3f7d9c1

File tree

11 files changed

+91
-63
lines changed

11 files changed

+91
-63
lines changed

Block/InfiniteScroll.php

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Magepow\InfiniteScroll\Block;
46

5-
/**
6-
* Class InfiniteScroll
7-
*
8-
*/
7+
use Magento\Framework\Exception\NoSuchEntityException;
8+
99
class InfiniteScroll extends \Magento\Framework\View\Element\Template
1010
{
11+
private \Magento\Store\Model\StoreManagerInterface $storeManager;
1112

12-
/**
13+
/**
1314
* InfiniteScroll constructor.
1415
* @param \Magento\Framework\View\Element\Template\Context $context
15-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
16-
* @param array $data
16+
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
17+
* @param array $data
1718
*/
1819
public function __construct(
1920
\Magento\Framework\View\Element\Template\Context $context,
@@ -26,15 +27,17 @@ public function __construct(
2627

2728

2829
/**
29-
* getLoadingImage
30-
*
31-
* @return mixed
30+
* @param null $img
31+
* @return string
3232
*/
33-
public function getMedia($img=null)
33+
public function getMedia($img = null): string
3434
{
35-
$urlMedia = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
36-
if($img) return $urlMedia . $img;
37-
return $urlMedia;
38-
}
35+
$urlMedia = '';
36+
try {
37+
$urlMedia = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
38+
} catch (NoSuchEntityException $e) {
39+
}
3940

40-
}
41+
return $img ? $urlMedia . $img : $urlMedia;
42+
}
43+
}

Helper/Data.php

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Magepow\InfiniteScroll\Helper;
46

57
class Data extends \Magento\Framework\App\Helper\AbstractHelper
@@ -11,34 +13,46 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
1113

1214
public function __construct(
1315
\Magento\Framework\App\Helper\Context $context
14-
)
15-
{
16+
) {
1617
parent::__construct($context);
1718
$this->configModule = $this->getConfig(strtolower($this->_getModuleName()));
1819
}
1920

20-
public function getConfig($cfg='')
21+
/**
22+
* @param string $cfg
23+
* @return \Magento\Framework\App\Config\ScopeConfigInterface|mixed
24+
*/
25+
public function getConfig(string $cfg = '')
2126
{
22-
if($cfg) return $this->scopeConfig->getValue( $cfg, \Magento\Store\Model\ScopeInterface::SCOPE_STORE );
27+
if ($cfg) {
28+
return $this->scopeConfig->getValue($cfg, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
29+
}
2330
return $this->scopeConfig;
2431
}
2532

26-
public function getConfigModule($cfg='', $value=null)
33+
/**
34+
* @param string $cfg
35+
* @param null $value
36+
* @return array|\Magento\Framework\App\Config\ScopeConfigInterface|mixed|null
37+
*/
38+
public function getConfigModule(string $cfg = '', $value = null)
2739
{
2840
$values = $this->configModule;
29-
if( !$cfg ) return $values;
30-
$config = explode('/', $cfg);
31-
$end = count($config) - 1;
41+
if (!$cfg) {
42+
return $values;
43+
}
44+
$config = explode('/', $cfg);
45+
$end = count($config) - 1;
3246
foreach ($config as $key => $vl) {
33-
if( isset($values[$vl]) ){
34-
if( $key == $end ) {
47+
if (isset($values[$vl])) {
48+
if ($key === $end) {
3549
$value = $values[$vl];
36-
}else {
50+
} else {
3751
$values = $values[$vl];
3852
}
39-
}
53+
}
4054

4155
}
4256
return $value;
4357
}
44-
}
58+
}

etc/acl.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<?xml version="1.0"?>
2-
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
33
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
44
<acl>
55
<resources>

etc/adminhtml/system.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?xml version="1.0"?>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
23
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
34
<system>
45
<tab id="magepow" translate="label" sortOrder="89">

etc/config.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?xml version="1.0"?>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
23
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
34
<default>
45
<magepow_infinitescroll>

etc/module.xml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
<?xml version="1.0"?>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
23
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
3-
<module name="Magepow_InfiniteScroll" setup_version="1.0.0">
4+
<module name="Magepow_InfiniteScroll">
45
<sequence>
56
<module name="Magento_Catalog"/>
67
<module name="Magento_CatalogSearch"/>
7-
<module name="Magento_LayeredNavigation" />
8+
<module name="Magento_LayeredNavigation"/>
89
</sequence>
910
</module>
10-
</config>
11+
</config>

view/frontend/layout/ajaxscroll.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?xml version="1.0"?>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
23
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
34
<body>
45
<referenceContainer name="before.body.end">
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?xml version="1.0"?>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
23
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
34
<update handle="ajaxscroll"/>
4-
</page>
5+
</page>
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?xml version="1.0"?>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
23
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
34
<update handle="ajaxscroll"/>
4-
</page>
5+
</page>
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?xml version="1.0"?>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
23
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
34
<update handle="ajaxscroll"/>
4-
</page>
5+
</page>

0 commit comments

Comments
 (0)