From c824de8a71ea845cad8c06fe9580ff39255de952 Mon Sep 17 00:00:00 2001 From: Cristian Vatca Date: Thu, 10 Oct 2024 14:28:26 +0300 Subject: [PATCH] adding modifications for PHP 8.3 and Magento 2.4.7 adding modifications for PHP 8.3 and Magento 2.4.7, code cleanup and small fixes. --- Block/GigyaScript.php | 2 +- Controller/Raas/GigyaPost.php | 2 +- Helper/CmsStarterKit/GSFactory.php | 12 ++-- Helper/CmsStarterKit/GigyaApiHelper.php | 20 +++---- Helper/CmsStarterKit/GigyaJsonObject.php | 5 +- .../fieldMapping/GigyaUpdater.php | 11 ++-- Helper/CmsStarterKit/user/GigyaProfile.php | 12 ++-- Helper/CmsStarterKit/user/GigyaUser.php | 10 ++-- Helper/GigyaCronHelper.php | 8 ++- Helper/GigyaMageHelper.php | 27 ++++++--- Helper/GigyaScriptHelper.php | 5 +- Helper/GigyaSyncHelper.php | 13 +++-- Helper/RetryGigyaSyncHelper.php | 21 ++++--- Model/Cache/Type/FieldMapping.php | 13 +++-- Model/Config.php | 32 +++++------ Model/Config/Backend/AppSecret.php | 15 +++-- Model/Config/Backend/KeyFileLocation.php | 36 +++++++----- .../Source/DeletionNotFoundBehavior.php | 4 +- Model/Config/Source/DeletionType.php | 4 +- Model/Config/Source/Domain.php | 12 ++-- Model/Config/Source/SessionMode.php | 9 +-- Model/Config/ValidateAWSDetails.php | 56 +++++++++++-------- Model/Config/ValidateFieldMappingConf.php | 49 +++++++++------- Model/Cron/GigyaOfflineSync.php | 15 ++--- Model/Cron/RetryGigyaUpdate.php | 16 ++++-- Model/FieldMapping/AbstractFieldMapping.php | 2 +- Model/FieldMapping/GigyaFromMagento.php | 12 ++-- Model/GigyaAccountService.php | 10 ++-- Model/GigyaCustomerFieldsUpdater.php | 10 ++-- Model/MagentoCustomerFieldsUpdater.php | 23 ++++---- Model/ResourceModel/ConnectionFactory.php | 10 +++- Model/Session.php | 2 +- Model/Session/Extend.php | 36 ++++++------ Observer/AbstractGigyaAccountEnricher.php | 5 +- Observer/AbstractMagentoCustomerEnricher.php | 4 +- Observer/BackendMagentoCustomerEnricher.php | 3 +- Observer/DefaultGigyaSyncFieldMapping.php | 12 ++-- Observer/SyncCustomerToGigyaObserver.php | 13 +++-- Plugin/App/ConfigPlugin.php | 7 ++- Plugin/Config/Model/Config.php | 14 +++-- .../Api/AllowDeleteInvalidCustomer.php | 31 +++++----- .../Model/CustomerExtractorPlugin.php | 5 +- .../Model/RollbackGigyaDataPlugin.php | 11 ++-- Plugin/Framework/Session/Config.php | 7 ++- Plugin/Framework/Session/SessionManager.php | 18 +++--- Session/Config.php | 20 ++++--- Setup/InstallSchema.php | 4 +- Setup/UpgradeData.php | 3 +- Setup/UpgradeSchema.php | 8 ++- 49 files changed, 386 insertions(+), 293 deletions(-) diff --git a/Block/GigyaScript.php b/Block/GigyaScript.php index 10048d9..3b17fc2 100644 --- a/Block/GigyaScript.php +++ b/Block/GigyaScript.php @@ -59,7 +59,7 @@ class GigyaScript extends Template protected EncoderInterface $urlEncoder; protected GigyaScriptHelper $scriptHelper; - private StoreInterface $store; + protected StoreInterface $store; /** * GigyaScript constructor. diff --git a/Controller/Raas/GigyaPost.php b/Controller/Raas/GigyaPost.php index 3b5cb91..37ef32c 100644 --- a/Controller/Raas/GigyaPost.php +++ b/Controller/Raas/GigyaPost.php @@ -56,7 +56,7 @@ class GigyaPost extends LoginPost /** * @var AccountManagementInterface */ - protected AccountManagementInterface $customerAccountManagement; + protected $customerAccountManagement; /** * @var Address diff --git a/Helper/CmsStarterKit/GSFactory.php b/Helper/CmsStarterKit/GSFactory.php index 84a56c5..605e163 100644 --- a/Helper/CmsStarterKit/GSFactory.php +++ b/Helper/CmsStarterKit/GSFactory.php @@ -2,7 +2,9 @@ namespace Gigya\GigyaIM\Helper\CmsStarterKit; +use Exception; use Gigya\PHP\GSException; +use Gigya\PHP\GSKeyNotFoundException; use Gigya\PHP\GSObject; class GSFactory @@ -17,7 +19,7 @@ class GSFactory * * @return GigyaApiRequest * - * @throws \Exception + * @throws Exception */ public static function createGsRequest($apiKey, $secret, $apiMethod, $params, $dataCenter = "us1.gigya.com", $useHTTPS = true) { @@ -35,7 +37,7 @@ public static function createGsRequest($apiKey, $secret, $apiMethod, $params, $d * * @return GigyaApiRequest * - * @throws \Exception + * @throws Exception */ public static function createGSRequestAppKey($apiKey, $key, $secret, $apiMethod, $params, $dataCenter = "us1.gigya.com", $useHTTPS = true) { @@ -52,7 +54,7 @@ public static function createGSRequestAppKey($apiKey, $key, $secret, $apiMethod, * @param bool $useHTTPS * * @return GigyaAuthRequest - * @throws \Gigya\PHP\GSKeyNotFoundException + * @throws GSKeyNotFoundException */ public static function createGSRequestPrivateKey($apiKey, $userKey, $privateKey, $apiMethod, $params, $dataCenter = "us1.gigya.com", $useHTTPS = true) { @@ -68,7 +70,7 @@ public static function createGSRequestPrivateKey($apiKey, $userKey, $privateKey, * * @return GigyaApiRequest * - * @throws \Exception + * @throws Exception */ public static function createGSRequestAccessToken($token, $apiMethod, $params, $dataCenter = "us1.gigya.com", $useHTTPS = true) { @@ -80,7 +82,7 @@ public static function createGSRequestAccessToken($token, $apiMethod, $params, $ * * @return GSObject * @throws GSException - * @throws \Exception + * @throws Exception */ public static function createGSObjectFromArray($array) { diff --git a/Helper/CmsStarterKit/GigyaApiHelper.php b/Helper/CmsStarterKit/GigyaApiHelper.php index 9a1c7ad..6ae5863 100644 --- a/Helper/CmsStarterKit/GigyaApiHelper.php +++ b/Helper/CmsStarterKit/GigyaApiHelper.php @@ -2,6 +2,7 @@ namespace Gigya\GigyaIM\Helper\CmsStarterKit; +use Exception; use Gigya\GigyaIM\Helper\CmsStarterKit\user\GigyaUser; use Gigya\GigyaIM\Helper\CmsStarterKit\user\GigyaUserFactory; use Gigya\PHP\GSException; @@ -9,7 +10,6 @@ use Gigya\PHP\GSResponse; use Gigya\PHP\JWTUtils; use Gigya\PHP\SigUtils; -use stdClass; use Magento\Framework\Module\Dir; class GigyaApiHelper @@ -72,7 +72,7 @@ public function __construct( * * @throws GSApiException * @throws GSException - * @throws \Exception + * @throws Exception */ public function sendApiCall($method, $params) { @@ -111,7 +111,7 @@ public function sendApiCall($method, $params) * * @return GigyaUser|false * - * @throws \Exception + * @throws Exception * @throws GSApiException */ public function validateUid($uid, $uidSignature, $signatureTimestamp, $include = null, $extraProfileFields = null, $orgParams = []) @@ -143,13 +143,13 @@ public function validateUid($uid, $uidSignature, $signatureTimestamp, $include = * * @return GigyaUser|false * - * @throws \Gigya\GigyaIM\Helper\CmsStarterKit\GSApiException + * @throws GSApiException */ public function validateJwtAuth($uid, $idToken, $include = null, $extraProfileFields = null, $orgParams = null) { try { $jwt = JWTUtils::validateSignature($idToken, $this->apiKey, $this->dataCenter); - } catch (\Exception $e) { + } catch (Exception $e) { return false; } @@ -168,7 +168,7 @@ public function validateJwtAuth($uid, $idToken, $include = null, $extraProfileFi * * @return GigyaUser * - * @throws \Exception + * @throws Exception * @throws GSApiException */ public function fetchGigyaAccount($uid, $include = null, $extraProfileFields = null, $params = []) @@ -283,7 +283,7 @@ public function searchGigyaUsers($query, $useCursor = false) * @param string $uid UID * @param array $data data * - * @throws \Exception + * @throws Exception * @throws \InvalidArgumentException * @throws GSApiException */ @@ -314,7 +314,7 @@ public function updateGigyaAccount($uid, $data) } /** - * @throws \Exception + * @throws Exception * @throws GSApiException */ public function getSiteSchema() @@ -328,7 +328,7 @@ public function getSiteSchema() * * @return bool * - * @throws \Exception + * @throws Exception * @throws GSException */ public function isRaasEnabled($apiKey = null) @@ -345,7 +345,7 @@ public function isRaasEnabled($apiKey = null) if ($e->getErrorCode() == 403036) { return false; } - throwException($e); + throw new Exception($e); } return false; diff --git a/Helper/CmsStarterKit/GigyaJsonObject.php b/Helper/CmsStarterKit/GigyaJsonObject.php index a39d630..53815e7 100644 --- a/Helper/CmsStarterKit/GigyaJsonObject.php +++ b/Helper/CmsStarterKit/GigyaJsonObject.php @@ -2,6 +2,7 @@ namespace Gigya\GigyaIM\Helper\CmsStarterKit; +use Exception; use stdClass; abstract class GigyaJsonObject extends stdClass @@ -26,7 +27,7 @@ public function __construct($json) * @param $arguments * * @return mixed|null - * @throws \Exception + * @throws Exception */ public function __call($name, $arguments) { @@ -39,7 +40,7 @@ public function __call($name, $arguments) return $this->$property = $arguments[0]; } else { - throw new \Exception("Method $name does not exist"); + throw new Exception("Method $name does not exist"); } } diff --git a/Helper/CmsStarterKit/fieldMapping/GigyaUpdater.php b/Helper/CmsStarterKit/fieldMapping/GigyaUpdater.php index a84e9e6..1f8caa0 100644 --- a/Helper/CmsStarterKit/fieldMapping/GigyaUpdater.php +++ b/Helper/CmsStarterKit/fieldMapping/GigyaUpdater.php @@ -2,6 +2,7 @@ namespace Gigya\GigyaIM\Helper\CmsStarterKit\fieldMapping; +use DateTime; use Exception; use Gigya\GigyaIM\Helper\CmsStarterKit\GigyaApiHelper; use Gigya\GigyaIM\Helper\CmsStarterKit\GSApiException; @@ -58,7 +59,7 @@ public function __construct( $apiHelper ) { $this->cmsArray = (!empty($cmsValuesArray)) ? $cmsValuesArray : []; - $this->gigyaUid = $gigyaUid; + $this->gigyaUid = (string)$gigyaUid; $this->path = (string) $path; $this->mapped = !empty($this->path); $this->apiHelper = $apiHelper; @@ -189,6 +190,7 @@ protected function retrieveFieldMappings(): void /** * @return array + * @throws Exception */ protected function createGigyaArray(): array { @@ -221,12 +223,10 @@ private function castVal(mixed $val, $conf): mixed case "text": case "varchar": return (string) $val; - break; case "long"; case "integer": case "int": return (int) $val; - break; case "boolean": case "bool": if (is_string($val)) { @@ -234,19 +234,16 @@ private function castVal(mixed $val, $conf): mixed } return filter_var($val, FILTER_VALIDATE_BOOLEAN); - break; case 'date': if ($val and !preg_match('/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(Z|(\+|-)\d{2}(:?\d{2})?)/', $val)) { - $datetime = new \DateTime($val); + $datetime = new DateTime($val); // Return date in format ISO 8601 (https://en.wikipedia.org/wiki/ISO_8601) $val = $datetime->format('c'); } return $val; - break; default: return $val; - break; } } diff --git a/Helper/CmsStarterKit/user/GigyaProfile.php b/Helper/CmsStarterKit/user/GigyaProfile.php index d8721c9..39661c8 100644 --- a/Helper/CmsStarterKit/user/GigyaProfile.php +++ b/Helper/CmsStarterKit/user/GigyaProfile.php @@ -10,12 +10,12 @@ class GigyaProfile extends GigyaJsonObject /** * @var int */ - private int $birthDay; + private ?int $birthDay=null; /** * @var int */ - private int $birthMonth; + private ?int $birthMonth=null; /** * @var int @@ -45,7 +45,7 @@ class GigyaProfile extends GigyaJsonObject /** * @var string */ - private string $gender; + private ?string $gender=null; /** * @var string @@ -205,7 +205,7 @@ class GigyaProfile extends GigyaJsonObject /** * @return int */ - public function getBirthDay(): int + public function getBirthDay(): int | null { return $this->birthDay; } @@ -221,7 +221,7 @@ public function setBirthDay($birthDay): void /** * @return int */ - public function getBirthMonth(): int + public function getBirthMonth(): int | null { return $this->birthMonth; } @@ -317,7 +317,7 @@ public function setFirstName($firstName): void /** * @return string */ - public function getGender(): string + public function getGender(): string | null { return $this->gender; } diff --git a/Helper/CmsStarterKit/user/GigyaUser.php b/Helper/CmsStarterKit/user/GigyaUser.php index ecd563d..66124df 100644 --- a/Helper/CmsStarterKit/user/GigyaUser.php +++ b/Helper/CmsStarterKit/user/GigyaUser.php @@ -84,7 +84,7 @@ class GigyaUser extends GigyaJsonObject /** * @var string */ - private string $isActive; + private ?string $isActive = ""; /** * @var array @@ -102,19 +102,19 @@ class GigyaUser extends GigyaJsonObject private string $time; /** - * @var array + * @var array|null */ - private array $data; + private ?array $data = []; /** * @var array */ - private array $subscriptions; + private ?array $subscriptions = []; /** * @var boolean */ - private bool $isVerified; + private ?bool $isVerified = false; /** * @return string diff --git a/Helper/GigyaCronHelper.php b/Helper/GigyaCronHelper.php index 38ce814..ca6cd5a 100644 --- a/Helper/GigyaCronHelper.php +++ b/Helper/GigyaCronHelper.php @@ -13,6 +13,8 @@ use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Store\Model\StoreManagerInterface; +use Zend_Mail; +use Zend_Mail_Exception; class GigyaCronHelper extends AbstractHelper { @@ -95,7 +97,7 @@ public function getCustomersByAttributeValue($attributeCode, $value): array * @param $attributeCode * @param $value * - * @return CustomerInterface + * @return CustomerInterface|null * * @throws LocalizedException */ @@ -169,7 +171,7 @@ public function sendEmail($job_type, $job_status, $email_to, $processed_items = } /* Generic email sender init */ - $email_sender = new \Zend_Mail(); + $email_sender = new Zend_Mail(); /* Set email body */ $email_body = $custom_email_body; @@ -196,7 +198,7 @@ public function sendEmail($job_type, $job_status, $email_to, $processed_items = $email_sender->send(); $this->logger->info($job_type . ' cron: mail sent to: ' . implode(', ', $email_to) . ' with status ' . $job_status); - } catch (\Zend_Mail_Exception $e) { + } catch (Zend_Mail_Exception $e) { $this->logger->warning($job_type . ' cron: unable to send email: ' . $e->getMessage()); return false; } diff --git a/Helper/GigyaMageHelper.php b/Helper/GigyaMageHelper.php index 419c5cd..ade3287 100644 --- a/Helper/GigyaMageHelper.php +++ b/Helper/GigyaMageHelper.php @@ -8,6 +8,7 @@ use Firebase\JWT\JWT; use Gigya\GigyaIM\Api\GigyaAccountServiceInterface; use Gigya\GigyaIM\Helper\CmsStarterKit\GSApiException; +use Gigya\GigyaIM\Model\Config\Source\Domain; use Gigya\PHP\GSException; use Gigya\PHP\SigUtils; use Gigya\GigyaIM\Helper\CmsStarterKit\user\GigyaUser; @@ -18,6 +19,7 @@ use Gigya\GigyaIM\Model\SettingsFactory; use Gigya\GigyaIM\Encryption\Encryptor; use Magento\Customer\Api\Data\CustomerInterface; +use Magento\Framework\App\ObjectManager; use Magento\Store\Model\ScopeInterface; use Magento\Framework\App\Helper\AbstractHelper; use Magento\Framework\App\Helper\Context; @@ -27,7 +29,7 @@ class GigyaMageHelper extends AbstractHelper { - const MODULE_NAME = 'Gigya_GigyaIM'; + const string MODULE_NAME = 'Gigya_GigyaIM'; private string $extra_profile_fields_config = "https://s3.amazonaws.com/gigya-cms-configs/extraProfileFieldsMap.json"; private mixed $apiKey; @@ -40,8 +42,8 @@ class GigyaMageHelper extends AbstractHelper private string $privateKey; private string $appSecret; - /** @var GigyaApiHelper */ - protected GigyaApiHelper $gigyaApiHelper; + /** @var GigyaApiHelper|null */ + protected GigyaApiHelper|null $gigyaApiHelper = null; protected mixed $configSettings; protected ModuleListInterface $_moduleList; protected Config $configModel; @@ -57,10 +59,10 @@ class GigyaMageHelper extends AbstractHelper protected Encryptor $encryptor; protected Dir $dir; - const CHARS_PASSWORD_LOWERS = 'abcdefghjkmnpqrstuvwxyz'; - const CHARS_PASSWORD_UPPERS = 'ABCDEFGHJKLMNPQRSTUVWXYZ'; - const CHARS_PASSWORD_DIGITS = '23456789'; - const CHARS_PASSWORD_SPECIALS = '!$*-.=?@_'; + const string CHARS_PASSWORD_LOWERS = 'abcdefghjkmnpqrstuvwxyz'; + const string CHARS_PASSWORD_UPPERS = 'ABCDEFGHJKLMNPQRSTUVWXYZ'; + const string CHARS_PASSWORD_DIGITS = '23456789'; + const string CHARS_PASSWORD_SPECIALS = '!$*-.=?@_'; /** * GigyaMageHelper constructor. @@ -98,6 +100,13 @@ public function __construct( $this->dir = $dir; $this->setGigyaSettings(); + + try { + $authKey = ($this->authMode == 'user_rsa') ? $this->getPrivateKey() : $this->getAppSecret(); + $this->gigyaApiHelper = new GigyaApiHelper($this->apiKey, $this->appKey, $authKey, $this->apiDomain, $this->dir, $this->authMode); + } catch (Exception $e) { +// return false; + } } /** @@ -243,7 +252,7 @@ public function setGigyaSettings( $this->encryptor->initEncryptor($scopeType, $scopeCode, $keyFileLocation); - if ($settings['domain'] == \Gigya\GigyaIM\Model\Config\Source\Domain::OTHER) { + if ($settings['domain'] == Domain::OTHER) { $this->apiDomain = $settings['data_center_host']; } else { $this->apiDomain = $settings['domain']; @@ -285,7 +294,7 @@ public function getGigyaApiHelper(): GigyaApiHelper|false protected function createEnvironmentParam(): array { // get Magento version - $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); + $objectManager = ObjectManager::getInstance(); $productMetadata = $objectManager->get('Magento\Framework\App\ProductMetadataInterface'); $magento_version = $productMetadata->getVersion(); diff --git a/Helper/GigyaScriptHelper.php b/Helper/GigyaScriptHelper.php index 6c01442..b261d69 100644 --- a/Helper/GigyaScriptHelper.php +++ b/Helper/GigyaScriptHelper.php @@ -4,7 +4,6 @@ */ namespace Gigya\GigyaIM\Helper; -use Gigya\GigyaIM\Model\Config\Source\Domain; use Magento\Framework\App\Helper\AbstractHelper; use Magento\Framework\App\Helper\Context; @@ -13,10 +12,10 @@ class GigyaScriptHelper extends AbstractHelper /** * @var GigyaMageHelper */ - public $gigyaMageHelper; + public GigyaMageHelper $gigyaMageHelper; /** - * @param \Magento\Framework\App\Helper\Context $context + * @param Context $context * @param GigyaMageHelper $gigyaMageHelper */ public function __construct( diff --git a/Helper/GigyaSyncHelper.php b/Helper/GigyaSyncHelper.php index 194775b..dc03dce 100644 --- a/Helper/GigyaSyncHelper.php +++ b/Helper/GigyaSyncHelper.php @@ -14,6 +14,7 @@ use Magento\Framework\App\Area; use Magento\Framework\App\Helper\AbstractHelper; use Magento\Framework\App\Helper\Context as HelperContext; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Message\ManagerInterface as MessageManager; use Magento\Customer\Api\CustomerRepositoryInterface; @@ -22,14 +23,14 @@ class GigyaSyncHelper extends AbstractHelper { - const DIR_BOTH = 'both'; - const DIR_G2CMS = 'g2cms'; - const DIR_CMS2G = 'cms2g'; + const string DIR_BOTH = 'both'; + const string DIR_G2CMS = 'g2cms'; + const string DIR_CMS2G = 'cms2g'; /** * @var array */ - protected static $customerIdsExcludedFromSync = [ self::DIR_CMS2G => [], self::DIR_G2CMS => [] ]; + protected static array $customerIdsExcludedFromSync = [ self::DIR_CMS2G => [], self::DIR_G2CMS => [] ]; /** * @var MessageManager @@ -285,13 +286,13 @@ public function updateMagentoCustomerDataWithSessionGigyaAccount($magentoCustome * @return CustomerInterface The Magento customer linked with this Gigya account (can be null if no account exists yet) * @throws @see getMagentoCustomerAndLoggingEmail() */ - public function setMagentoLoggingContext($gigyaAccount): CustomerInterface + public function setMagentoLoggingContext($gigyaAccount): CustomerInterface | null { // This value will be set with the preferred email that should be attached with the Magento customer account, among all the Gigya loginIDs emails // We initialize it to null. If it's still null at the end of the algorithm that means that the user can not logged in // because all Gigya loginIDs emails are already set to existing Magento customer accounts with a different or null Gigya UID // Using Object manager in order to fix the di compilation issue - $om = \Magento\Framework\App\ObjectManager::getInstance(); + $om = ObjectManager::getInstance(); $session = $om->get('Magento\Customer\Model\Session'); $session->setGigyaAccountLoggingEmail(null); diff --git a/Helper/RetryGigyaSyncHelper.php b/Helper/RetryGigyaSyncHelper.php index 6c8c3d0..e96862d 100644 --- a/Helper/RetryGigyaSyncHelper.php +++ b/Helper/RetryGigyaSyncHelper.php @@ -2,6 +2,7 @@ namespace Gigya\GigyaIM\Helper; +use Exception; use Gigya\GigyaIM\Exception\RetryGigyaException; use Magento\Framework\Api\FilterBuilder; use Magento\Framework\Api\Search\FilterGroupBuilder; @@ -21,6 +22,8 @@ use Magento\Framework\DB\Adapter\AdapterInterface; use Magento\Framework\App\Area; use Magento\Customer\Model\Config\Share; +use Zend_Db; +use Zend_Db_Select; /** * RetryGigyaSyncHelper @@ -35,11 +38,11 @@ class RetryGigyaSyncHelper extends GigyaSyncHelper /** * Denotes a retry entry created after an update failure on Gigya service */ - const ORIGIN_GIGYA = 'gigya'; + const string ORIGIN_GIGYA = 'gigya'; /** * Denotes a retry entry created after an update failure on Magento */ - const ORIGIN_CMS = 'cms'; + const string ORIGIN_CMS = 'cms'; /** @var GigyaLogger */ protected GigyaLogger $logger; @@ -203,11 +206,11 @@ public function getCurrentRetryCount($origin, $customerEntityId): int $selectRetryRows = $this->connection ->select() ->from($this->resourceConnection->getTableName('gigya_sync_retry')) - ->reset(\Zend_Db_Select::COLUMNS) + ->reset(Zend_Db_Select::COLUMNS) ->columns('retry_count') ->where($where); - $retryRows = $this->connection->fetchAll($selectRetryRows, [], \Zend_Db::FETCH_ASSOC); + $retryRows = $this->connection->fetchAll($selectRetryRows, [], Zend_Db::FETCH_ASSOC); if (empty($retryRows)) { return -1; @@ -259,14 +262,14 @@ public function getRetryEntries($origin, $uid = null, $getGigyaData = false): ar $selectRetryRows = $this->connection ->select() ->from($this->resourceConnection->getTableName('gigya_sync_retry')) - ->reset(\Zend_Db_Select::COLUMNS) + ->reset(Zend_Db_Select::COLUMNS) ->columns($columns); if (!is_null($where)) { $selectRetryRows = $selectRetryRows->where($where); } - return $this->connection->fetchAll($selectRetryRows, [], \Zend_Db::FETCH_ASSOC); + return $this->connection->fetchAll($selectRetryRows, [], Zend_Db::FETCH_ASSOC); } /** @@ -408,7 +411,7 @@ public function deleteRetryEntry( ['customer_entity_id' => $customerEntityId] ); } - } catch (\Exception $e) { + } catch (Exception $e) { $this->connection->rollBack(); if (!is_null($failureMessage)) { $this->logger->critical( @@ -470,7 +473,7 @@ public function scheduleRetry($origin, $customerEntityId, $customerEntityEmail, } else { try { $areaCode = $this->appState->getAreaCode(); - } catch (\Magento\Framework\Exception\LocalizedException $e) { + } catch (LocalizedException $e) { $areaCode = null; } @@ -501,7 +504,7 @@ public function scheduleRetry($origin, $customerEntityId, $customerEntityEmail, } $this->commit(); - } catch (\Exception $e) { + } catch (Exception $e) { $this->rollBack(); $this->logger->critical( 'Could not log retry entry for '.$origin.'. No automatic retry will be performed on it.', diff --git a/Model/Cache/Type/FieldMapping.php b/Model/Cache/Type/FieldMapping.php index 304800f..0481161 100644 --- a/Model/Cache/Type/FieldMapping.php +++ b/Model/Cache/Type/FieldMapping.php @@ -1,25 +1,28 @@ get(self::TYPE_IDENTIFIER), self::CACHE_TAG); } diff --git a/Model/Config.php b/Model/Config.php index 92d6fab..60cf52d 100644 --- a/Model/Config.php +++ b/Model/Config.php @@ -17,32 +17,32 @@ class Config { // Session duration will be fixed by config - const SESSION_MODE_FIXED = 0; + const int SESSION_MODE_FIXED = 0; // Session duration is 60 secs; automatically renewed on any user action - const SESSION_MODE_EXTENDED = 1; + const int SESSION_MODE_EXTENDED = 1; // Session close when browser close - const SESSION_MODE_BROWSER_INSTANCE = 2; + const int SESSION_MODE_BROWSER_INSTANCE = 2; // Session never close even when browser close - const SESSION_MODE_ENDLESS = 3; + const int SESSION_MODE_ENDLESS = 3; - const XML_PATH_SESSION_MODE = 'gigya_session/session/mode'; - const XML_PATH_SESSION_EXPIRATION = 'gigya_session/session/expiration'; + const string XML_PATH_SESSION_MODE = 'gigya_session/session/mode'; + const string XML_PATH_SESSION_EXPIRATION = 'gigya_session/session/expiration'; - const XML_PATH_REMEMBER_MODE = 'gigya_session/remember/mode'; - const XML_PATH_REMEMBER_EXPIRATION = 'gigya_session/remember/expiration'; + const string XML_PATH_REMEMBER_MODE = 'gigya_session/remember/mode'; + const string XML_PATH_REMEMBER_EXPIRATION = 'gigya_session/remember/expiration'; - const XML_PATH_MAPPING_FILE_PATH = 'gigya_section_fieldmapping/general_fieldmapping/mapping_file_path'; + const string XML_PATH_MAPPING_FILE_PATH = 'gigya_section_fieldmapping/general_fieldmapping/mapping_file_path'; - const XML_PATH_GENERAL = 'gigya_section/general'; + const string XML_PATH_GENERAL = 'gigya_section/general'; - const XML_PATH_DEBUG_MODE = 'gigya_advanced/debug_mode/debug_mode'; + const string XML_PATH_DEBUG_MODE = 'gigya_advanced/debug_mode/debug_mode'; // Screen-sets configuration - const XML_PATH_LOGIN_DESKTOP_SCREENSET_ID = 'gigya_screensets/login_registration/desktop_screenset_id'; - const XML_PATH_LOGIN_MOBILE_SCREENSET_ID = 'gigya_screensets/login_registration/mobile_screenset_id'; - const XML_PATH_PROFILE_DESKTOP_SCREENSET_ID = 'gigya_screensets/profile_update/desktop_screenset_id'; - const XML_PATH_PROFILE_MOBILE_SCREENSET_ID = 'gigya_screensets/profile_update/mobile_screenset_id'; - const XML_PATH_PROFILE_CUSTOM_SCREENSETS = 'gigya_screensets/custom_screensets/custom_screenset_dynamic'; + const string XML_PATH_LOGIN_DESKTOP_SCREENSET_ID = 'gigya_screensets/login_registration/desktop_screenset_id'; + const string XML_PATH_LOGIN_MOBILE_SCREENSET_ID = 'gigya_screensets/login_registration/mobile_screenset_id'; + const string XML_PATH_PROFILE_DESKTOP_SCREENSET_ID = 'gigya_screensets/profile_update/desktop_screenset_id'; + const string XML_PATH_PROFILE_MOBILE_SCREENSET_ID = 'gigya_screensets/profile_update/mobile_screenset_id'; + const string XML_PATH_PROFILE_CUSTOM_SCREENSETS = 'gigya_screensets/custom_screensets/custom_screenset_dynamic'; /** * @var ScopeConfigInterface diff --git a/Model/Config/Backend/AppSecret.php b/Model/Config/Backend/AppSecret.php index e9ccdb3..603aa59 100644 --- a/Model/Config/Backend/AppSecret.php +++ b/Model/Config/Backend/AppSecret.php @@ -17,13 +17,13 @@ class AppSecret extends Encrypted private Encryptor $encryptor; /** - * @param \Magento\Framework\Model\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\App\Config\ScopeConfigInterface $config - * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList - * @param \Gigya\GigyaIM\Encryption\Encryptor $encryptor - * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource - * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection + * @param Context $context + * @param Registry $registry + * @param ScopeConfigInterface $config + * @param TypeListInterface $cacheTypeList + * @param Encryptor $encryptor + * @param AbstractResource $resource + * @param AbstractDb $resourceCollection * @param array $data */ public function __construct( @@ -80,7 +80,6 @@ protected function _afterLoad() { $this->initEncryptor(); parent::_afterLoad(); - ; } /** diff --git a/Model/Config/Backend/KeyFileLocation.php b/Model/Config/Backend/KeyFileLocation.php index 32619da..42dc9b6 100644 --- a/Model/Config/Backend/KeyFileLocation.php +++ b/Model/Config/Backend/KeyFileLocation.php @@ -2,12 +2,18 @@ namespace Gigya\GigyaIM\Model\Config\Backend; +use Magento\Framework\App\Cache\TypeListInterface; use Magento\Framework\App\Config\ScopeConfigInterface; use Gigya\GigyaIM\Helper\GigyaEncryptorHelper; +use Magento\Framework\App\Config\Value; +use Magento\Framework\Data\Collection\AbstractDb; use Magento\Framework\Exception\FileSystemException; use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Model\Context; +use Magento\Framework\Model\ResourceModel\AbstractResource; +use Magento\Framework\Registry; -class KeyFileLocation extends \Magento\Framework\App\Config\Value +class KeyFileLocation extends Value { /** * @var GigyaEncryptorHelper @@ -16,23 +22,23 @@ class KeyFileLocation extends \Magento\Framework\App\Config\Value /** * @param GigyaEncryptorHelper $gigyaEncryptorHelper - * @param \Magento\Framework\Model\Context $context - * @param \Magento\Framework\Registry $registry + * @param Context $context + * @param Registry $registry * @param ScopeConfigInterface $config - * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList - * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource - * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection + * @param TypeListInterface $cacheTypeList + * @param AbstractResource|null $resource + * @param AbstractDb|null $resourceCollection * @param array $data */ public function __construct( GigyaEncryptorHelper $gigyaEncryptorHelper, - \Magento\Framework\Model\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Framework\App\Config\ScopeConfigInterface $config, - \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, - \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, - \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [] + Context $context, + Registry $registry, + ScopeConfigInterface $config, + TypeListInterface $cacheTypeList, + AbstractResource $resource = null, + AbstractDb $resourceCollection = null, + array $data = [] ) { parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data); @@ -40,9 +46,9 @@ public function __construct( } /** - * @return \Gigya\GigyaIM\Model\Config\Backend\KeyFileLocation + * @return KeyFileLocation * - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ public function beforeSave() { diff --git a/Model/Config/Source/DeletionNotFoundBehavior.php b/Model/Config/Source/DeletionNotFoundBehavior.php index f7c0d8b..6300d5f 100644 --- a/Model/Config/Source/DeletionNotFoundBehavior.php +++ b/Model/Config/Source/DeletionNotFoundBehavior.php @@ -6,8 +6,8 @@ class DeletionNotFoundBehavior implements OptionSourceInterface { - const FAILURE = "failure"; - const SUCCESS = "success"; + const string FAILURE = "failure"; + const string SUCCESS = "success"; /** * @return array diff --git a/Model/Config/Source/DeletionType.php b/Model/Config/Source/DeletionType.php index 4d9ef57..4377fe5 100644 --- a/Model/Config/Source/DeletionType.php +++ b/Model/Config/Source/DeletionType.php @@ -6,8 +6,8 @@ class DeletionType implements OptionSourceInterface { - const HARD_DELETE = "hard_delete"; - const SOFT_DELETE = "soft_delete"; + const string HARD_DELETE = "hard_delete"; + const string SOFT_DELETE = "soft_delete"; /** * @return array diff --git a/Model/Config/Source/Domain.php b/Model/Config/Source/Domain.php index 4ed77e8..addddbb 100644 --- a/Model/Config/Source/Domain.php +++ b/Model/Config/Source/Domain.php @@ -6,12 +6,12 @@ class Domain implements OptionSourceInterface { - const DC_US = "us1.gigya.com"; - const DC_EU = "eu1.gigya.com"; - const DC_AU = "au1.gigya.com"; - const DC_RU = "ru1.gigya.com"; - const DC_CN = "cn1.gigya-api.cn"; - const OTHER = "other"; + const string DC_US = "us1.gigya.com"; + const string DC_EU = "eu1.gigya.com"; + const string DC_AU = "au1.gigya.com"; + const string DC_RU = "ru1.gigya.com"; + const string DC_CN = "cn1.gigya-api.cn"; + const string OTHER = "other"; /** * @return array diff --git a/Model/Config/Source/SessionMode.php b/Model/Config/Source/SessionMode.php index c578f01..2d747dc 100644 --- a/Model/Config/Source/SessionMode.php +++ b/Model/Config/Source/SessionMode.php @@ -2,6 +2,7 @@ namespace Gigya\GigyaIM\Model\Config\Source; +use Gigya\GigyaIM\Model\Config; use Magento\Framework\Data\OptionSourceInterface; class SessionMode implements OptionSourceInterface @@ -14,10 +15,10 @@ class SessionMode implements OptionSourceInterface public function toOptionArray() { return [ - ['value' => \Gigya\GigyaIM\Model\Config::SESSION_MODE_FIXED, 'label' => __('Fixed')], - ['value' => \Gigya\GigyaIM\Model\Config::SESSION_MODE_EXTENDED, 'label' => __('Extended')], - ['value' => \Gigya\GigyaIM\Model\Config::SESSION_MODE_BROWSER_INSTANCE, 'label' => __('Browser instance')], - ['value' => \Gigya\GigyaIM\Model\Config::SESSION_MODE_ENDLESS, 'label' => __('Endless')] + ['value' => Config::SESSION_MODE_FIXED, 'label' => __('Fixed')], + ['value' => Config::SESSION_MODE_EXTENDED, 'label' => __('Extended')], + ['value' => Config::SESSION_MODE_BROWSER_INSTANCE, 'label' => __('Browser instance')], + ['value' => Config::SESSION_MODE_ENDLESS, 'label' => __('Endless')] ]; } } diff --git a/Model/Config/ValidateAWSDetails.php b/Model/Config/ValidateAWSDetails.php index 0b95624..acfda49 100644 --- a/Model/Config/ValidateAWSDetails.php +++ b/Model/Config/ValidateAWSDetails.php @@ -6,19 +6,29 @@ use Aws\S3\Exception\S3Exception; use Aws\S3\S3Client; +use Gigya\GigyaIM\Helper\GigyaMageHelper; +use Magento\Customer\Model\ResourceModel\Customer; +use Magento\Framework\App\Cache\TypeListInterface; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\Config\Value; +use Magento\Framework\Data\Collection\AbstractDb; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Encryption\EncryptorInterface; use Gigya\GigyaIM\Logger\Logger as GigyaLogger; +use Magento\Framework\Model\Context; +use Magento\Framework\Model\ResourceModel\AbstractResource; +use Magento\Framework\Registry; +use Magento\Store\Model\StoreManagerInterface; -class ValidateAWSDetails extends \Magento\Framework\App\Config\Value +class ValidateAWSDetails extends Value { - /** @var \Magento\Customer\Model\ResourceModel\Customer */ + /** @var Customer */ protected $_customerResource; - /** @var \Magento\Store\Model\StoreManagerInterface */ + /** @var StoreManagerInterface */ protected $_storeManager; - /** @var \Gigya\GigyaIM\Helper\GigyaMageHelper */ + /** @var GigyaMageHelper */ protected $gigyaMageHelper; /** @var EncryptorInterface */ @@ -30,31 +40,31 @@ class ValidateAWSDetails extends \Magento\Framework\App\Config\Value /** * Constructor * - * @param \Magento\Framework\Model\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\App\Config\ScopeConfigInterface $config - * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList - * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param \Magento\Customer\Model\ResourceModel\Customer $customerResource - * @param \Gigya\GigyaIM\Helper\GigyaMageHelper $gigyaMageHelper + * @param Context $context + * @param Registry $registry + * @param ScopeConfigInterface $config + * @param TypeListInterface $cacheTypeList + * @param StoreManagerInterface $storeManager + * @param Customer $customerResource + * @param GigyaMageHelper $gigyaMageHelper * @param EncryptorInterface $encryptor * @param GigyaLogger $logger - * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource - * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection + * @param AbstractResource $resource + * @param AbstractDb $resourceCollection * @param array $data */ public function __construct( - \Magento\Framework\Model\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Framework\App\Config\ScopeConfigInterface $config, - \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, - \Magento\Store\Model\StoreManagerInterface $storeManager, - \Magento\Customer\Model\ResourceModel\Customer $customerResource, - \Gigya\GigyaIM\Helper\GigyaMageHelper $gigyaMageHelper, + Context $context, + Registry $registry, + ScopeConfigInterface $config, + TypeListInterface $cacheTypeList, + StoreManagerInterface $storeManager, + Customer $customerResource, + GigyaMageHelper $gigyaMageHelper, EncryptorInterface $encryptor, GigyaLogger $logger, - \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, - \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, + AbstractResource $resource = null, + AbstractDb $resourceCollection = null, array $data = [] ) { $this->_storeManager = $storeManager; @@ -71,7 +81,7 @@ public function __construct( * * @return $this * - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ public function beforeSave() { diff --git a/Model/Config/ValidateFieldMappingConf.php b/Model/Config/ValidateFieldMappingConf.php index dc7b888..b571217 100644 --- a/Model/Config/ValidateFieldMappingConf.php +++ b/Model/Config/ValidateFieldMappingConf.php @@ -2,15 +2,25 @@ namespace Gigya\GigyaIM\Model\Config; +use Gigya\GigyaIM\Helper\GigyaMageHelper; +use Magento\Customer\Model\ResourceModel\Customer; +use Magento\Framework\App\Cache\TypeListInterface; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\Config\Value; +use Magento\Framework\Data\Collection\AbstractDb; use Magento\Framework\Exception\LocalizedException; use Gigya\GigyaIM\Logger\Logger as GigyaLogger; +use Magento\Framework\Model\Context; +use Magento\Framework\Model\ResourceModel\AbstractResource; +use Magento\Framework\Registry; +use Magento\Store\Model\StoreManagerInterface; /** * Customer sharing config model * * @author Magento Core Team */ -class ValidateFieldMappingConf extends \Magento\Framework\App\Config\Value +class ValidateFieldMappingConf extends Value { /** * @var GigyaLogger @@ -20,28 +30,29 @@ class ValidateFieldMappingConf extends \Magento\Framework\App\Config\Value /** * Constructor * - * @param \Magento\Framework\Model\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\App\Config\ScopeConfigInterface $config - * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList - * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param \Magento\Customer\Model\ResourceModel\Customer $customerResource + * @param Context $context + * @param Registry $registry + * @param ScopeConfigInterface $config + * @param TypeListInterface $cacheTypeList + * @param StoreManagerInterface $storeManager + * @param Customer $customerResource + * @param GigyaMageHelper $gigyaMageHelper * @param GigyaLogger $logger - * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource - * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection + * @param AbstractResource|null $resource + * @param AbstractDb|null $resourceCollection * @param array $data */ public function __construct( - \Magento\Framework\Model\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Framework\App\Config\ScopeConfigInterface $config, - \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, - \Magento\Store\Model\StoreManagerInterface $storeManager, - \Magento\Customer\Model\ResourceModel\Customer $customerResource, - \Gigya\GigyaIM\Helper\GigyaMageHelper $gigyaMageHelper, + Context $context, + Registry $registry, + ScopeConfigInterface $config, + TypeListInterface $cacheTypeList, + StoreManagerInterface $storeManager, + Customer $customerResource, + GigyaMageHelper $gigyaMageHelper, GigyaLogger $logger, - \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, - \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, + AbstractResource $resource = null, + AbstractDb $resourceCollection = null, array $data = [] ) { $this->logger = $logger; @@ -52,7 +63,7 @@ public function __construct( /** * @return $this * - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ public function beforeSave() { diff --git a/Model/Cron/GigyaOfflineSync.php b/Model/Cron/GigyaOfflineSync.php index caa9826..432856d 100644 --- a/Model/Cron/GigyaOfflineSync.php +++ b/Model/Cron/GigyaOfflineSync.php @@ -2,6 +2,7 @@ namespace Gigya\GigyaIM\Model\Cron; +use Exception; use Gigya\GigyaIM\Helper\CmsStarterKit\fieldMapping\FieldMappingException; use Gigya\GigyaIM\Helper\CmsStarterKit\GigyaApiHelper; use Gigya\GigyaIM\Helper\GigyaCronHelper; @@ -97,7 +98,7 @@ public function __construct( /** * @param string $gigyaQuery - * @param \Exception &$gigyaException + * @param Exception &$gigyaException * @param int $triesLeft * * @return array|false @@ -112,7 +113,7 @@ public function searchGigyaUsers($gigyaQuery, &$gigyaException, $triesLeft = 1) $gigyaUsers = $this->gigyaApiHelper->searchGigyaUsers($gigyaQuery, true); return $gigyaUsers; - } catch (\Exception $e) { + } catch (Exception $e) { sleep(self::RETRY_WAIT); $gigyaException = ['message' => $e->getMessage(), 'code' => $e->getCode()]; return $this->searchGigyaUsers($gigyaQuery, $gigyaException, $triesLeft - 1); @@ -156,7 +157,7 @@ public function execute() $gigyaUsers = $this->searchGigyaUsers($gigyaQuery, $gigyaException, 3); if ($gigyaUsers === false) { $this->handleError($gigyaException['message'], $emailsOnFailure, $processedUsers, $usersNotFound); - throw new \Exception($gigyaException['message'], $gigyaException['code']); + throw new Exception($gigyaException['message'], $gigyaException['code']); } foreach ($gigyaUsers as $gigyaUser) { @@ -165,14 +166,14 @@ public function execute() if (empty($gigyaUID)) { $message = 'User with the following data does not have a UID. Unable to process. ' . json_encode($gigyaUser); $this->handleError($message, $emailsOnFailure, $processedUsers, $usersNotFound); - throw new \Exception($message); + throw new Exception($message); } /* Abort if user does not have a valid lastUpdatedTimestamp */ if (empty($gigyaUser->getLastUpdatedTimestamp())) { $message = 'User ' . $gigyaUID . ' does not have a valid last updated timestamp'; $this->handleError($message, $emailsOnFailure, $processedUsers, $usersNotFound); - throw new \Exception($message); + throw new Exception($message); } /* Run sync (field mapping) */ @@ -190,7 +191,7 @@ public function execute() } $processedUsers++; - } catch (\Exception $e) { + } catch (Exception $e) { $message = 'Error syncing user. Gigya UID: ' . $gigyaUID; $this->handleError($message, $emailsOnFailure, $processedUsers, $usersNotFound); throw new FieldMappingException($message); @@ -207,7 +208,7 @@ public function execute() $this->logger->info(self::CRON_NAME . ' completed. Users processed: ' . $processedUsers . (($usersNotFound) ? '. Users not found: ' . $usersNotFound : '')); $status = ($usersNotFound > 0) ? 'completed with errors' : 'succeeded'; $this->gigyaCronHelper->sendEmail(self::CRON_NAME, $status, $emailsOnSuccess, $processedUsers, $usersNotFound); - } catch (\Exception $e) { + } catch (Exception $e) { $this->handleError($e->getMessage(), $emailsOnFailure, $processedUsers, $usersNotFound); $this->logger->error('Error on cron ' . self::CRON_NAME . ': ' . $e->getMessage() . '.'); } diff --git a/Model/Cron/RetryGigyaUpdate.php b/Model/Cron/RetryGigyaUpdate.php index 61dfbe9..d4120b0 100644 --- a/Model/Cron/RetryGigyaUpdate.php +++ b/Model/Cron/RetryGigyaUpdate.php @@ -2,12 +2,16 @@ namespace Gigya\GigyaIM\Model\Cron; +use Gigya\GigyaIM\Exception\RetryGigyaException; use Gigya\GigyaIM\Helper\RetryGigyaSyncHelper; use Gigya\GigyaIM\Logger\Logger as GigyaLogger; use Gigya\GigyaIM\Model\Config as GigyaConfig; +use Magento\Cron\Model\Schedule; use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Customer\Api\Data\CustomerInterface; -use \Magento\Framework\Event\ManagerInterface as EventManager; +use Magento\Framework\Event\ManagerInterface as EventManager; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Exception\NoSuchEntityException; /** * RetryGigyaUpdate @@ -56,13 +60,13 @@ public function __construct( /** * For all scheduled retry entries will perform a Gigya & Magento update on the corresponding accounts & Customer entities. * - * @param \Magento\Cron\Model\Schedule $schedule + * @param Schedule $schedule * - * @throws \Gigya\GigyaIM\Exception\RetryGigyaException - * @throws \Magento\Framework\Exception\LocalizedException - * @throws \Magento\Framework\Exception\NoSuchEntityException + * @throws RetryGigyaException + * @throws LocalizedException + * @throws NoSuchEntityException */ - public function execute(\Magento\Cron\Model\Schedule $schedule=null) + public function execute(Schedule $schedule=null) { if ($this->config->isGigyaEnabled()) { $allRetriesRow = $this->retryGigyaSyncHelper->getRetryEntries(null); diff --git a/Model/FieldMapping/AbstractFieldMapping.php b/Model/FieldMapping/AbstractFieldMapping.php index 9bb9c2a..821bdce 100644 --- a/Model/FieldMapping/AbstractFieldMapping.php +++ b/Model/FieldMapping/AbstractFieldMapping.php @@ -2,7 +2,7 @@ namespace Gigya\GigyaIM\Model\FieldMapping; -use \Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Module\Dir; use Magento\Framework\Module\Dir\Reader as ModuleDirReader; use Gigya\GigyaIM\Logger\Logger as GigyaLogger; diff --git a/Model/FieldMapping/GigyaFromMagento.php b/Model/FieldMapping/GigyaFromMagento.php index e6c74a1..3965050 100644 --- a/Model/FieldMapping/GigyaFromMagento.php +++ b/Model/FieldMapping/GigyaFromMagento.php @@ -2,12 +2,14 @@ namespace Gigya\GigyaIM\Model\FieldMapping; +use Exception; use Gigya\GigyaIM\Helper\CmsStarterKit\GSApiException; use Magento\Customer\Model\Data\Customer; use Gigya\GigyaIM\Helper\CmsStarterKit\user\GigyaUser; use Gigya\GigyaIM\Exception\GigyaFieldMappingException; use Gigya\GigyaIM\Model\GigyaCustomerFieldsUpdater; -use \Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\Api\AttributeInterface; +use Magento\Framework\App\Config\ScopeConfigInterface; use Gigya\GigyaIM\Logger\Logger as GigyaLogger; use Magento\Framework\Module\Dir\Reader as ModuleDirReader; @@ -19,7 +21,7 @@ class GigyaFromMagento extends AbstractFieldMapping { /** - * @var \Gigya\GigyaIM\Model\GigyaCustomerFieldsUpdater + * @var GigyaCustomerFieldsUpdater */ protected $customerFieldsUpdater; @@ -46,7 +48,7 @@ public function __construct( /** * @param $isGigyaException - * @param \Exception|GSApiException $exception + * @param Exception|GSApiException $exception * * @throws GigyaFieldMappingException */ @@ -89,7 +91,7 @@ public function run($customer, $gigyaUser) $this->customerFieldsUpdater->updateGigya(); } catch (GSApiException $e) { $this->handleExceptions(true, $e); - } catch (\Exception $e) { + } catch (Exception $e) { $this->handleExceptions(false, $e); } } else { @@ -106,7 +108,7 @@ public function run($customer, $gigyaUser) /** * Get magento custom attribute user override by observer DefaultGigyaSyncFieldMapping - * @return \Magento\Framework\Api\AttributeInterface[]|null + * @return AttributeInterface[]|null */ public function getMagentoUserObserver() { diff --git a/Model/GigyaAccountService.php b/Model/GigyaAccountService.php index 91774a4..8a9efe6 100644 --- a/Model/GigyaAccountService.php +++ b/Model/GigyaAccountService.php @@ -9,8 +9,8 @@ use Gigya\GigyaIM\Helper\CmsStarterKit\user\GigyaSubscriptionContainer; use Gigya\GigyaIM\Api\GigyaAccountServiceInterface; use Gigya\GigyaIM\Helper\GigyaMageHelper; -use \Magento\Framework\Event\ManagerInterface as EventManager; -use \Gigya\GigyaIM\Logger\Logger as GigyaLogger; +use Magento\Framework\Event\ManagerInterface as EventManager; +use Gigya\GigyaIM\Logger\Logger as GigyaLogger; /** * GigyaAccountService @@ -31,12 +31,12 @@ class GigyaAccountService implements GigyaAccountServiceInterface /** * Event dispatched when the Gigya data have correctly been sent to the Gigya remote service. */ - const EVENT_UPDATE_GIGYA_SUCCESS = 'gigya_success_sync_to_gigya'; + const string EVENT_UPDATE_GIGYA_SUCCESS = 'gigya_success_sync_to_gigya'; /** * Event dispatched when the Gigya data could not be sent to the Gigya remote service or when this service replies with an error (validation or other functionnal error) */ - const EVENT_UPDATE_GIGYA_FAILURE = 'gigya_failed_sync_to_gigya'; + const string EVENT_UPDATE_GIGYA_FAILURE = 'gigya_failed_sync_to_gigya'; /** @var GigyaMageHelper */ protected GigyaMageHelper $gigyaMageHelper; @@ -229,7 +229,7 @@ function ($value, $key) { * * @throws GSException */ - public function update(GigyaUser $gigyaAccount) + public function update(GigyaUser $gigyaAccount, $dispatchEvent = true) { $result = null; $gigyaApiData = self::getGigyaApiAccountData($gigyaAccount); diff --git a/Model/GigyaCustomerFieldsUpdater.php b/Model/GigyaCustomerFieldsUpdater.php index 1908156..df7c242 100644 --- a/Model/GigyaCustomerFieldsUpdater.php +++ b/Model/GigyaCustomerFieldsUpdater.php @@ -2,12 +2,14 @@ namespace Gigya\GigyaIM\Model; +use Exception; use Gigya\GigyaIM\Helper\CmsStarterKit\fieldMapping; use Gigya\GigyaIM\Helper\CmsStarterKit\user\GigyaSubscription; use Gigya\GigyaIM\Helper\CmsStarterKit\user\GigyaUser; use Gigya\GigyaIM\Exception\GigyaFieldMappingException; use Gigya\GigyaIM\Helper\GigyaMageHelper; use Gigya\GigyaIM\Model\Cache\Type\FieldMapping as CacheType; +use Magento\Customer\Model\Address; use Magento\Framework\Event\ManagerInterface as EventManagerInterface; use Magento\Newsletter\Model\Subscriber; use Gigya\GigyaIM\Logger\Logger as GigyaLogger; @@ -212,7 +214,7 @@ public function getValueFromMagentoCustomer($cmsName) $methodParams = strtolower($subPath); $value = call_user_func([$magentoUser, $methodName], $methodParams); if ($value == null) { - throw new \Exception('Custom attribute '.$subPath.' is not set'); + throw new Exception('Custom attribute '.$subPath.' is not set'); } /* Value is of type AttributeValue */ @@ -224,7 +226,7 @@ public function getValueFromMagentoCustomer($cmsName) $subPath = substr($subPath, 8); $param0 = null; - /** @var \Magento\Customer\Model\Address $magentoBilling */ + /** @var Address $magentoBilling */ $magentoBilling = $this->addressFactory->create(); $this->addressResourceModel->load($magentoBilling, $magentoUser->getDefaultBilling()); $methodName = 'get' . ucfirst($subPath); @@ -242,7 +244,7 @@ public function getValueFromMagentoCustomer($cmsName) $value = call_user_func([$magentoUser, $methodName]) ?: ''; } } - } catch (\Exception $e) { + } catch (Exception $e) { throw new GigyaFieldMappingException(sprintf('Field mapping Magento to Gigya : exception while looking for Customer entity value [%s] : %s', $cmsName, $e->getMessage())); } @@ -264,7 +266,7 @@ protected function retrieveFieldMappings(): void try { parent::retrieveFieldMappings(); - } catch (\Exception $e) { + } catch (Exception $e) { if (!$this->confMapping || $this->confMapping->getMappingConf() == null) { throw new GigyaFieldMappingException("Field mapping file could not be found or is empty or is not correctly formated."); } else { diff --git a/Model/MagentoCustomerFieldsUpdater.php b/Model/MagentoCustomerFieldsUpdater.php index 7dc3c70..a63695a 100644 --- a/Model/MagentoCustomerFieldsUpdater.php +++ b/Model/MagentoCustomerFieldsUpdater.php @@ -2,13 +2,16 @@ namespace Gigya\GigyaIM\Model; +use Exception; use Gigya\GigyaIM\Helper\CmsStarterKit\fieldMapping; +use Gigya\GigyaIM\Helper\CmsStarterKit\fieldMapping\ConfItem; use Gigya\GigyaIM\Helper\CmsStarterKit\user\GigyaUser; use Gigya\GigyaIM\Logger\Logger as GigyaLogger; use Gigya\GigyaIM\Model\Cache\Type\FieldMapping as CacheType; use Magento\Customer\Api\AddressRepositoryInterface; -use Magento\Customer\Api\CustomerRepositoryInterface; use Magento\Customer\Api\Data\AddressInterfaceFactory as AddressFactory; +use Magento\Customer\Model\Data\Address; +use Magento\Customer\Model\Data\Customer; use Magento\Framework\App\ObjectManager; use Magento\Framework\Event\ManagerInterface; use Magento\Framework\Event\ManagerInterface as EventManagerInterface; @@ -92,7 +95,7 @@ public function callCmsHook() } /** - * @param \Magento\Customer\Model\Data\Customer $account + * @param Customer $account */ public function setAccountValues(&$account) { @@ -101,7 +104,7 @@ public function setAccountValues(&$account) $magentoBillingAddressId = $account->getDefaultBilling(); try { $magentoBillingAddress = $this->addressRepository->getById($magentoBillingAddressId); - } catch (\Exception $ex) { + } catch (Exception $ex) { $this->logger->error($ex->__toString()); $magentoBillingAddress = false; } @@ -112,14 +115,14 @@ public function setAccountValues(&$account) if ($magentoBillingAddress === false) { $isBillingAddressNew = true; - /** @var \Magento\Customer\Model\Data\Address $magentoBillingAddress */ + /** @var Address $magentoBillingAddress */ $magentoBillingAddress = $this->addressFactory->create(); } else { $isBillingAddressNew = false; } foreach ($gigyaMapping as $gigyaName => $confs) { - /** @var \Gigya\GigyaIM\Helper\CmsStarterKit\fieldMapping\ConfItem $conf */ + /** @var ConfItem $conf */ $value = parent::getValueFromGigyaAccount($gigyaName); // e.g: loginProvider = facebook /* If no value found, log and skip field */ @@ -167,7 +170,7 @@ public function setAccountValues(&$account) $magentoBillingAddress->setCustomerId($account->getId()); - /** @var \Magento\Customer\Model\Data\Customer $account */ + /** @var Customer $account */ $this->addressRepository->save($magentoBillingAddress); $account->setDefaultBilling($magentoBillingAddress->getId()); @@ -176,13 +179,13 @@ public function setAccountValues(&$account) } $this->logger->debug("Added address {$magentoBillingAddress->getId()} to customer"); - } catch (\Exception $e) { + } catch (Exception $e) { $this->logger->debug("Failed to import customer address data: " . $e->getMessage()); } } else { try { $this->addressRepository->save($magentoBillingAddress); - } catch (\Exception $ex) { + } catch (Exception $ex) { $this->logger->error($ex->__toString()); } } @@ -220,7 +223,7 @@ public function saveCmsAccount(&$cmsAccount, $cmsAccountSaver = null) /** * @param boolean $skipCache * - * @throws \Exception + * @throws Exception */ public function retrieveFieldMappings($skipCache = false): void { @@ -234,7 +237,7 @@ public function retrieveFieldMappings($skipCache = false): void if ($mappingJson === false) { $err = error_get_last(); $message = "MagentoCustomerFieldsUpdater: Could not retrieve field mapping configuration file. The message was: " . $err['message']; - throw new \Exception("$message"); + throw new Exception("$message"); } $conf = new fieldMapping\Conf($mappingJson); diff --git a/Model/ResourceModel/ConnectionFactory.php b/Model/ResourceModel/ConnectionFactory.php index 4277c14..bdb2865 100644 --- a/Model/ResourceModel/ConnectionFactory.php +++ b/Model/ResourceModel/ConnectionFactory.php @@ -2,7 +2,11 @@ namespace Gigya\GigyaIM\Model\ResourceModel; +use DomainException; use Magento\Framework\App\ResourceConnection; +use Magento\Framework\DB\Adapter\AdapterInterface; +use Magento\Framework\Exception\FileSystemException; +use Magento\Framework\Exception\RuntimeException; use Magento\Framework\Model\ResourceModel\Type\Db\ConnectionFactoryInterface; use Magento\Framework\App\DeploymentConfig; use Magento\Framework\Config\ConfigOptionsListConstants; @@ -38,7 +42,9 @@ public function __construct( * Creates a new connection object with the same configuration as the default one. * New connections are used to inject a row in the database if a transaction fails. * - * @return \Magento\Framework\DB\Adapter\AdapterInterface + * @return AdapterInterface + * @throws FileSystemException + * @throws RuntimeException */ public function getNewConnection() { @@ -50,7 +56,7 @@ public function getNewConnection() if ($connectionConfig) { return $this->connectionFactory->create($connectionConfig); } else { - throw new \DomainException('Connection "' . $connectionName . '" is not defined'); + throw new DomainException('Connection "' . $connectionName . '" is not defined'); } } } diff --git a/Model/Session.php b/Model/Session.php index e71356b..76dc6de 100644 --- a/Model/Session.php +++ b/Model/Session.php @@ -2,7 +2,7 @@ namespace Gigya\GigyaIM\Model; -use \Magento\Framework\Session\SessionManager; +use Magento\Framework\Session\SessionManager; class Session extends SessionManager { diff --git a/Model/Session/Extend.php b/Model/Session/Extend.php index 7104686..8ceadae 100644 --- a/Model/Session/Extend.php +++ b/Model/Session/Extend.php @@ -2,14 +2,17 @@ namespace Gigya\GigyaIM\Model\Session; -use Gigya\PHP\SigUtils; +use Gigya\GigyaIM\Helper\GigyaMageHelper; +use Gigya\GigyaIM\Logger\Logger; +use Gigya\GigyaIM\Model\Session; use Gigya\GigyaIM\Model\Config; -use Magento\Framework\App\Config\ScopeConfigInterface; -use Magento\Framework\App\ScopeInterface; -use Magento\Framework\Event\Observer; -use Magento\Framework\Event\ObserverInterface; +use Magento\Framework\Exception\InputException; +use Magento\Framework\Exception\NoSuchEntityException; +use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory; +use Magento\Framework\Stdlib\Cookie\CookieSizeLimitReachedException; +use Magento\Framework\Stdlib\Cookie\FailureToSendException; +use Magento\Framework\Stdlib\CookieManagerInterface; use Magento\Framework\UrlInterface; -use Magento\Store\Model\StoreManagement; use Magento\Store\Model\StoreManager; class Extend @@ -21,12 +24,12 @@ class Extend protected $configModel; /** - * @var \Gigya\GigyaIM\Helper\GigyaMageHelper + * @var GigyaMageHelper */ protected $gigyaMageHelper; /** - * @var \Magento\Framework\Stdlib\CookieManagerInterface + * @var CookieManagerInterface */ protected $cookieManager; @@ -46,13 +49,13 @@ class Extend public function __construct( Config $configModel, - \Gigya\GigyaIM\Helper\GigyaMageHelper $gigyaMageHelper, - \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager, - \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory, - \Gigya\GigyaIM\Model\Session $sessionModel, + GigyaMageHelper $gigyaMageHelper, + CookieManagerInterface $cookieManager, + CookieMetadataFactory $cookieMetadataFactory, + Session $sessionModel, UrlInterface $urlInterface, StoreManager $storeManager, - \Gigya\GigyaIM\Logger\Logger $logger + Logger $logger ) { $this->configModel = $configModel; $this->gigyaMageHelper = $gigyaMageHelper; @@ -67,9 +70,10 @@ public function __construct( /** * @param bool $checkCookieValidity * - * @throws \Magento\Framework\Exception\InputException - * @throws \Magento\Framework\Stdlib\Cookie\CookieSizeLimitReachedException - * @throws \Magento\Framework\Stdlib\Cookie\FailureToSendException + * @throws CookieSizeLimitReachedException + * @throws FailureToSendException + * @throws InputException + * @throws NoSuchEntityException */ public function extendSession($checkCookieValidity = true) { diff --git a/Observer/AbstractGigyaAccountEnricher.php b/Observer/AbstractGigyaAccountEnricher.php index 98e6ba5..56bf2cd 100644 --- a/Observer/AbstractGigyaAccountEnricher.php +++ b/Observer/AbstractGigyaAccountEnricher.php @@ -34,9 +34,8 @@ */ class AbstractGigyaAccountEnricher implements ObserverInterface { - const EVENT_MAP_GIGYA_FROM_MAGENTO_SUCCESS = 'gigya_success_map_from_magento'; - - const EVENT_MAP_GIGYA_FROM_MAGENTO_FAILURE = 'gigya_failed_map_from_magento'; + const string EVENT_MAP_GIGYA_FROM_MAGENTO_SUCCESS = 'gigya_success_map_from_magento'; + const string EVENT_MAP_GIGYA_FROM_MAGENTO_FAILURE = 'gigya_failed_map_from_magento'; /** @var GigyaSyncHelper */ protected GigyaSyncHelper $gigyaSyncHelper; diff --git a/Observer/AbstractMagentoCustomerEnricher.php b/Observer/AbstractMagentoCustomerEnricher.php index 90f9839..2717bf4 100644 --- a/Observer/AbstractMagentoCustomerEnricher.php +++ b/Observer/AbstractMagentoCustomerEnricher.php @@ -32,9 +32,9 @@ */ abstract class AbstractMagentoCustomerEnricher implements ObserverInterface { - const EVENT_MAP_GIGYA_TO_MAGENTO_SUCCESS = 'gigya_success_map_to_magento'; + const string EVENT_MAP_GIGYA_TO_MAGENTO_SUCCESS = 'gigya_success_map_to_magento'; - const EVENT_MAP_GIGYA_TO_MAGENTO_FAILURE = 'gigya_failed_map_to_magento'; + const string EVENT_MAP_GIGYA_TO_MAGENTO_FAILURE = 'gigya_failed_map_to_magento'; /** @var CustomerRepositoryInterface */ protected CustomerRepositoryInterface $customerRepository; diff --git a/Observer/BackendMagentoCustomerEnricher.php b/Observer/BackendMagentoCustomerEnricher.php index 668bd0b..37a9f9e 100644 --- a/Observer/BackendMagentoCustomerEnricher.php +++ b/Observer/BackendMagentoCustomerEnricher.php @@ -2,6 +2,7 @@ namespace Gigya\GigyaIM\Observer; +use Exception; use Gigya\GigyaIM\Api\GigyaAccountRepositoryInterface; use Gigya\GigyaIM\Helper\GigyaSyncHelper; use Gigya\GigyaIM\Model\FieldMapping\GigyaToMagento; @@ -81,7 +82,7 @@ public function saveMagentoCustomer($magentoCustomer): void { try { parent::saveMagentoCustomer($magentoCustomer); - } catch (\Exception $e) { + } catch (Exception $e) { $magentoCustomer->setGigyaAccountEnriched(false); $this->customerRegistry->push($magentoCustomer); } diff --git a/Observer/DefaultGigyaSyncFieldMapping.php b/Observer/DefaultGigyaSyncFieldMapping.php index 714445e..0ce335a 100644 --- a/Observer/DefaultGigyaSyncFieldMapping.php +++ b/Observer/DefaultGigyaSyncFieldMapping.php @@ -8,6 +8,8 @@ use Magento\Framework\Event\ObserverInterface; use Magento\Framework\Event\Observer; use Gigya\GigyaIM\Model\Config as GigyaConfig; +use Zend_Date; +use Zend_Date_Exception; /** * DefaultCMSSyncFieldMapping @@ -33,7 +35,7 @@ public function __construct(GigyaConfig $config) * * @param Observer $observer * - * @throws \Zend_Date_Exception + * @throws Zend_Date_Exception */ public function execute(Observer $observer) { @@ -64,10 +66,10 @@ public function execute(Observer $observer) $dob = $magentoCustomer->getDob(); if ($dob !== null && trim($dob) !== '') { - $date = new \Zend_Date($dob, 'YYYY-MM-dd'); - $birthYear = (int)$date->get(\Zend_Date::YEAR); - $birthMonth = (int)$date->get(\Zend_Date::MONTH); - $birthDay = (int)$date->get(\Zend_Date::DAY); + $date = new Zend_Date($dob, 'YYYY-MM-dd'); + $birthYear = (int)$date->get(Zend_Date::YEAR); + $birthMonth = (int)$date->get(Zend_Date::MONTH); + $birthDay = (int)$date->get(Zend_Date::DAY); $gigyaProfile->setBirthDay($birthDay); $gigyaProfile->setBirthMonth($birthMonth); diff --git a/Observer/SyncCustomerToGigyaObserver.php b/Observer/SyncCustomerToGigyaObserver.php index df6a327..65c983f 100644 --- a/Observer/SyncCustomerToGigyaObserver.php +++ b/Observer/SyncCustomerToGigyaObserver.php @@ -2,6 +2,7 @@ namespace Gigya\GigyaIM\Observer; +use Gigya\GigyaIM\Exception\RetryGigyaException; use Gigya\GigyaIM\Helper\RetryGigyaSyncHelper; use Gigya\GigyaIM\Model\GigyaAccountService; use Magento\Framework\Event\Observer; @@ -57,7 +58,7 @@ public function __construct( * * @param Observer $observer * - * @throws \Gigya\GigyaIM\Exception\RetryGigyaException + * @throws RetryGigyaException */ public function execute(Observer $observer) { @@ -85,7 +86,7 @@ public function execute(Observer $observer) * * @return void * - * @throws \Gigya\GigyaIM\Exception\RetryGigyaException + * @throws RetryGigyaException */ protected function performGigyaUpdateFailure($observer) { @@ -110,8 +111,8 @@ protected function performGigyaUpdateFailure($observer) /** * If a retry row has been stored we will delete it when the a customer update has succeeded. * - * @param \Magento\Framework\Event\Observer $observer - * @throws \Gigya\GigyaIM\Exception\RetryGigyaException + * @param Observer $observer + * @throws RetryGigyaException */ protected function performGigyaUpdateSuccess($observer) { @@ -129,9 +130,9 @@ protected function performGigyaUpdateSuccess($observer) /** * Delete the retry row, if any, if a customer update has failed due to a field mapping error. * - * @param \Magento\Framework\Event\Observer $observer + * @param Observer $observer * - * @throws \Gigya\GigyaIM\Exception\RetryGigyaException + * @throws RetryGigyaException */ protected function performFieldMappingFailure($observer) { diff --git a/Plugin/App/ConfigPlugin.php b/Plugin/App/ConfigPlugin.php index a4ceb3d..990da99 100644 --- a/Plugin/App/ConfigPlugin.php +++ b/Plugin/App/ConfigPlugin.php @@ -2,6 +2,7 @@ namespace Gigya\GigyaIM\Plugin\App; +use Closure; use Gigya\GigyaIM\Model\Config as GigyaConfig; use Magento\Framework\App\Config\ScopeConfigInterface; @@ -10,11 +11,11 @@ class ConfigPlugin /** * Arbitrarily set 10 years as 'endless' session duration. That should be sufficient. */ - const ENDLESS_SESSION_LIFETIME = 315360000; /* 10 years in seconds */ + const int ENDLESS_SESSION_LIFETIME = 315360000; /* 10 years in seconds */ /** * @param ScopeConfigInterface $subject - * @param \Closure $proceed + * @param Closure $proceed * @param string $path * @param string $scope * @param $scopeCode @@ -22,7 +23,7 @@ class ConfigPlugin */ public function aroundGetValue( ScopeConfigInterface $subject, - \Closure $proceed, + Closure $proceed, $path = null, $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeCode = null diff --git a/Plugin/Config/Model/Config.php b/Plugin/Config/Model/Config.php index 4a356a4..c4e3170 100644 --- a/Plugin/Config/Model/Config.php +++ b/Plugin/Config/Model/Config.php @@ -2,12 +2,16 @@ namespace Gigya\GigyaIM\Plugin\Config\Model; +use Exception; use Gigya\GigyaIM\Helper\CmsStarterKit\GSApiException; use Gigya\GigyaIM\Helper\GigyaMageHelper; use Gigya\GigyaIM\Model\Config as GigyaConfig; use Gigya\GigyaIM\Logger\Logger as GigyaLogger; +use Gigya\GigyaIM\Model\Config\Source\Domain; +use Gigya\PHP\GSException; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Exception\NoSuchEntityException; use Magento\Store\Model\StoreRepository; use Magento\Store\Model\ScopeInterface; @@ -64,9 +68,9 @@ public function __construct( * @param \Magento\Config\Model\Config $subject * * @throws LocalizedException - * @throws \Gigya\PHP\GSException - * @throws \Magento\Framework\Exception\NoSuchEntityException - * @throws \Exception + * @throws GSException + * @throws NoSuchEntityException + * @throws Exception */ public function beforeSave(\Magento\Config\Model\Config $subject) { @@ -110,7 +114,7 @@ public function beforeSave(\Magento\Config\Model\Config $subject) /** * @param \Magento\Config\Model\Config $subject * @return array - * @throws \Magento\Framework\Exception\NoSuchEntityException + * @throws NoSuchEntityException */ public function getScope(\Magento\Config\Model\Config $subject) { @@ -196,7 +200,7 @@ public function validateSettings($settings, $scopeType, $scopeCode) ); } - if ($settings['domain'] == \Gigya\GigyaIM\Model\Config\Source\Domain::OTHER && + if ($settings['domain'] == Domain::OTHER && empty($settings['data_center_host']) === true) { throw new LocalizedException( __('It is necessary to provide a data center host') diff --git a/Plugin/Customer/Api/AllowDeleteInvalidCustomer.php b/Plugin/Customer/Api/AllowDeleteInvalidCustomer.php index d9e1779..c1f6d67 100644 --- a/Plugin/Customer/Api/AllowDeleteInvalidCustomer.php +++ b/Plugin/Customer/Api/AllowDeleteInvalidCustomer.php @@ -2,6 +2,11 @@ namespace Gigya\GigyaIM\Plugin\Customer\Api; +use Closure; +use Gigya\GigyaIM\Helper\GigyaSyncHelper; +use Magento\Customer\Api\CustomerRepositoryInterface; +use Magento\Customer\Api\Data\CustomerInterface; + /** * Class AllowDeleteInvalidCustomer * @@ -14,15 +19,15 @@ class AllowDeleteInvalidCustomer { /** - * @var \Gigya\GigyaIM\Helper\GigyaSyncHelper + * @var GigyaSyncHelper */ protected $gigyaSyncHelper; /** - * @param \Gigya\GigyaIM\Helper\GigyaSyncHelper $gigyaSyncHelper + * @param GigyaSyncHelper $gigyaSyncHelper */ public function __construct( - \Gigya\GigyaIM\Helper\GigyaSyncHelper $gigyaSyncHelper + GigyaSyncHelper $gigyaSyncHelper ) { $this->gigyaSyncHelper = $gigyaSyncHelper; } @@ -30,15 +35,15 @@ public function __construct( /** * Prevents syncing a customer that is about to be deleted * - * @param \Magento\Customer\Api\CustomerRepositoryInterface $subject - * @param \Closure $proceed - * @param \Magento\Customer\Api\Data\CustomerInterface $customer + * @param CustomerRepositoryInterface $subject + * @param Closure $proceed + * @param CustomerInterface $customer * @return bool */ public function aroundDelete( - \Magento\Customer\Api\CustomerRepositoryInterface $subject, - \Closure $proceed, - \Magento\Customer\Api\Data\CustomerInterface $customer + CustomerRepositoryInterface $subject, + Closure $proceed, + CustomerInterface $customer ) { $customerId = $customer->getId(); $this->gigyaSyncHelper->excludeCustomerIdFromSync($customerId); @@ -50,14 +55,14 @@ public function aroundDelete( /** * Prevents syncing a customer that is about to be deleted * - * @param \Magento\Customer\Api\CustomerRepositoryInterface $subject - * @param \Closure $proceed + * @param CustomerRepositoryInterface $subject + * @param Closure $proceed * @param int $customerId * @return bool */ public function aroundDeleteById( - \Magento\Customer\Api\CustomerRepositoryInterface $subject, - \Closure $proceed, + CustomerRepositoryInterface $subject, + Closure $proceed, $customerId ) { $this->gigyaSyncHelper->excludeCustomerIdFromSync($customerId); diff --git a/Plugin/Customer/Model/CustomerExtractorPlugin.php b/Plugin/Customer/Model/CustomerExtractorPlugin.php index ac3c15d..a5ee1d1 100644 --- a/Plugin/Customer/Model/CustomerExtractorPlugin.php +++ b/Plugin/Customer/Model/CustomerExtractorPlugin.php @@ -5,6 +5,7 @@ use Gigya\GigyaIM\Helper\CmsStarterKit\user\GigyaUser; use Gigya\GigyaIM\Helper\GigyaSyncHelper; use Magento\Customer\Api\Data\CustomerInterface; +use Magento\Customer\Model\CustomerExtractor; use Magento\Customer\Model\Session; use Magento\Framework\App\RequestInterface; use Gigya\GigyaIM\Model\Config as GigyaConfig; @@ -75,9 +76,9 @@ protected function shallUpdateSessionGigyaAccountWithMagentoCustomerData($formCo * * @see GigyaSyncHelper::updateMagentoCustomerDataWithSessionGigyaAccount() * - * @see \Magento\Customer\Model\CustomerExtractor::extract() + * @see CustomerExtractor::extract * - * @param \Magento\Customer\Model\CustomerExtractor $subject + * @param CustomerExtractor $subject * @param callable $proceed * @param string $formCode * @param RequestInterface $request diff --git a/Plugin/Customer/Model/RollbackGigyaDataPlugin.php b/Plugin/Customer/Model/RollbackGigyaDataPlugin.php index d08a1bd..25a38ed 100644 --- a/Plugin/Customer/Model/RollbackGigyaDataPlugin.php +++ b/Plugin/Customer/Model/RollbackGigyaDataPlugin.php @@ -2,8 +2,11 @@ namespace Gigya\GigyaIM\Plugin\Customer\Model; +use Closure; +use Exception; use Gigya\GigyaIM\Api\GigyaAccountServiceInterface; use Gigya\GigyaIM\Exception\GigyaMagentoCustomerSaveException; +use Gigya\GigyaIM\Exception\RetryGigyaException; use Gigya\GigyaIM\Helper\GigyaSyncHelper; use Gigya\GigyaIM\Helper\RetryGigyaSyncHelper; use Gigya\GigyaIM\Model\GigyaAccountService; @@ -46,17 +49,17 @@ public function __construct( * (*) we also save the Magento customer when it's loaded in backend, after being enriched with the current data from Gigya : in this case we do not want to sync back the customer to Gigya. * * @param CustomerRepositoryInterface $subject - * @param \Closure $proceed + * @param Closure $proceed * @param CustomerInterface $customer * * @return CustomerInterface * * @throws GigyaMagentoCustomerSaveException - * @throws \Gigya\GigyaIM\Exception\RetryGigyaException + * @throws RetryGigyaException */ public function aroundSave( CustomerRepositoryInterface $subject, - \Closure $proceed, + Closure $proceed, CustomerInterface $customer ) { $result = null; @@ -73,7 +76,7 @@ public function aroundSave( 'Could not remove retry entry for Magento update after a successful update on the same Magento Customer entity.' ); } - } catch (\Exception $e) { + } catch (Exception $e) { $uid = $customer->getCustomAttribute('gigya_uid') != null ? $customer->getCustomAttribute('gigya_uid')->getValue() : null; if (null !== $uid) { if (!$this->retryGigyaSyncHelper->isCustomerIdExcludedFromSync($customer->getId(), GigyaSyncHelper::DIR_CMS2G)) { diff --git a/Plugin/Framework/Session/Config.php b/Plugin/Framework/Session/Config.php index 594118b..90ab7cd 100644 --- a/Plugin/Framework/Session/Config.php +++ b/Plugin/Framework/Session/Config.php @@ -3,8 +3,9 @@ namespace Gigya\GigyaIM\Plugin\Framework\Session; use Gigya\GigyaIM\Model\Config as GigyaConfig; -use \Magento\Framework\App\State; -use \Magento\Framework\App\Request\Http as RequestHttp; +use Magento\Framework\App\State; +use Magento\Framework\App\Request\Http as RequestHttp; +use Magento\Framework\Exception\LocalizedException; class Config { @@ -50,7 +51,7 @@ public function beforeSetCookieLifetime(\Magento\Framework\Session\Config $subje { try { $areaCode = $this->state->getAreaCode(); - } catch (\Magento\Framework\Exception\LocalizedException $e) { + } catch (LocalizedException $e) { $areaCode = null; } $sessionMode = $this->config->getSessionMode(); diff --git a/Plugin/Framework/Session/SessionManager.php b/Plugin/Framework/Session/SessionManager.php index 1c82c8f..066b0e7 100644 --- a/Plugin/Framework/Session/SessionManager.php +++ b/Plugin/Framework/Session/SessionManager.php @@ -2,8 +2,12 @@ namespace Gigya\GigyaIM\Plugin\Framework\Session; +use Closure; use Gigya\GigyaIM\Model\Config as GigyaConfig; -use \Magento\Framework\App\State; +use Magento\Framework\App\State; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Exception\SessionException; +use Magento\Framework\Session\SessionManager as MagentoSessionManager; class SessionManager { @@ -43,17 +47,17 @@ public function __construct( protected $allowCookieLifetime = true; /** - * @param \Magento\Framework\Session\SessionManager $subject - * @param \Closure $proceed + * @param MagentoSessionManager $subject + * @param Closure $proceed * * @return mixed - * @throws \Magento\Framework\Exception\SessionException + * @throws SessionException */ - public function aroundStart(\Magento\Framework\Session\SessionManager $subject, \Closure $proceed) + public function aroundStart(MagentoSessionManager $subject, Closure $proceed) { try { $areaCode = $this->state->getAreaCode(); - } catch (\Magento\Framework\Exception\LocalizedException $e) { + } catch (LocalizedException $e) { $areaCode = null; } $sessionMode = $this->config->getSessionMode(); @@ -69,7 +73,7 @@ public function aroundStart(\Magento\Framework\Session\SessionManager $subject, */ try { $result = $proceed(); - } catch (\Magento\Framework\Exception\SessionException $e) { + } catch (SessionException $e) { $this->allowCookieLifetime = true; throw $e; } diff --git a/Session/Config.php b/Session/Config.php index 6e2ad21..903a0c0 100644 --- a/Session/Config.php +++ b/Session/Config.php @@ -5,16 +5,20 @@ use Magento\Framework\Session\Config as MagentoSessionConfig; use Magento\Framework\App\DeploymentConfig; use Magento\Framework\Filesystem; +use Magento\Framework\ValidatorFactory; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\Stdlib\StringUtils; +use Magento\Framework\App\RequestInterface; use Gigya\GigyaIM\Model\Config as GigyaConfig; class Config extends MagentoSessionConfig { /** * Config constructor. - * @param \Magento\Framework\ValidatorFactory $validatorFactory - * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig - * @param \Magento\Framework\Stdlib\StringUtils $stringHelper - * @param \Magento\Framework\App\RequestInterface $request + * @param ValidatorFactory $validatorFactory + * @param ScopeConfigInterface $scopeConfig + * @param StringUtils $stringHelper + * @param RequestInterface $request * @param Filesystem $filesystem * @param DeploymentConfig $deploymentConfig * @param GigyaConfig $gigyaConfig @@ -24,10 +28,10 @@ class Config extends MagentoSessionConfig * @SuppressWarnings(PHPMD.NPathComplexity) */ public function __construct( - \Magento\Framework\ValidatorFactory $validatorFactory, - \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, - \Magento\Framework\Stdlib\StringUtils $stringHelper, - \Magento\Framework\App\RequestInterface $request, + ValidatorFactory $validatorFactory, + ScopeConfigInterface $scopeConfig, + StringUtils $stringHelper, + RequestInterface $request, Filesystem $filesystem, DeploymentConfig $deploymentConfig, GigyaConfig $gigyaConfig, diff --git a/Setup/InstallSchema.php b/Setup/InstallSchema.php index afeb5b1..86abef7 100644 --- a/Setup/InstallSchema.php +++ b/Setup/InstallSchema.php @@ -5,15 +5,13 @@ use Magento\Framework\Setup\InstallSchemaInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\SchemaSetupInterface; -use Magento\Framework\DB\Ddl\Table; class InstallSchema implements InstallSchemaInterface { /** - * @param SchemaSetupInterface $setup + * @param SchemaSetupInterface $setup * @param ModuleContextInterface $context * - * @throws \Zend_Db_Exception */ public function install(SchemaSetupInterface $setup, ModuleContextInterface $context) { diff --git a/Setup/UpgradeData.php b/Setup/UpgradeData.php index 08aa18b..7231652 100644 --- a/Setup/UpgradeData.php +++ b/Setup/UpgradeData.php @@ -2,6 +2,7 @@ namespace Gigya\GigyaIM\Setup; +use Exception; use Magento\Config\Model\ResourceModel\Config as ResourceModelConfig; use Magento\Customer\Setup\CustomerSetup; use Magento\Customer\Setup\CustomerSetupFactory; @@ -79,7 +80,7 @@ public function __construct( * @return void * * @throws LocalizedException - * @throws \Exception + * @throws Exception */ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { diff --git a/Setup/UpgradeSchema.php b/Setup/UpgradeSchema.php index 51cbcf8..82e572d 100644 --- a/Setup/UpgradeSchema.php +++ b/Setup/UpgradeSchema.php @@ -6,6 +6,8 @@ use Magento\Framework\DB\Ddl\Table; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\SchemaSetupInterface; +use Magento\Framework\Setup\UpgradeSchemaInterface; +use Zend_Db_Exception; /** * UpgradeSchema @@ -14,12 +16,12 @@ * * @author vlemaire */ -class UpgradeSchema implements \Magento\Framework\Setup\UpgradeSchemaInterface +class UpgradeSchema implements UpgradeSchemaInterface { /** * @param SchemaSetupInterface $setup * @param ModuleContextInterface $context - * @throws \Zend_Db_Exception + * @throws Zend_Db_Exception */ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context) { @@ -63,7 +65,7 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con 'The attempt count to re synchronize the data' )->addColumn( 'date', - \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME, + Table::TYPE_DATETIME, null, [ 'nullable' => true ], 'Date time of the last attempt to re synchronize the data'