Skip to content

Commit

Permalink
Drop php7 support + fine tunning
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-kl1 committed Mar 26, 2024
1 parent 5266fbe commit 1c0c2ae
Show file tree
Hide file tree
Showing 33 changed files with 187 additions and 454 deletions.
5 changes: 1 addition & 4 deletions Block/Adminhtml/Config/Form/Field/Select/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@

class Country extends Select
{
private Full $countrySource;

public function __construct(
Context $context,
Full $countrySource,
private Full $countrySource,
array $data = []
) {
$this->countrySource = $countrySource;
parent::__construct($context, $data);
}

Expand Down
4 changes: 1 addition & 3 deletions Block/Adminhtml/Config/Form/Field/Select/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@

class Store extends Select
{
private StoreSource $storeSource;

public function __construct(
Context $context,
StoreSource $storeSource,
private StoreSource $storeSource,
array $data = []
) {
$this->storeSource = $storeSource;
Expand Down
4 changes: 1 addition & 3 deletions Block/Adminhtml/Config/Form/Field/Select/Website.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@

class Website extends Select
{
private StoreSource $storeSource;

public function __construct(
Context $context,
StoreSource $storeSource,
private StoreSource $storeSource,
array $data = []
) {
$this->storeSource = $storeSource;
Expand Down
35 changes: 8 additions & 27 deletions CustomerData/CountryStoreData.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,14 @@

final class CountryStoreData implements SectionSourceInterface
{
private CountryRegistryInterface $countryRegistry;

private ResolverFactory $countryResolverFactory;

private CountryStoreResolverInterface $countryStoreResolver;

private StoreManagerInterface $storeManager;

private ExtensibleDataObjectConverter $dataObjectConverter;

private LoggerInterface $logger;

public function __construct(
CountryRegistryInterface $countryRegistry,
ResolverFactory $countryResolverFactory,
CountryStoreResolverInterface $countryStoreResolver,
StoreManagerInterface $storeManager,
ExtensibleDataObjectConverter $dataObjectConverter,
LoggerInterface $logger
) {
$this->countryRegistry = $countryRegistry;
$this->countryResolverFactory = $countryResolverFactory;
$this->countryStoreResolver = $countryStoreResolver;
$this->storeManager = $storeManager;
$this->dataObjectConverter = $dataObjectConverter;
$this->logger = $logger;
}
private CountryRegistryInterface $countryRegistry,
private ResolverFactory $countryResolverFactory,
private CountryStoreResolverInterface $countryStoreResolver,
private StoreManagerInterface $storeManager,
private ExtensibleDataObjectConverter $dataObjectConverter,
private LoggerInterface $logger
) {}

public function getSectionData(): array
{
Expand All @@ -66,7 +47,7 @@ private function isInvalidated(CountryInterface $country): bool
$registeredStore = $this->countryStoreResolver->getStoreAware($country);
$currentStore = $this->storeManager->getStore();
} catch (NoSuchEntityException $e) {
$this->logger->error($e->getLogMessage(), $e->getTrace());
$this->logger->error($e->getLogMessage(), ['exception' => $e]);

return false;
}
Expand Down
11 changes: 1 addition & 10 deletions Model/Config/Source/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,7 @@

final class Options implements OptionSourceInterface
{
/**
* @var string[][]
*/
private array $options;

public function __construct(
array $options
) {
$this->options = $options;
}
public function __construct(private array $options) {}

public function toOptionArray(): array
{
Expand Down
10 changes: 2 additions & 8 deletions Model/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,11 @@

final class Country extends AbstractSimpleObject implements CountryInterface
{
private ListsInterface $localeList;

private ExtensionAttributesFactory $extensionFactory;

public function __construct(
ExtensionAttributesFactory $extensionFactory,
ListsInterface $localeList,
private ExtensionAttributesFactory $extensionFactory,
private ListsInterface $localeList,
array $data = []
) {
$this->localeList = $localeList;
$this->extensionFactory = $extensionFactory;
parent::__construct($data);
}

Expand Down
18 changes: 4 additions & 14 deletions Model/CountryRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,11 @@ final class CountryRegistry implements CountryRegistryInterface
{
private ?CountryInterface $country = null;

private CountryResolverInterface $countryResolver;

private CountryRepositoryInterface $countryRepository;

private DataPersistorInterface $dataPersistor;

public function __construct(
CountryResolverInterface $countryResolver,
CountryRepositoryInterface $countryRepository,
DataPersistorInterface $dataPersistor
) {
$this->countryResolver = $countryResolver;
$this->countryRepository = $countryRepository;
$this->dataPersistor = $dataPersistor;
}
private CountryResolverInterface $countryResolver,
private CountryRepositoryInterface $countryRepository,
private DataPersistorInterface $dataPersistor
) {}

public function get(): CountryInterface
{
Expand Down
17 changes: 5 additions & 12 deletions Model/CountryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,20 @@
use Opengento\CountryStore\Api\CountryRepositoryInterface;
use Opengento\CountryStore\Api\Data\CountryInterface;
use Opengento\CountryStore\Api\Data\CountryInterfaceFactory;

use function strtoupper;

final class CountryRepository implements CountryRepositoryInterface
{
private CountryInterfaceFactory $countryFactory;

private ReadExtensions $readExtensions;

/**
* @var CountryInterface[]
*/
private array $countries;
private array $countries = [];

public function __construct(
CountryInterfaceFactory $countryFactory,
ReadExtensions $readExtensions
) {
$this->countryFactory = $countryFactory;
$this->readExtensions = $readExtensions;
$this->countries = [];
}
private CountryInterfaceFactory $countryFactory,
private ReadExtensions $readExtensions
) {}

public function get(string $countryCode): CountryInterface
{
Expand Down
17 changes: 7 additions & 10 deletions Model/CountryResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Opengento\CountryStore\Model;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Exception\NotFoundException;
use Magento\Store\Model\ScopeInterface;
use Opengento\CountryStore\Api\CountryResolverInterface;
use Opengento\CountryStore\Api\Data\CountryInterface;
Expand All @@ -19,18 +20,14 @@ final class CountryResolver implements CountryResolverInterface

private const CONFIG_PATH_COUNTRY_STORE_RESOLVER_CODE = 'country/resolver/code';

private ScopeConfigInterface $scopeConfig;

private ResolverFactory $resolverFactory;

public function __construct(
ScopeConfigInterface $scopeConfig,
ResolverFactory $resolverFactory
) {
$this->scopeConfig = $scopeConfig;
$this->resolverFactory = $resolverFactory;
}
private ScopeConfigInterface $scopeConfig,
private ResolverFactory $resolverFactory
) {}

/**
* @throws NotFoundException
*/
public function getCountry(): CountryInterface
{
return $this->resolverFactory->get($this->resolveCountryResolverCode())->getCountry();
Expand Down
19 changes: 5 additions & 14 deletions Model/CountryStoreResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,16 @@
use Opengento\CountryStore\Api\Data\CountryInterface;
use Opengento\CountryStore\Model\Mapper\CountryStoreMapperInterface;
use Opengento\CountryStore\Model\Store\GetStoreByCountryInterface;

use function in_array;

final class CountryStoreResolver implements CountryStoreResolverInterface
{
private StoreManagerInterface $storeManager;

private CountryStoreMapperInterface $countryStoreMapper;

private GetStoreByCountryInterface $getStoreByCountry;

public function __construct(
StoreManagerInterface $storeManager,
CountryStoreMapperInterface $countryStoreMapper,
GetStoreByCountryInterface $getStoreByCountry
) {
$this->storeManager = $storeManager;
$this->countryStoreMapper = $countryStoreMapper;
$this->getStoreByCountry = $getStoreByCountry;
}
private StoreManagerInterface $storeManager,
private CountryStoreMapperInterface $countryStoreMapper,
private GetStoreByCountryInterface $getStoreByCountry
) {}

public function getStoreAware(CountryInterface $country): StoreInterface
{
Expand Down
1 change: 1 addition & 0 deletions Model/EntityManager/CountryHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Magento\Framework\Api\AbstractSimpleObject;
use Magento\Framework\EntityManager\HydratorInterface;
use Opengento\CountryStore\Api\Data\CountryInterface;

use function is_callable;
use function is_object;
use function method_exists;
Expand Down
41 changes: 14 additions & 27 deletions Model/Mapper/CountryStoreMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,32 @@

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Store\Api\Data\StoreInterface;
use Magento\Store\Api\Data\WebsiteInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Store\Api\StoreRepositoryInterface;
use Magento\Store\Api\WebsiteRepositoryInterface;
use Opengento\CountryStore\Api\Data\CountryInterface;
use Psr\Log\LoggerInterface;

use function array_fill_keys;
use function array_merge_recursive;

final class CountryStoreMapper implements CountryStoreMapperInterface
{
private const CONFIG_PATH_COUNTRY_STORE_MAP = 'country/information/store';

private ScopeConfigInterface $scopeConfig;

private SerializerInterface $serializer;

private StoreManagerInterface $storeManager;

private LoggerInterface $logger;

private ?array $countryStoreMapper = null;

private ?array $countriesByStore = null;

private ?array $storesByCountry = null;

public function __construct(
ScopeConfigInterface $scopeConfig,
SerializerInterface $serializer,
StoreManagerInterface $storeManager,
LoggerInterface $logger
) {
$this->scopeConfig = $scopeConfig;
$this->serializer = $serializer;
$this->storeManager = $storeManager;
$this->logger = $logger;
}
private ScopeConfigInterface $scopeConfig,
private SerializerInterface $serializer,
private StoreRepositoryInterface $storeRepository,
private WebsiteRepositoryInterface $websiteRepository,
private LoggerInterface $logger
) {}

public function getCountriesByStore(StoreInterface $store): array
{
Expand Down Expand Up @@ -77,17 +64,17 @@ private function loadMapper(): void
$countries = (array) $countryStoreMapper['countries'];

try {
$store = $this->storeManager->getStore((int) $countryStoreMapper['store']);
} catch (NoSuchEntityException $e) {
$this->logger->error($e->getLogMessage(), $e->getTrace());
$store = $this->storeRepository->getActiveStoreById((int) $countryStoreMapper['store']);
} catch (LocalizedException $e) {
$this->logger->error($e->getLogMessage(), ['exception' => $e]);
continue;
}
$this->countriesByStore[$store->getCode()] = $countries;

try {
$website = $this->storeManager->getWebsite($store->getWebsiteId());
$website = $this->websiteRepository->getById((int) $store->getWebsiteId());
} catch (LocalizedException $e) {
$this->logger->error($e->getLogMessage(), $e->getTrace());
$this->logger->error($e->getLogMessage(), ['exception' => $e]);
continue;
}
$storeCountries = array_fill_keys($countries, [$store->getCode()]);
Expand Down
18 changes: 4 additions & 14 deletions Model/Resolver/CloudFare.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,11 @@ final class CloudFare implements CountryResolverInterface

public const CF_HTTP_HEADER_IPCOUNTRY = 'HTTP_CF_IPCOUNTRY';

private Request $request;

private ResolverFactory $resolverFactory;

private CountryRepositoryInterface $countryRepository;

public function __construct(
Request $request,
ResolverFactory $resolverFactory,
CountryRepositoryInterface $countryRepository
) {
$this->request = $request;
$this->resolverFactory = $resolverFactory;
$this->countryRepository = $countryRepository;
}
private Request $request,
private ResolverFactory $resolverFactory,
private CountryRepositoryInterface $countryRepository
) {}

public function getCountry(): CountryInterface
{
Expand Down
Loading

0 comments on commit 1c0c2ae

Please sign in to comment.