Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Avoid running it in development mode #22

Merged
merged 1 commit into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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