Skip to content

Commit

Permalink
Config now implements the interface
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenBoersma committed Mar 3, 2023
1 parent 4fe2dd5 commit 4319014
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
26 changes: 13 additions & 13 deletions src/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@

namespace Elgentos\Rumvision\Model;

use Elgentos\Rumvision\Api\ConfigurationInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface;

class Config
class Config implements ConfigurationInterface
{
private const CONFIG_RUMVISION_ENALBED = 'elgentos_rumvision/general/enabled';
private const CONFIG_RUMVISION_TRACKING_ID = 'elgentos_rumvision/general/tracking_id';
private const CONFIG_RUMVISION_HOST_NAME = 'elgentos_rumvision/general/hostname';

/**
* @param ScopeConfigInterface $config
* @param StoreManagerInterface $storeManager
Expand All @@ -26,23 +23,26 @@ public function __construct(
private StoreManagerInterface $storeManager,
) {}

public function isEnabled() :bool
public function isEnabled(int $storeId = null): bool
{
return (bool)$this->config->getValue(self::CONFIG_RUMVISION_ENALBED, ScopeInterface::SCOPE_STORE, $this->getStoreId());
return (bool)$this->config->getValue(self::CONFIG_RUMVISION_ENALBED, ScopeInterface::SCOPE_STORE, $this->getStoreId($storeId));
}

public function getTrackingId() :string
public function getTrackingId(int $storeId = null): string
{
return $this->config->getValue(self::CONFIG_RUMVISION_TRACKING_ID, ScopeInterface::SCOPE_STORE, $this->getStoreId());
return (string)$this->config->getValue(self::CONFIG_RUMVISION_ENALBED, ScopeInterface::SCOPE_STORE, $this->getStoreId($storeId));
}

public function getHostName() :string
public function getHostName(int $storeId = null): string
{
return $this->config->getValue(self::CONFIG_RUMVISION_HOST_NAME, ScopeInterface::SCOPE_STORE, $this->getStoreId());
return (string)$this->config->getValue(self::CONFIG_RUMVISION_ENALBED, ScopeInterface::SCOPE_STORE, $this->getStoreId($storeId));
}

public function getStoreId() :int
public function getStoreId(int $storeId = null) :int
{
return (int)$this->storeManager->getStore()->getId();
return (int)$this->storeManager
->getStore($storeId)
->getId();
}

}
23 changes: 14 additions & 9 deletions src/ViewModel/Rumvision.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,34 @@

namespace Elgentos\Rumvision\ViewModel;

use Elgentos\Rumvision\Model\Config;
use Elgentos\Rumvision\Api\ConfigurationInterface;
use Magento\Framework\View\Element\Block\ArgumentInterface;

class Rumvision implements ArgumentInterface
{
public function __construct(
private Config $config
)
{}
private ConfigurationInterface $configuration
) {}

public function shouldIncludeScript(): ?bool
public function shouldIncludeScript(): bool
{
return (bool)$this->config->isEnabled()
&& (bool)$this->config->getTrackingId();
$isEnabled = $this->configuration
->isEnabled();
$trackingId = $this->configuration
->getTrackingId();

return $isEnabled && $trackingId;
}

public function getTrackingId() :string
{
return $this->config->getTrackingId();
return $this->configuration
->getTrackingId();
}

public function getHostName() :string
{
return $this->config->getHostName();
return $this->configuration
->getHostName();
}
}

0 comments on commit 4319014

Please sign in to comment.