Skip to content

Commit

Permalink
Merge pull request #25 from rafaelstz/bugfix/18-bug-development-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelstz committed Dec 7, 2022
2 parents 43d5555 + ddd2e7f commit 9dab3f2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 33 deletions.
33 changes: 9 additions & 24 deletions Block/Quicklink.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @author Rafael Corrêa Gomes <rafaelcgstz@gmail.com>
* @copyright Copyright (c) 2020.
* @copyright Copyright (c) 2023.
*/

namespace Rafaelcg\Quicklink\Block;
Expand All @@ -16,19 +16,11 @@
*/
class Quicklink extends Template
{
private Template\Context $context;

/**
* @var Template\Context
*/
private $context;
/**
* @var array
*/
private $data;
/**
* @var Data
*/
private $helper;
private array $data;

private Data $helper;

/**
* Constructor
Expand Down Expand Up @@ -56,7 +48,7 @@ public function __construct(
*
* @return array|string
*/
public function initConfig()
public function initConfig(): array|string
{
$initConfig = [];
$timeout = $this->helper->getTimeout();
Expand All @@ -80,24 +72,17 @@ public function initConfig()
return $initConfig;
}

protected function runInDeveloperMode()
{
return $this->helper->getRunInDeveloperMode();
}

/**
* Render GA tracking scripts
*
* @return string
*/
protected function _toHtml()
protected function _toHtml(): string
{
$isProductionMode = $this->_appState->getMode() === State::MODE_PRODUCTION;
$runInDeveloperMode = $this->helper->runInDeveloperMode();
if (!$this->helper->isQuicklinkEnabled()) {
if (!$runInDeveloperMode && !$isProductionMode) {
return '';
}
if (!$runInDeveloperMode && !$isProductionMode) {
return '';
}
return parent::_toHtml();
}
Expand Down
19 changes: 10 additions & 9 deletions Model/Helper/Data.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @author Rafael Corrêa Gomes <rafaelcgstz@gmail.com>
* @copyright Copyright (c) 2020.
* @copyright Copyright (c) 2023.
*/

namespace Rafaelcg\Quicklink\Model\Helper;
Expand Down Expand Up @@ -32,7 +32,7 @@ class Data extends AbstractHelper
* @param null $scopeCode
* @return mixed
*/
public function getConfig($path, $scopeCode = null)
public function getConfig($path, $scopeCode = null): mixed
{
$config = $this->scopeConfig->getValue($path, ScopeInterface::SCOPE_STORE, $scopeCode);
return !empty($config) ? $config : false;
Expand All @@ -43,7 +43,7 @@ public function getConfig($path, $scopeCode = null)
*
* @return int|mixed
*/
public function getTimeout()
public function getTimeout(): mixed
{
return $this->getConfig(self::XML_PATH_TIMEOUT);
}
Expand All @@ -53,7 +53,7 @@ public function getTimeout()
*
* @return int|mixed
*/
public function getRequestLimit()
public function getRequestLimit(): mixed
{
return $this->getConfig(self::XML_PATH_REQUEST_LIMIT);
}
Expand All @@ -63,7 +63,7 @@ public function getRequestLimit()
*
* @return int|mixed
*/
public function getConcurrencyLimit()
public function getConcurrencyLimit(): mixed
{
return $this->getConfig(self::XML_PATH_CONCURRENCY_LIMIT);
}
Expand All @@ -73,29 +73,30 @@ public function getConcurrencyLimit()
*
* @return int|mixed
*/
public function getPriority()
public function getPriority(): mixed
{
return $this->getConfig(self::XML_PATH_PRIORITY);
}

/**
* Whether Quicklink is ready to use
*
* @deprecated 2.2.0
* @param null $store
* @return bool
*/
public function isQuicklinkEnabled($store = null)
public function isQuicklinkEnabled($store = null): bool
{
return $this->scopeConfig->isSetFlag(self::XML_PATH_ACTIVE, ScopeInterface::SCOPE_STORE, $store);
}

/**
* Check if can run in developer mode
* Check if you can run it in developer mode
*
* @param null $store
* @return bool
*/
public function runInDeveloperMode($store = null)
public function runInDeveloperMode($store = null): bool
{
return $this->scopeConfig->isSetFlag(self::XML_PATH_DEVELOPER_MODE, ScopeInterface::SCOPE_STORE, $store);
}
Expand Down

0 comments on commit 9dab3f2

Please sign in to comment.