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

Clean up Config.php and use isSetFlag method for boolean functions #214

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
64 changes: 33 additions & 31 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,36 +141,37 @@ public function getWebsiteIdByStoreId($storeId)
/**
* @return mixed
*/
public function getConfig($configPath, $scopeId = null, $scope = null)
public function getConfig($configPath, $scopeId = null, $scope = ScopeInterface::SCOPE_STORE)
{
if (!$scope && $this->isSingleStoreMode()) {
return $this->scopeConfig->getValue($configPath);
}
return $this->scopeConfig->getValue($configPath, $scope ?: ScopeInterface::SCOPE_STORE, is_null($scopeId) ? $this->storeManager->getStore()->getId() : $scopeId);
return $this->scopeConfig->getValue(
$configPath,
$scope,
is_null($scopeId) ? $this->storeManager->getStore()->getId() : $scopeId
);
}

/**
* @return boolean
*/
public function isEnabled($scopeId = null, $scope = null)
public function isEnabled($scopeId = null, $scope = ScopeInterface::SCOPE_STORE)
{
return ($this->getConfig(self::XML_PATH_YOTPO_ENABLED, $scopeId, $scope)) ? true : false;
return $this->scopeConfig->isSetFlag(self::XML_PATH_YOTPO_ENABLED, $scope, $scopeId);
}

/**
* @return boolean
*/
public function isDebugMode($scope = null, $scopeId = null)
public function isDebugMode($scopeId = null, $scope = ScopeInterface::SCOPE_STORE)
{
return ($this->getConfig(self::XML_PATH_YOTPO_DEBUG_MODE_ENABLED, $scope, $scopeId)) ? true : false;
return $this->scopeConfig->isSetFlag(self::XML_PATH_YOTPO_DEBUG_MODE_ENABLED, $scope, $scopeId);
}

/**
* @return string
*/
public function getAppKey($scopeId = null, $scope = null)
public function getAppKey($scopeId = null, $scope = ScopeInterface::SCOPE_STORE)
{
return $this->getConfig(self::XML_PATH_YOTPO_APP_KEY, $scopeId, $scope);
return $this->scopeConfig->getValue(self::XML_PATH_YOTPO_APP_KEY, $scopeId, $scope);
}

/**
Expand All @@ -191,55 +192,56 @@ public function getAppKeys(array $storeIds = [])
/**
* @return string
*/
public function getSecret($scopeId = null, $scope = null)
public function getSecret($scopeId = null, $scope = ScopeInterface::SCOPE_STORE)
{
return (($secret = $this->getConfig(self::XML_PATH_YOTPO_SECRET, $scopeId, $scope))) ? $this->encryptor->decrypt($secret) : null;
$secret = $this->getConfig(self::XML_PATH_YOTPO_SECRET, $scopeId, $scope);
return ($secret) ? $this->encryptor->decrypt($secret) : null;
}

/**
* @return boolean
*/
public function isWidgetEnabled($scopeId = null, $scope = null)
public function isWidgetEnabled($scopeId = null, $scope = ScopeInterface::SCOPE_STORE)
{
return ($this->getConfig(self::XML_PATH_YOTPO_WIDGET_ENABLED, $scopeId, $scope)) ? true : false;
return $this->scopeConfig->isSetFlag(self::XML_PATH_YOTPO_WIDGET_ENABLED, $scope, $scopeId);
}

/**
* @return boolean
*/
public function isCategoryBottomlineEnabled($scopeId = null, $scope = null)
public function isCategoryBottomlineEnabled($scopeId = null, $scope = ScopeInterface::SCOPE_STORE)
{
return ($this->getConfig(self::XML_PATH_YOTPO_YOTPO_CATEGORY_BOTTOMLINE_ENABLED, $scopeId, $scope)) ? true : false;
return $this->scopeConfig->isSetFlag(self::XML_PATH_YOTPO_YOTPO_CATEGORY_BOTTOMLINE_ENABLED, $scope, $scopeId);
}

/**
* @return boolean
*/
public function isBottomlineEnabled($scopeId = null, $scope = null)
public function isBottomlineEnabled($scopeId = null, $scope = ScopeInterface::SCOPE_STORE)
{
return ($this->getConfig(self::XML_PATH_YOTPO_BOTTOMLINE_ENABLED, $scopeId, $scope)) ? true : false;
return $this->scopeConfig->isSetFlag(self::XML_PATH_YOTPO_BOTTOMLINE_ENABLED, $scope, $scopeId);
}

