Skip to content

Commit

Permalink
CS fixer 4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
leemyongpakvn committed Dec 1, 2023
1 parent 9dd6d9a commit b3a2b5f
Show file tree
Hide file tree
Showing 25 changed files with 160 additions and 237 deletions.
49 changes: 22 additions & 27 deletions classes/Database/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,19 @@

namespace PrestaShop\Module\Ps_Googleanalytics\Database;

use Configuration;
use Db;
use Language;
use Ps_Googleanalytics;
use Shop;
use Tab;

class Install
{
/**
* @var Ps_Googleanalytics
* @var \Ps_Googleanalytics
*/
private $module;

public function __construct(Ps_Googleanalytics $module)
public function __construct(\Ps_Googleanalytics $module)
{
if (Shop::isFeatureActive()) {
Shop::setContext(Shop::CONTEXT_ALL);
if (\Shop::isFeatureActive()) {
\Shop::setContext(\Shop::CONTEXT_ALL);
}

$this->module = $module;
Expand Down Expand Up @@ -73,7 +68,7 @@ public function installTables()
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=utf8';

foreach ($sql as $query) {
if (!Db::getInstance()->execute($query)) {
if (!\Db::getInstance()->execute($query)) {
return false;
}
}
Expand All @@ -88,9 +83,9 @@ public function installTables()
*/
public function setDefaultConfiguration()
{
Configuration::updateValue('GA_CANCELLED_STATES', json_encode([Configuration::get('PS_OS_CANCELED')]));
Configuration::updateValue('GA_BACKLOAD_ENABLED', false);
Configuration::updateValue('GA_BACKLOAD_DAYS', 30);
\Configuration::updateValue('GA_CANCELLED_STATES', json_encode([\Configuration::get('PS_OS_CANCELED')]));
\Configuration::updateValue('GA_BACKLOAD_ENABLED', false);
\Configuration::updateValue('GA_BACKLOAD_DAYS', 30);

return true;
}
Expand All @@ -102,18 +97,18 @@ public function setDefaultConfiguration()
*/
public function registerHooks()
{
return $this->module->registerHook('displayHeader') &&
$this->module->registerHook('displayAdminOrder') &&
$this->module->registerHook('displayBeforeBodyClosingTag') &&
$this->module->registerHook('displayFooterProduct') &&
$this->module->registerHook('displayOrderConfirmation') &&
$this->module->registerHook('actionProductCancel') &&
$this->module->registerHook('actionValidateOrder') &&
$this->module->registerHook('actionOrderStatusPostUpdate') &&
$this->module->registerHook('actionCartUpdateQuantityBefore') &&
$this->module->registerHook('actionObjectProductInCartDeleteBefore') &&
$this->module->registerHook('displayBackOfficeHeader') &&
$this->module->registerHook('actionCarrierProcess');
return $this->module->registerHook('displayHeader')
&& $this->module->registerHook('displayAdminOrder')
&& $this->module->registerHook('displayBeforeBodyClosingTag')
&& $this->module->registerHook('displayFooterProduct')
&& $this->module->registerHook('displayOrderConfirmation')
&& $this->module->registerHook('actionProductCancel')
&& $this->module->registerHook('actionValidateOrder')
&& $this->module->registerHook('actionOrderStatusPostUpdate')
&& $this->module->registerHook('actionCartUpdateQuantityBefore')
&& $this->module->registerHook('actionObjectProductInCartDeleteBefore')
&& $this->module->registerHook('displayBackOfficeHeader')
&& $this->module->registerHook('actionCarrierProcess');
}

/**
Expand All @@ -123,13 +118,13 @@ public function registerHooks()
*/
public function installTab()
{
$tab = new Tab();
$tab = new \Tab();
$tab->class_name = 'AdminGanalyticsAjax';
$tab->module = $this->module->name;
$tab->active = true;
$tab->id_parent = -1;
$tab->name = array_fill_keys(
Language::getIDs(false),
\Language::getIDs(false),
$this->module->displayName
);

Expand Down
10 changes: 4 additions & 6 deletions classes/Database/Uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@

namespace PrestaShop\Module\Ps_Googleanalytics\Database;

use Db;
use Tab;
use Validate;

class Uninstall
{
Expand All @@ -37,7 +35,7 @@ public function uninstallTables()
$sql[] = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'ganalytics_data`';

foreach ($sql as $query) {
if (!Db::getInstance()->execute($query)) {
if (!\Db::getInstance()->execute($query)) {
return false;
}
}
Expand All @@ -53,9 +51,9 @@ public function uninstallTables()
public function uninstallTab()
{
$result = true;
$id_tab = (int) Tab::getIdFromClassName('AdminGanalyticsAjax');
$tab = new Tab($id_tab);
if (Validate::isLoadedObject($tab)) {
$id_tab = (int) \Tab::getIdFromClassName('AdminGanalyticsAjax');
$tab = new \Tab($id_tab);
if (\Validate::isLoadedObject($tab)) {
$result = $tab->delete();
}

Expand Down
70 changes: 31 additions & 39 deletions classes/Form/ConfigurationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,11 @@

namespace PrestaShop\Module\Ps_Googleanalytics\Form;

use AdminController;
use Configuration;
use Context;
use HelperForm;
use OrderState;
use Ps_Googleanalytics;
use Tools;

class ConfigurationForm
{
private $module;

public function __construct(Ps_Googleanalytics $module)
public function __construct(\Ps_Googleanalytics $module)
{
$this->module = $module;
}
Expand All @@ -45,15 +37,15 @@ public function __construct(Ps_Googleanalytics $module)
public function generate()
{
// Get default language
$default_lang = (int) Configuration::get('PS_LANG_DEFAULT');
$default_lang = (int) \Configuration::get('PS_LANG_DEFAULT');

$helper = new HelperForm();
$helper = new \HelperForm();

// Module, token and currentIndex
$helper->module = $this->module;
$helper->name_controller = $this->module->name;
$helper->token = Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = AdminController::$currentIndex . '&configure=' . $this->module->name;
$helper->token = \Tools::getAdminTokenLite('AdminModules');
$helper->currentIndex = \AdminController::$currentIndex . '&configure=' . $this->module->name;

// Language
$helper->default_form_language = $default_lang;
Expand All @@ -67,11 +59,11 @@ public function generate()
$helper->toolbar_btn = [
'save' => [
'desc' => $this->module->getTranslator()->trans('Save', [], 'Modules.Googleanalytics.Admin'),
'href' => AdminController::$currentIndex . '&configure=' . $this->module->name . '&save=' . $this->module->name .
'href' => \AdminController::$currentIndex . '&configure=' . $this->module->name . '&save=' . $this->module->name .
'&token=' . $helper->token,
],
'back' => [
'href' => AdminController::$currentIndex . '&token=' . $helper->token,
'href' => \AdminController::$currentIndex . '&token=' . $helper->token,
'desc' => $this->module->getTranslator()->trans('Back to list', [], 'Modules.Googleanalytics.Admin'),
],
];
Expand Down Expand Up @@ -153,7 +145,7 @@ public function generate()
'class' => 'chosen',
'multiple' => true,
'options' => [
'query' => OrderState::getOrderStates((int) Context::getContext()->language->id),
'query' => \OrderState::getOrderStates((int) \Context::getContext()->language->id),
'id' => 'id_order_state',
'name' => 'name',
],
Expand Down Expand Up @@ -191,13 +183,13 @@ public function generate()
];

// Load current value
$helper->fields_value['GA_ACCOUNT_ID'] = Configuration::get('GA_ACCOUNT_ID');
$helper->fields_value['GA_USERID_ENABLED'] = (bool) Configuration::get('GA_USERID_ENABLED');
$helper->fields_value['GA_ANONYMIZE_ENABLED'] = (bool) Configuration::get('GA_ANONYMIZE_ENABLED');
$helper->fields_value['GA_TRACK_BACKOFFICE_ENABLED'] = (bool) Configuration::get('GA_TRACK_BACKOFFICE_ENABLED');
$helper->fields_value['GA_CANCELLED_STATES[]'] = json_decode(Configuration::get('GA_CANCELLED_STATES'), true);
$helper->fields_value['GA_BACKLOAD_ENABLED'] = (bool) Configuration::get('GA_BACKLOAD_ENABLED');
$helper->fields_value['GA_BACKLOAD_DAYS'] = (int) Configuration::get('GA_BACKLOAD_DAYS');
$helper->fields_value['GA_ACCOUNT_ID'] = \Configuration::get('GA_ACCOUNT_ID');
$helper->fields_value['GA_USERID_ENABLED'] = (bool) \Configuration::get('GA_USERID_ENABLED');
$helper->fields_value['GA_ANONYMIZE_ENABLED'] = (bool) \Configuration::get('GA_ANONYMIZE_ENABLED');
$helper->fields_value['GA_TRACK_BACKOFFICE_ENABLED'] = (bool) \Configuration::get('GA_TRACK_BACKOFFICE_ENABLED');
$helper->fields_value['GA_CANCELLED_STATES[]'] = json_decode(\Configuration::get('GA_CANCELLED_STATES'), true);
$helper->fields_value['GA_BACKLOAD_ENABLED'] = (bool) \Configuration::get('GA_BACKLOAD_ENABLED');
$helper->fields_value['GA_BACKLOAD_DAYS'] = (int) \Configuration::get('GA_BACKLOAD_DAYS');

return $helper->generateForm($fields_form);
}
Expand All @@ -209,43 +201,43 @@ public function generate()
*/
public function treat()
{
$gaAccountId = Tools::getValue('GA_ACCOUNT_ID');
$gaUserIdEnabled = Tools::getValue('GA_USERID_ENABLED');
$gaAnonymizeEnabled = Tools::getValue('GA_ANONYMIZE_ENABLED');
$gaTrackBackOffice = Tools::getValue('GA_TRACK_BACKOFFICE_ENABLED');
$gaCancelledStates = Tools::getValue('GA_CANCELLED_STATES');
$gaBackloadEnabled = Tools::getValue('GA_BACKLOAD_ENABLED');
$gaBackloadDays = Tools::getValue('GA_BACKLOAD_DAYS');
$gaAccountId = \Tools::getValue('GA_ACCOUNT_ID');
$gaUserIdEnabled = \Tools::getValue('GA_USERID_ENABLED');
$gaAnonymizeEnabled = \Tools::getValue('GA_ANONYMIZE_ENABLED');
$gaTrackBackOffice = \Tools::getValue('GA_TRACK_BACKOFFICE_ENABLED');
$gaCancelledStates = \Tools::getValue('GA_CANCELLED_STATES');
$gaBackloadEnabled = \Tools::getValue('GA_BACKLOAD_ENABLED');
$gaBackloadDays = \Tools::getValue('GA_BACKLOAD_DAYS');

if (!empty($gaAccountId)) {
Configuration::updateValue('GA_ACCOUNT_ID', $gaAccountId);
Configuration::updateValue('GANALYTICS_CONFIGURATION_OK', true);
\Configuration::updateValue('GA_ACCOUNT_ID', $gaAccountId);
\Configuration::updateValue('GANALYTICS_CONFIGURATION_OK', true);
}

if (null !== $gaUserIdEnabled) {
Configuration::updateValue('GA_USERID_ENABLED', (bool) $gaUserIdEnabled);
\Configuration::updateValue('GA_USERID_ENABLED', (bool) $gaUserIdEnabled);
}

if (null !== $gaAnonymizeEnabled) {
Configuration::updateValue('GA_ANONYMIZE_ENABLED', (bool) $gaAnonymizeEnabled);
\Configuration::updateValue('GA_ANONYMIZE_ENABLED', (bool) $gaAnonymizeEnabled);
}

if (null !== $gaTrackBackOffice) {
Configuration::updateValue('GA_TRACK_BACKOFFICE_ENABLED', (bool) $gaTrackBackOffice);
\Configuration::updateValue('GA_TRACK_BACKOFFICE_ENABLED', (bool) $gaTrackBackOffice);
}

if (null !== $gaBackloadEnabled) {
Configuration::updateValue('GA_BACKLOAD_ENABLED', (bool) $gaBackloadEnabled);
\Configuration::updateValue('GA_BACKLOAD_ENABLED', (bool) $gaBackloadEnabled);
}

if (null !== $gaBackloadDays) {
Configuration::updateValue('GA_BACKLOAD_DAYS', (int) $gaBackloadDays);
\Configuration::updateValue('GA_BACKLOAD_DAYS', (int) $gaBackloadDays);
}

if ($gaCancelledStates === false) {
Configuration::updateValue('GA_CANCELLED_STATES', '');
\Configuration::updateValue('GA_CANCELLED_STATES', '');
} else {
Configuration::updateValue('GA_CANCELLED_STATES', json_encode($gaCancelledStates));
\Configuration::updateValue('GA_CANCELLED_STATES', json_encode($gaCancelledStates));
}

return $this->module->displayConfirmation($this->module->getTranslator()->trans('Settings updated successfully.', [], 'Modules.Googleanalytics.Admin'));
Expand Down
4 changes: 1 addition & 3 deletions classes/GoogleAnalyticsTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

namespace PrestaShop\Module\Ps_Googleanalytics;

use Configuration;

class GoogleAnalyticsTools
{
/**
Expand Down Expand Up @@ -102,7 +100,7 @@ public function renderEvent($eventName, $eventData, $ignoredKeys = [])
// Automatically add send_to parameter to all events to avoid sending extra events
// to other gtag configs (Ads for example).
$eventData = array_merge(
['send_to' => Configuration::get('GA_ACCOUNT_ID')],
['send_to' => \Configuration::get('GA_ACCOUNT_ID')],
$eventData
);

Expand Down
8 changes: 2 additions & 6 deletions classes/Handler/GanalyticsJsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,12 @@

namespace PrestaShop\Module\Ps_Googleanalytics\Handler;

use Configuration;
use Context;
use Ps_Googleanalytics;

class GanalyticsJsHandler
{
private $module;
private $context;

public function __construct(Ps_Googleanalytics $module, Context $context)
public function __construct(\Ps_Googleanalytics $module, \Context $context)
{
$this->module = $module;
$this->context = $context;
Expand All @@ -44,7 +40,7 @@ public function __construct(Ps_Googleanalytics $module, Context $context)
*/
public function generate($jsCode)
{
if (Configuration::get('GA_ACCOUNT_ID')) {
if (\Configuration::get('GA_ACCOUNT_ID')) {
$this->context->smarty->assign(
[
'jsCode' => $jsCode,
Expand Down
16 changes: 7 additions & 9 deletions classes/Handler/ModuleHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

namespace PrestaShop\Module\Ps_Googleanalytics\Handler;

use Module;

class ModuleHandler
{
/**
Expand All @@ -31,13 +29,13 @@ class ModuleHandler
*/
public function isModuleEnabled($moduleName)
{
$module = Module::getInstanceByName($moduleName);
$module = \Module::getInstanceByName($moduleName);

if (!($module instanceof Module)) {
if (!($module instanceof \Module)) {
return false;
}

if (false === Module::isInstalled($moduleName)) {
if (false === \Module::isInstalled($moduleName)) {
return false;
}

Expand All @@ -56,7 +54,7 @@ public function isModuleEnabled($moduleName)
*/
public function isModuleEnabledAndHookedOn($moduleName, $hookName)
{
$module = Module::getInstanceByName($moduleName);
$module = \Module::getInstanceByName($moduleName);

if (false === $this->isModuleEnabled($moduleName)) {
return false;
Expand All @@ -72,13 +70,13 @@ public function isModuleEnabledAndHookedOn($moduleName, $hookName)
*/
public function uninstallModule($moduleName)
{
if (false === Module::isInstalled($moduleName)) {
if (false === \Module::isInstalled($moduleName)) {
return false;
}

$oldModule = Module::getInstanceByName($moduleName);
$oldModule = \Module::getInstanceByName($moduleName);

if (!($oldModule instanceof Module)) {
if (!($oldModule instanceof \Module)) {
return false;
}

Expand Down
4 changes: 1 addition & 3 deletions classes/Hook/HookActionCarrierProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@

namespace PrestaShop\Module\Ps_Googleanalytics\Hooks;

use Context;
use PrestaShop\Module\Ps_Googleanalytics\Repository\CarrierRepository;
use Ps_Googleanalytics;

class HookActionCarrierProcess implements HookInterface
{
private $module;
private $context;
private $params;

public function __construct(Ps_Googleanalytics $module, Context $context)
public function __construct(\Ps_Googleanalytics $module, \Context $context)
{
$this->module = $module;
$this->context = $context;
Expand Down
Loading

0 comments on commit b3a2b5f

Please sign in to comment.