diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..14e897f --- /dev/null +++ b/.gitattributes @@ -0,0 +1,8 @@ +/.github export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/CHANGELOG.md export-ignore +/phpcs.xml.dist export-ignore +/phpmd.xml.dist export-ignore +/phpstan.neon.dist export-ignore +/README.md export-ignore diff --git a/.github/workflows/static-analysis.yaml b/.github/workflows/static-analysis.yaml new file mode 100644 index 0000000..43a1dfc --- /dev/null +++ b/.github/workflows/static-analysis.yaml @@ -0,0 +1,66 @@ +name: 'Static Analysis' + +on: + pull_request: ~ + push: + branches: + - 'master' + +jobs: + static-analysis: + runs-on: 'ubuntu-latest' + + strategy: + matrix: + php-version: + - '8.1' + + steps: + - name: 'Checkout' + uses: 'actions/checkout@v3' + + - name: 'Install PHP' + uses: 'shivammathur/setup-php@v2' + with: + php-version: '${{ matrix.php-version }}' + coverage: 'none' + tools: 'composer:v2' + env: + COMPOSER_AUTH_JSON: | + { + "http-basic": { + "repo.magento.com": { + "username": "${{ secrets.MAGENTO_USERNAME }}", + "password": "${{ secrets.MAGENTO_PASSWORD }}" + } + } + } + + - name: 'Get composer cache directory' + id: 'composer-cache' + run: 'echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT' + + - name: 'Cache dependencies' + uses: 'actions/cache@v3' + with: + path: '${{ steps.composer-cache.outputs.dir }}' + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: '${{ runner.os }}-composer-' + + - name: 'Install dependencies' + run: 'composer install --prefer-dist' + + - name: 'Run composer audit' + run: 'composer audit --format=plain' + + - name: 'Run Parallel Lint' + run: 'vendor/bin/parallel-lint --exclude vendor .' + + - name: 'Run PHP CodeSniffer' + run: 'vendor/bin/phpcs --extensions=php,phtml' + + - name: 'Run PHPMD' + run: 'vendor/bin/phpmd . xml phpmd.xml.dist' + + - name: 'Run PHPStan' + run: 'vendor/bin/phpstan analyse' diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..437d97f --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/.fleet +/.idea +/vendor +/composer.lock +/phpcs.xml +/phpstan.neon diff --git a/Api/Data/AddressInterface.php b/Api/Data/AddressInterface.php index 128054c..c0a6082 100644 --- a/Api/Data/AddressInterface.php +++ b/Api/Data/AddressInterface.php @@ -1,130 +1,111 @@ - * @copyright 2016 Smile - * @license Apache License Version 2.0 - */ + +declare(strict_types=1); + namespace Smile\Map\Api\Data; +use Magento\Customer\Api\Data\RegionInterface; + /** * Address interface definition. - * - * @category Smile - * @package Smile\Map - * @author Aurelien FOUCRET + * Method's return type must be specified using return annotation */ interface AddressInterface { - /**#@+ - * Constants for keys of data array. Identical to the name of the getter in snake case - */ - const STREET = 'street'; - const POSTCODE = 'postcode'; - const CITY = 'city'; - const REGION = 'region'; - const REGION_ID = 'region_id'; - const COUNTRY_ID = 'country_id'; + public const STREET = 'street'; + public const POSTCODE = 'postcode'; + public const CITY = 'city'; + public const REGION = 'region'; + public const REGION_ID = 'region_id'; + public const COUNTRY_ID = 'country_id'; /** * Get region. * - * @return \Magento\Customer\Api\Data\RegionInterface|null + * @return RegionInterface|string|null */ - public function getRegion(); + public function getRegion(): RegionInterface|string|null; /** * Get region ID. * - * @return int|null + * @return ?int */ - public function getRegionId(); + public function getRegionId(): ?int; /** * Two-letter country code in ISO_3166-2 format. * - * @return string|null + * @return ?string */ - public function getCountryId(); + public function getCountryId(): ?string; /** * Get street. * - * @return string[]|string|null + * @return array */ - public function getStreet(); + public function getStreet(): array; /** * Get postcode. * - * @return string|null + * @return ?string */ - public function getPostcode(); + public function getPostcode(): ?string; /** * Get city name. * - * @return string|null + * @return ?string */ - public function getCity(); + public function getCity(): ?string; /** * Set country id. * * @param string $countryId Country id. - * * @return $this */ - public function setCountryId($countryId); + public function setCountryId(string $countryId): self; /** * Set region. * - * @param string $region Region. - * + * @param ?string $region Region. * @return $this */ - public function setRegion($region = null); + public function setRegion(?string $region = null): self; /** * Set region ID. * * @param int $regionId Region id. - * * @return $this */ - public function setRegionId($regionId); + public function setRegionId(int $regionId): self; /** * Set street. * * @param string[]|string $street Street. - * * @return $this */ - public function setStreet($street); + public function setStreet(array|string $street): self; /** * Set postcode. * * @param string $postcode Postcode. - * * @return $this */ - public function setPostcode($postcode); + public function setPostcode(string $postcode): self; /** * Set city name. * * @param string $city City name. - * * @return $this */ - public function setCity($city); + public function setCity(string $city): self; } diff --git a/Api/Data/GeoPointInterface.php b/Api/Data/GeoPointInterface.php index 5886527..3954002 100644 --- a/Api/Data/GeoPointInterface.php +++ b/Api/Data/GeoPointInterface.php @@ -1,45 +1,28 @@ - * @copyright 2016 Smile - * @license Apache License Version 2.0 - */ + +declare(strict_types=1); + namespace Smile\Map\Api\Data; /** * Geo point interface definition. - * - * @category Smile - * @package Smile\Map - * @author Aurelien FOUCRET */ interface GeoPointInterface { - /**#@+ - * Constants for keys of data array. Identical to the name of the getter in snake case - */ - const LATITUDE = 'latitude'; - const LONGITUDE = 'longitude'; - /**#@-*/ + public const LATITUDE = 'latitude'; + public const LONGITUDE = 'longitude'; /** * Geopoint latitude. * * @return float */ - public function getLatitude(); + public function getLatitude(): float; /** * Geopoint longitude. * * @return float */ - public function getLongitude(); + public function getLongitude(): float; } diff --git a/Api/Data/GeolocalizedAddressInterface.php b/Api/Data/GeolocalizedAddressInterface.php index f9ea186..782aa1b 100644 --- a/Api/Data/GeolocalizedAddressInterface.php +++ b/Api/Data/GeolocalizedAddressInterface.php @@ -1,46 +1,28 @@ - * @copyright 2016 Smile - * @license Apache License Version 2.0 - */ + +declare(strict_types=1); + namespace Smile\Map\Api\Data; /** * Geolocalized address interface definition. - * - * @category Smile - * @package Smile\Map - * @author Aurelien FOUCRET */ interface GeolocalizedAddressInterface extends AddressInterface { - /**#@+ - * Constants for keys of data array. Identical to the name of the getter in snake case - */ - const COORDINATES = 'coordinates'; - /**#@-*/ + public const COORDINATES = 'coordinates'; /** * Get address coordinates. * * @return \Smile\Map\Api\Data\GeoPointInterface */ - public function getCoordinates(); + public function getCoordinates(): ?GeoPointInterface; /** * Set address coordinates. * * @param \Smile\Map\Api\Data\GeoPointInterface $coordinates Coordinates. - * * @return $this */ - public function setCoordinates(\Smile\Map\Api\Data\GeoPointInterface $coordinates); + public function setCoordinates(GeoPointInterface $coordinates): self; } diff --git a/Api/MapInterface.php b/Api/MapInterface.php index 0c7b929..37c766b 100644 --- a/Api/MapInterface.php +++ b/Api/MapInterface.php @@ -1,26 +1,13 @@ - * @copyright 2016 Smile - * @license Apache License Version 2.0 - */ + +declare(strict_types=1); + namespace Smile\Map\Api; use Smile\Map\Api\Data\GeoPointInterface; /** * Map interface definition. - * - * @category Smile - * @package Smile\Map - * @author Aurelien FOUCRET */ interface MapInterface { @@ -29,29 +16,28 @@ interface MapInterface * * @return string */ - public function getIdentifier(); + public function getIdentifier(): string; /** * Returns current map provider name. * * @return string */ - public function getName(); + public function getName(): string; /** * Return current map configuration. * * @return array */ - public function getConfig(); + public function getConfig(): array; /** * Returns the direction URL using the current provider. * - * @param GeoPointInterface $dest Destination for the direction URL. - * @param GeoPointInterface $orig Optional origin for the direction URL. - * + * @param \Smile\Map\Api\Data\GeoPointInterface $dest Destination for the direction URL. + * @param \Smile\Map\Api\Data\GeoPointInterface $orig Optional origin for the direction URL. * @return string */ - public function getDirectionUrl(GeoPointInterface $dest, GeoPointInterface $orig = null); + public function getDirectionUrl(GeoPointInterface $dest, ?GeoPointInterface $orig = null): string; } diff --git a/Api/MapProviderInterface.php b/Api/MapProviderInterface.php index 4b6e1c1..08ba428 100644 --- a/Api/MapProviderInterface.php +++ b/Api/MapProviderInterface.php @@ -1,24 +1,11 @@ - * @copyright 2016 Smile - * @license Apache License Version 2.0 - */ + +declare(strict_types=1); + namespace Smile\Map\Api; /** * Map provider interface definition. - * - * @category Smile - * @package Smile\Map - * @author Aurelien FOUCRET */ interface MapProviderInterface { @@ -27,5 +14,5 @@ interface MapProviderInterface * * @return MapInterface */ - public function getMap(); + public function getMap(): MapInterface; } diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e5f9b30 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,19 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +## [2.1.x] - 2023-04-24 +[2.1.x]: https://github.com/Smile-SA/magento2-module-map/compare/2.0.x...2.1.x + +Dataset compatibility ES 2.11.x and PHP 8.2 + +- fix Dynamic type declaration +- fix Type hinting +- Replace `Zend_Date` by `DateTime` +- Remove `MutationObserver` support +- fix UI Component Retailer Offer editing +- Replace `Zend_Validate` by `Laminas\Validator` +- fix Retailer Grid Column Action +- fix Retailer Grid Mass Actions +- fix some translations +- remove Temando/Shipping Plugin diff --git a/Helper/Map.php b/Helper/Map.php index 361d866..971ecee 100644 --- a/Helper/Map.php +++ b/Helper/Map.php @@ -1,22 +1,17 @@ - * @copyright 2016 Smile - * @license Apache License Version 2.0 - */ + +declare(strict_types=1); + namespace Smile\Map\Helper; use Magento\Framework\App\Filesystem\DirectoryList; -use Magento\Framework\Filesystem; -use \Magento\Framework\Locale\Resolver as LocaleResolver; use Magento\Framework\App\Helper\AbstractHelper; use Magento\Framework\App\Helper\Context; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Filesystem; +use Magento\Framework\Filesystem\Directory\ReadInterface; +use Magento\Framework\Locale\Resolver as LocaleResolver; +use Magento\Framework\UrlInterface; use Magento\Framework\View\Asset\Repository; use Magento\MediaStorage\Helper\File\Storage\Database; use Magento\Store\Model\ScopeInterface; @@ -25,110 +20,58 @@ /** * Map helper. - * - * @category Smile - * @package Smile\Map - * @author Aurelien FOUCRET */ class Map extends AbstractHelper { - /** - * @var string - */ - const MAP_CONFIG_XML_PATH = 'smile_map/map'; - - /** - * @var string - */ - const SHARED_SETTINGS_NAME = 'all'; - - /** - * @var \Magento\Framework\Locale\Resolver - */ - private $localeResolver; - - /** - * @var \Magento\MediaStorage\Helper\File\Storage\Database - */ - private $fileStorageHelper; - - /** - * @var \Magento\Framework\Filesystem - */ - private $fileSystem; + private const MAP_CONFIG_XML_PATH = 'smile_map/map'; + private const SHARED_SETTINGS_NAME = 'all'; - /** - * @var \Magento\Framework\Filesystem\Directory\ReadInterface - */ - private $mediaDirectory; - - /** - * @var \Magento\Framework\View\Asset\Repository - */ - private $assetRepository; + private ReadInterface $mediaDirectory; - /** - * @var StoreManagerInterface - */ - protected $storeManager; - - /** - * Map constructor. - * - * @param Context $context Application Context - * @param LocaleResolver $localeResolver Locale Resolver - * @param Database $fileStorageHelper File Storage Helper - * @param Repository $assetRepository Asset Repository - * @param Filesystem $fileSystem File System - * @param StoreManagerInterface $storeManager Store Manager - */ public function __construct( Context $context, - LocaleResolver $localeResolver, - Database $fileStorageHelper, - Repository $assetRepository, - Filesystem $fileSystem, - StoreManagerInterface $storeManager + private LocaleResolver $localeResolver, + private Database $fileStorageHelper, + private Repository $assetRepository, + private Filesystem $fileSystem, + protected StoreManagerInterface $storeManager ) { - $this->localeResolver = $localeResolver; - $this->fileStorageHelper = $fileStorageHelper; - $this->fileSystem = $fileSystem; - $this->assetRepository = $assetRepository; - $this->storeManager = $storeManager; + $this->mediaDirectory = $this->fileSystem->getDirectoryRead(DirectoryList::MEDIA); parent::__construct($context); } /** * Returns currently configured map provider. - * - * @return string */ - public function getProviderIdentifier() + public function getProviderIdentifier(): string { return $this->scopeConfig->getValue(self::MAP_CONFIG_XML_PATH . '/provider'); } /** * Returns map configuration by provider. - * - * @param string $providerIdentifier Provider identifier. - * - * @return mixed[] */ - public function getProviderConfiguration($providerIdentifier) + public function getProviderConfiguration(string $providerIdentifier): array { $config = []; - $mapKeyFunc = function (&$value, $key) use (&$config, $providerIdentifier) { - if (strpos($key, 'provider_' . $providerIdentifier) === 0 || strpos($key, 'provider_' . self::SHARED_SETTINGS_NAME) === 0) { - $prefixes = ['provider_' . $providerIdentifier . '_', 'provider_' . self::SHARED_SETTINGS_NAME . '_']; - $key = str_replace($prefixes, '', $key); + $mapKeyFunc = function (&$value, $key) use (&$config, $providerIdentifier): void { + if ( + str_starts_with($key, 'provider_' . $providerIdentifier) + || str_starts_with($key, 'provider_' . self::SHARED_SETTINGS_NAME) + ) { + $prefixes = ['provider_' . $providerIdentifier . '_', 'provider_' . self::SHARED_SETTINGS_NAME . '_']; + $key = str_replace($prefixes, '', $key); $config[$key] = $value; } }; - $allConfig = $this->scopeConfig->getValue(self::MAP_CONFIG_XML_PATH, 'store', $this->storeManager->getStore()->getCode()); - + $allConfig = $this->scopeConfig->getValue( + self::MAP_CONFIG_XML_PATH, + 'store', + $this->storeManager->getStore()->getCode() + ); + array_walk($allConfig, $mapKeyFunc); if (!isset($config['country'])) { @@ -145,26 +88,22 @@ public function getProviderConfiguration($providerIdentifier) } /** - * Retrieve custom marker icon to use, if any. Otherwise returns default leaflet marker. - * - * @param array $config The Map configuration. - * - * @return string + * Retrieve custom marker icon to use, if any. Otherwise, returns default leaflet marker. */ - private function getMarkerIcon($config) + private function getMarkerIcon(array $config): string { $folderName = MarkerIcon::UPLOAD_DIR; - $storeLogoPath = isset($config['markerIcon']) ? $config['markerIcon'] : null; + $storeLogoPath = $config['markerIcon'] ?? null; $path = $folderName . '/' . $storeLogoPath; - $logoUrl = $this->_urlBuilder->getBaseUrl(['_type' => \Magento\Framework\UrlInterface::URL_TYPE_MEDIA]) . $path; + $logoUrl = $this->_urlBuilder->getBaseUrl(['_type' => UrlInterface::URL_TYPE_MEDIA]) . $path; try { $defaultFile = "Smile_Map::leaflet/images/marker-icon.png"; $params = ['_secure' => $this->_getRequest()->isSecure()]; $url = $this->assetRepository->getUrlWithParams($defaultFile, $params); - } catch (\Magento\Framework\Exception\LocalizedException $e) { - $this->_logger->critical($e); + } catch (LocalizedException $e) { + $this->_logger->critical($e->getMessage()); $url = $this->_urlBuilder->getUrl('', ['_direct' => 'core/index/notFound']); } @@ -176,13 +115,9 @@ private function getMarkerIcon($config) } /** - * If DB file storage is on - find there, otherwise - just file_exists - * - * @param string $filename relative path - * - * @return bool + * If DB file storage is on - find there, otherwise - just file_exists. */ - private function isFile($filename) + private function isFile(string $filename): bool { if ($this->fileStorageHelper->checkDbUsage() && !$this->getMediaDirectory()->isFile($filename)) { $this->fileStorageHelper->saveFileToFilesystem($filename); @@ -192,16 +127,10 @@ private function isFile($filename) } /** - * Get media directory - * - * @return \Magento\Framework\Filesystem\Directory\Read + * Get media directory. */ - private function getMediaDirectory() + private function getMediaDirectory(): ReadInterface { - if (!$this->mediaDirectory) { - $this->mediaDirectory = $this->fileSystem->getDirectoryRead(DirectoryList::MEDIA); - } - return $this->mediaDirectory; } } diff --git a/Model/Address.php b/Model/Address.php index 70eb68d..478466a 100644 --- a/Model/Address.php +++ b/Model/Address.php @@ -1,131 +1,122 @@ - * @copyright 2016 Smile - * @license Apache License Version 2.0 - */ + +declare(strict_types=1); + namespace Smile\Map\Model; -use Smile\Map\Api\Data\AddressInterface; +use Magento\Customer\Api\Data\RegionInterface; use Magento\Framework\Model\AbstractModel; +use Smile\Map\Api\Data\AddressInterface; /** * Default implementation of the AddressInterface. - * - * @category Smile - * @package Smile\Map - * @author Aurelien FOUCRET */ class Address extends AbstractModel implements AddressInterface { + public const RETAILER_ID_FIELD = 'retailer_id'; + /** - * {@inheritDoc} + * @inheritdoc */ - public function getCountryId() + public function getRegion(): RegionInterface|string|null { - return $this->getData(self::COUNTRY_ID); + return $this->getData(self::REGION); } /** - * {@inheritDoc} + * @inheritdoc */ - public function getRegion() + public function getRegionId(): ?int { - return $this->getData(self::REGION); + return (int) $this->getData(self::REGION_ID); } /** - * {@inheritDoc} + * @inheritdoc */ - public function getRegionId() + public function getCountryId(): ?string { - return $this->getData(self::REGION_ID); + return $this->getData(self::COUNTRY_ID); } - /** - * {@inheritDoc} + * @inheritdoc */ - public function getStreet() + public function getStreet(): array { - return is_array($this->getData(self::STREET)) ? $this->getData(self::STREET) : [$this->getData(self::STREET)]; + return is_array($this->getData(self::STREET)) + ? $this->getData(self::STREET) + : [$this->getData(self::STREET)]; } /** - * {@inheritDoc} + * @inheritdoc */ - public function getPostcode() + public function getPostcode(): ?string { return $this->getData(self::POSTCODE); } /** - * {@inheritDoc} + * @inheritdoc */ - public function getCity() + public function getCity(): ?string { return $this->getData(self::CITY); } /** - * {@inheritDoc} + * Set retailer id. */ - public function setRetailerId($retailerId) + public function setRetailerId(int $retailerId): self { - return $this->setData(self::RETAILER_ID, $retailerId); + return $this->setData(self::RETAILER_ID_FIELD, $retailerId); } /** - * {@inheritDoc} + * @inheritdoc */ - public function setCountryId($countryId) + public function setCountryId(string $countryId): self { return $this->setData(self::COUNTRY_ID, $countryId); } /** - * {@inheritDoc} + * @inheritdoc */ - public function setRegion($region = null) + public function setRegion(?string $region = null): self { return $this->setData(self::REGION, $region); } /** - * {@inheritDoc} + * @inheritdoc */ - public function setRegionId($regionId) + public function setRegionId(int $regionId): self { return $this->setData(self::REGION_ID, $regionId); } /** - * {@inheritDoc} + * @inheritdoc */ - public function setStreet($street) + public function setStreet(array|string $street): self { return $this->setData(self::STREET, $street); } /** - * {@inheritDoc} + * @inheritdoc */ - public function setPostcode($postcode) + public function setPostcode(string $postcode): self { return $this->setData(self::POSTCODE, $postcode); } /** - * {@inheritDoc} + * @inheritdoc */ - public function setCity($city) + public function setCity(string $city): self { return $this->setData(self::CITY, $city); } diff --git a/Model/AddressFormatter.php b/Model/AddressFormatter.php index 3b55916..b45d9e5 100644 --- a/Model/AddressFormatter.php +++ b/Model/AddressFormatter.php @@ -1,122 +1,53 @@ - * @copyright 2016 Smile - * @license Apache License Version 2.0 - */ + +declare(strict_types=1); + namespace Smile\Map\Model; -use Smile\Map\Api\Data\AddressInterface; -use Magento\Store\Model\ScopeInterface; +use Magento\Directory\Api\CountryInformationAcquirerInterface; +use Magento\Framework\App\Cache\Type\Config; use Magento\Framework\App\CacheInterface; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\Exception\NoSuchEntityException; +use Magento\Framework\Filter\FilterManager; +use Magento\Store\Model\ScopeInterface; +use Magento\Store\Model\StoreManagerInterface; +use Smile\Map\Api\Data\AddressInterface; /** * Address formatter tool. - * - * @category Smile - * @package Smile\Map - * @author Aurelien FOUCRET */ class AddressFormatter { - /** - * @var string - */ - const FORMAT_XML_BASE_XPATH = 'smile_map/address_templates'; - - /** - * @var string - */ - const FORMAT_TEXT = 'text'; - - /** - * @var string - */ - const FORMAT_ONELINE = 'oneline'; - - /** - * @var string - */ - const FORMAT_HTML = 'html'; - - /** - * @var string - */ - const FORMAT_PDF = 'pdf'; - - /** - * @var \Magento\Store\Model\StoreManagerInterface - */ - private $storeManager; - - /** - * @var \Magento\Framework\App\Config\ScopeConfigInterface - */ - private $scopeConfig; - - /** - * @var \Magento\Directory\Api\CountryInformationAcquirerInterface - */ - private $countryInfo; - - /** - * @var \Magento\Framework\Filter\FilterManager - */ - private $filterManager; - - /** - * @var \Magento\Framework\App\CacheInterface - */ - private $cacheInterface; + private const FORMAT_XML_BASE_XPATH = 'smile_map/address_templates'; + public const FORMAT_TEXT = 'text'; + public const FORMAT_ONELINE = 'oneline'; + public const FORMAT_HTML = 'html'; + public const FORMAT_PDF = 'pdf'; - /** - * @var array - */ - private $localCache = []; + private array $localCache = []; - /** - * Constructor. - * - * @param \Magento\Framework\Filter\FilterManager $filterManager Filter manager used to render address templates. - * @param \Magento\Store\Model\StoreManagerInterface $storeManager Store manager. - * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig Store configuration - * @param \Magento\Directory\Api\CountryInformationAcquirerInterface $countryInfo Country info. - * @param \Magento\Framework\App\CacheInterface $cacheInterface Cache Interface. - */ public function __construct( - \Magento\Framework\Filter\FilterManager $filterManager, - \Magento\Store\Model\StoreManagerInterface $storeManager, - \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, - \Magento\Directory\Api\CountryInformationAcquirerInterface $countryInfo, - \Magento\Framework\App\CacheInterface $cacheInterface + private FilterManager $filterManager, + private StoreManagerInterface $storeManager, + private ScopeConfigInterface $scopeConfig, + private CountryInformationAcquirerInterface $countryInfo, + private CacheInterface $cacheInterface ) { - $this->filterManager = $filterManager; - $this->storeManager = $storeManager; - $this->scopeConfig = $scopeConfig; - $this->countryInfo = $countryInfo; - $this->cacheInterface = $cacheInterface; } /** * Format the address according to a template. * - * @param AddressInterface $address Address to be formatted. - * @param string $format Format code. - * @param int $storeId Store id. - * - * @return string + * @throws NoSuchEntityException */ - public function formatAddress(AddressInterface $address, $format = self::FORMAT_TEXT, $storeId = null) - { + public function formatAddress( + AddressInterface $address, + string $format = self::FORMAT_TEXT, + ?int $storeId = null + ): string { if ($storeId === null) { - $storeId = $this->storeManager->getStore()->getId(); + $storeId = (int) $this->storeManager->getStore()->getId(); } $template = $this->getAddressTemplate($format, $storeId); @@ -128,17 +59,16 @@ public function formatAddress(AddressInterface $address, $format = self::FORMAT_ /** * Extract variables used into templates. * - * @param AddressInterface $address Address to be formatted. - * - * @return array + * @throws NoSuchEntityException */ - private function getVariables(AddressInterface $address) + private function getVariables(AddressInterface $address): array { + // @phpstan-ignore-next-line $variables = $address->getData(); if ($address->getStreet()) { foreach ($address->getStreet() as $index => $streetLine) { - $index = $index + 1; + ++$index; $variables["street{$index}"] = $streetLine; } @@ -155,13 +85,8 @@ private function getVariables(AddressInterface $address) /** * Load template from the configuration. - * - * @param string $format Format code. - * @param int $storeId Store id. - * - * @return string */ - private function getAddressTemplate($format, $storeId) + private function getAddressTemplate(string $format, int $storeId): string { $path = self::FORMAT_XML_BASE_XPATH . '/' . $format; @@ -173,16 +98,14 @@ private function getAddressTemplate($format, $storeId) * This is mainly due to the fact that calling CountryInformationAcquirerInterface::getCountryInfo processes a full * loading of directory data, without using any cache. * - * @param string $countryId The Country Id - * - * @return mixed + * @throws NoSuchEntityException */ - private function getCountryFullName($countryId) + private function getCountryFullName(string $countryId): mixed { $store = $this->storeManager->getStore(); $storeLocale = $this->scopeConfig->getValue( 'general/locale/code', - \Magento\Store\Model\ScopeInterface::SCOPE_STORES, + ScopeInterface::SCOPE_STORES, $store->getCode() ); @@ -196,7 +119,7 @@ private function getCountryFullName($countryId) $this->cacheInterface->save( $data, $cacheKey, - [\Magento\Framework\App\Cache\Type\Config::TYPE_IDENTIFIER], + [Config::TYPE_IDENTIFIER], 7200 ); } diff --git a/Model/Config/Backend/MarkerIcon.php b/Model/Config/Backend/MarkerIcon.php index 8a6b358..28bd6f9 100644 --- a/Model/Config/Backend/MarkerIcon.php +++ b/Model/Config/Backend/MarkerIcon.php @@ -1,34 +1,20 @@ - * @copyright 2017 Smile - * @license Open Software License ("OSL") v. 3.0 - */ + +declare(strict_types=1); + namespace Smile\Map\Model\Config\Backend; +use Magento\Config\Model\Config\Backend\File; + /** * MarkerIcon backend model. Extended to allow svg files. - * - * @category Smile - * @package Smile\Map - * @author Romain Ruaud */ -class MarkerIcon extends \Magento\Config\Model\Config\Backend\File +class MarkerIcon extends File { - /** - * Where the files are stored. - */ - const UPLOAD_DIR = 'smile_map/marker'; + public const UPLOAD_DIR = 'smile_map/marker'; /** - * {@inheritdoc} - * @SuppressWarnings(PHPMD.CamelCaseMethodName) method is inherited. + * @inheritdoc */ protected function _getAllowedExtensions() { diff --git a/Model/Config/Source/MapProvider.php b/Model/Config/Source/MapProvider.php index 3912a94..9c3bd08 100644 --- a/Model/Config/Source/MapProvider.php +++ b/Model/Config/Source/MapProvider.php @@ -1,47 +1,25 @@ - * @copyright 2017 Smile - * @license Open Software License ("OSL") v. 3.0 - */ + +declare(strict_types=1); + namespace Smile\Map\Model\Config\Source; +use Magento\Framework\Data\OptionSourceInterface; +use Smile\Map\Model\MapProvider as MapProviderModel; + /** * Source Model for Map provider in module configuration. - * - * @category Smile - * @package Smile\Map - * @author Romain Ruaud */ -class MapProvider implements \Magento\Framework\Data\OptionSourceInterface +class MapProvider implements OptionSourceInterface { - /** - * @var \Smile\Map\Model\MapProvider - */ - private $mapProvider; - - /** - * MapProvider constructor. - * - * @param \Smile\Map\Model\MapProvider $mapProvider The Map provider - */ - public function __construct(\Smile\Map\Model\MapProvider $mapProvider) + public function __construct(private MapProviderModel $mapProvider) { - $this->mapProvider = $mapProvider; } /** - * Return array of options as value-label pairs - * - * @return array Format: array(array('value' => '', 'label' => '