/**
* @return boolean
*/
public function isBottomlineQnaEnabled($scopeId = null, $scope = null)
public function isBottomlineQnaEnabled($scopeId = null, $scope = ScopeInterface::SCOPE_STORE)
{
return ($this->getConfig(self::XML_PATH_YOTPO_BOTTOMLINE_QNA_ENABLED, $scopeId, $scope)) ? true : false;
return $this->scopeConfig->isSetFlag(self::XML_PATH_YOTPO_BOTTOMLINE_QNA_ENABLED, $scope, $scopeId);
}

/**
* @return boolean
*/
public function isMdrEnabled($scopeId = null, $scope = null)
public function isMdrEnabled($scopeId = null, $scope = ScopeInterface::SCOPE_STORE)
{
return ($this->getConfig(self::XML_PATH_YOTPO_MDR_ENABLED, $scopeId, $scope)) ? true : false;
return $this->scopeConfig->isSetFlag(self::XML_PATH_YOTPO_MDR_ENABLED, $scope, $scopeId);
}

/**
* @return array
*/
public function getCustomOrderStatus($scopeId = null, $scope = null)
public function getCustomOrderStatus($scopeId = null, $scope = ScopeInterface::SCOPE_STORE)
{
$orderStatuses = $this->getConfig(self::XML_PATH_YOTPO_CUSTOM_ORDER_STATUS, $scopeId, $scope);
return ($orderStatuses) ? array_map('strtolower', explode(',', $orderStatuses)) : [Order::STATE_COMPLETE];
Expand All @@ -250,7 +252,7 @@ public function getCustomOrderStatus($scopeId = null, $scope = null)
* @param string $format
* @return date
*/
public function getOrdersSyncAfterDate($scopeId = null, $scope = null, $format = 'Y-m-d H:i:s')
public function getOrdersSyncAfterDate($scopeId = null, $scope = ScopeInterface::SCOPE_STORE, $format = 'Y-m-d H:i:s')
{
$timestamp = strtotime($this->getConfig(self::XML_PATH_YOTPO_ORDERS_SYNC_FROM_DATE, $scopeId, $scope) ?: $this->getCurrentDate());
return date($format, $timestamp);
Expand Down Expand Up @@ -289,17 +291,17 @@ public function getOrdersSyncAfterMinDate($format = 'Y-m-d')
/**
* @return boolean
*/
public function isAppKeyAndSecretSet($scopeId = null, $scope = null)
public function isAppKeyAndSecretSet($scopeId = null, $scope = ScopeInterface::SCOPE_STORE)
{
return ($this->getAppKey($scopeId, $scope) && $this->getSecret($scopeId, $scope)) ? true : false;
return ($this->getAppKey($scopeId, $scope) && $this->getSecret($scopeId, $scope));
}

/**
* @return boolean
*/
public function isActivated($scopeId = null, $scope = null)
public function isActivated($scopeId = null, $scope = ScopeInterface::SCOPE_STORE)
{
return ($this->isEnabled($scopeId, $scope) && $this->isAppKeyAndSecretSet($scopeId, $scope)) ? true : false;
return ($this->isEnabled($scopeId, $scope) && $this->isAppKeyAndSecretSet($scopeId, $scope));
}

/**
Expand Down Expand Up @@ -327,7 +329,7 @@ public function setStoreCredentialsAndIsEnabled($appKey, $secret, $isEnabled, $s
* @param int|null $storeId
* @param string|null $scopes
*/
public function resetStoreCredentials($storeId = null, $scopes = ScopeInterface::SCOPE_STORES)
public function resetStoreCredentials($storeId = null, $scopes = ScopeInterface::SCOPE_STORE)
{
$this->resourceConfig->deleteConfig(self::XML_PATH_YOTPO_ENABLED, $scopes, $storeId);
$this->resourceConfig->deleteConfig(self::XML_PATH_YOTPO_APP_KEY, $scopes, $storeId);
Expand Down Expand Up @@ -460,7 +462,7 @@ public function getAllStoreIds($withDefault = false, $onlyActive = true)
public function filterDisabledStoreIds(array $storeIds = [])
{
foreach ($storeIds as $key => $storeId) {
if (!($this->isEnabled($storeId, ScopeInterface::SCOPE_STORE) && $this->isAppKeyAndSecretSet($storeId, ScopeInterface::SCOPE_STORE))) {
if (!($this->isEnabled($storeId) && $this->isAppKeyAndSecretSet($storeId))) {
unset($storeIds[$key]);
}
}
Expand Down