Skip to content

Commit

Permalink
Merge pull request #34653 from Hlavtox/type-legacy-admin-protected
Browse files Browse the repository at this point in the history
Type protected and private methods of legacy admin controllers
  • Loading branch information
Hlavtox committed Nov 28, 2023
2 parents 9781b9e + ce5af89 commit 28602bf
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 53 deletions.
4 changes: 2 additions & 2 deletions controllers/admin/AdminAccessController.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public function getCurrentProfileId()
*
* @return int
*/
protected function sortModuleByName($a, $b)
protected function sortModuleByName(array $a, array $b)
{
$moduleAName = isset($a['name']) ? $a['name'] : null;
$moduleBName = isset($b['name']) ? $b['name'] : null;
Expand All @@ -218,7 +218,7 @@ protected function displayTabs(array $tabs)
return $tabsTree;
}

protected function getChildrenTab(array &$tabs, $id_parent = 0)
protected function getChildrenTab(array &$tabs, int $id_parent = 0)
{
$children = [];
foreach ($tabs as $tab) {
Expand Down
6 changes: 3 additions & 3 deletions controllers/admin/AdminCarrierWizardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ public function renderStepFive($carrier)
* @param array $tpl_vars
* @param array $fields_value
*/
protected function getTplRangesVarsAndValues($carrier, &$tpl_vars, &$fields_value)
protected function getTplRangesVarsAndValues(Carrier $carrier, array &$tpl_vars, array &$fields_value)
{
$tpl_vars['zones'] = Zone::getZones(false, true);
$carrier_zones = $carrier->getZones();
Expand Down Expand Up @@ -664,7 +664,7 @@ public function ajaxProcessChangeRanges()
die($template->fetch());
}

protected function validateForm($die = true)
protected function validateForm(bool $die = true)
{
$step_number = (int) Tools::getValue('step_number');
$return = ['has_error' => false];
Expand Down Expand Up @@ -889,7 +889,7 @@ public function ajaxProcessFinishStep()
die(json_encode($return));
}

protected function changeGroups($id_carrier, $delete = true)
protected function changeGroups(int $id_carrier, bool $delete = true)
{
$carrier = new Carrier((int) $id_carrier);
if (!Validate::isLoadedObject($carrier)) {
Expand Down
2 changes: 1 addition & 1 deletion controllers/admin/AdminCarriersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ protected function beforeDelete($object)
return (bool) $object->isUsed();
}

protected function changeGroups($id_carrier, $delete = true)
protected function changeGroups(int $id_carrier, bool $delete = true)
{
if ($delete) {
Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . 'carrier_group WHERE id_carrier = ' . (int) $id_carrier);
Expand Down
8 changes: 4 additions & 4 deletions controllers/admin/AdminCartRulesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public function processDelete()
}

/**
* @param $current_object
* @param CartRule $current_object
*
* @return bool|void
*
Expand Down Expand Up @@ -325,7 +325,7 @@ public function processAdd()
/**
* @TODO Move this function into CartRule
*
* @param ObjectModel $currentObject
* @param CartRule $currentObject
*
* @return bool|void
*
Expand Down Expand Up @@ -639,9 +639,9 @@ public function ajaxProcess()
}
}

protected function searchProducts($search)
protected function searchProducts(string $searchString)
{
if ($products = Product::searchByName((int) $this->context->language->id, $search)) {
if ($products = Product::searchByName((int) $this->context->language->id, $searchString)) {
foreach ($products as &$product) {
$combinations = [];
$productObj = new Product((int) $product['id_product'], false, (int) $this->context->language->id);
Expand Down
4 changes: 2 additions & 2 deletions controllers/admin/AdminCustomerThreadsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ public function getTimeline($messages, $id_order)
return $timeline;
}

protected function displayMessage($message, $email = false, $id_employee = null)
protected function displayMessage(array $message, string|bool $email = false, int $id_employee = null)
{
$tpl = $this->createTemplate('message.tpl');

Expand Down Expand Up @@ -906,7 +906,7 @@ protected function displayMessage($message, $email = false, $id_employee = null)
return $tpl->fetch();
}

protected function displayButton($content)
protected function displayButton(string $content)
{
return '<div><p>' . $content . '</p></div>';
}
Expand Down
5 changes: 3 additions & 2 deletions controllers/admin/AdminGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,15 @@ public function renderView()
$this->tpl_view_vars = [
'group' => $group,
'language' => $this->context->language,
// @phpstan-ignore-next-line
'customerList' => $this->renderCustomersList($group),
'categorieReductions' => $this->formatCategoryDiscountList($group->id),
];

return parent::renderView();
}

protected function renderCustomersList($group)
protected function renderCustomersList(Group $group)
{
$genders = [0 => '?'];
$genders_icon = ['default' => 'unknown.gif'];
Expand Down Expand Up @@ -449,7 +450,7 @@ public function renderForm()
return parent::renderForm();
}

protected function formatCategoryDiscountList($id_group)
protected function formatCategoryDiscountList(int $id_group)
{
$group_reductions = GroupReduction::getGroupReductions((int) $id_group, $this->context->language->id);
$category_reductions = [];
Expand Down
12 changes: 6 additions & 6 deletions controllers/admin/AdminImagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ public function initRegenerate()
*
* @return bool
*/
protected function _deleteOldImages($dir, $type, $product = false)
protected function _deleteOldImages(string $dir, array $type, bool $product = false)
{
if (!is_dir($dir)) {
return false;
Expand Down Expand Up @@ -640,7 +640,7 @@ protected function _deleteOldImages($dir, $type, $product = false)
*
* @return bool|string
*/
protected function _regenerateNewImages($dir, $type, $productsImages = false)
protected function _regenerateNewImages(string $dir, array $type, bool $productsImages = false)
{
if (!is_dir($dir)) {
return false;
Expand Down Expand Up @@ -758,7 +758,7 @@ protected function _regenerateNewImages($dir, $type, $productsImages = false)
*
* @return bool
*/
protected function _regenerateNoPictureImages($dir, $type, $languages)
protected function _regenerateNoPictureImages(string $dir, array $type, array $languages)
{
$errors = false;

Expand Down Expand Up @@ -799,7 +799,7 @@ protected function _regenerateNoPictureImages($dir, $type, $languages)
}

/* Hook watermark optimization */
protected function _regenerateWatermark($dir, $type = null)
protected function _regenerateWatermark(string $dir, array $formats = null)
{
$result = Db::getInstance()->executeS('
SELECT m.`name` FROM `' . _DB_PREFIX_ . 'module` m
Expand All @@ -815,7 +815,7 @@ protected function _regenerateWatermark($dir, $type = null)
foreach ($result as $module) {
$moduleInstance = Module::getInstanceByName($module['name']);
if ($moduleInstance && is_callable([$moduleInstance, 'hookActionWatermark'])) {
call_user_func([$moduleInstance, 'hookActionWatermark'], ['id_image' => $imageObj->id, 'id_product' => $imageObj->id_product, 'image_type' => $type]);
call_user_func([$moduleInstance, 'hookActionWatermark'], ['id_image' => $imageObj->id, 'id_product' => $imageObj->id_product, 'image_type' => $formats]);
}

if (time() - $this->start_time > $this->max_execution_time - 4) { // stop 4 seconds before the tiemout, just enough time to process the end of the page on a slow server
Expand All @@ -827,7 +827,7 @@ protected function _regenerateWatermark($dir, $type = null)
}
}

protected function _regenerateThumbnails($type = 'all', $deleteOldImages = false)
protected function _regenerateThumbnails(string $type = 'all', bool $deleteOldImages = false)
{
$this->start_time = time();
ini_set('max_execution_time', $this->max_execution_time); // ini_set may be disabled, we need the real value
Expand Down
2 changes: 1 addition & 1 deletion controllers/admin/AdminModulesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function setMedia($isNewTheme = false)
*
* @return string
*/
protected function getCurrentUrl($remove = [])
protected function getCurrentUrl(array $remove = [])
{
$url = $_SERVER['REQUEST_URI'];
if (!$remove) {
Expand Down
4 changes: 2 additions & 2 deletions controllers/admin/AdminProductsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ public static function getQuantities($echo, $tr)
}
}

protected function _cleanMetaKeywords($keywords)
protected function _cleanMetaKeywords(string $keywords)
{
if (!empty($keywords) && $keywords != '') {
if (!empty($keywords)) {
$out = [];
$words = explode(',', $keywords);
foreach ($words as $word_item) {
Expand Down
2 changes: 1 addition & 1 deletion controllers/admin/AdminSearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ protected function getSearchPanels(string $searchedExpression): void
*
* @return bool
*/
protected function isCountableAndNotEmpty(array $array, $key)
protected function isCountableAndNotEmpty(array $array, string $key)
{
return isset($array[$key]) &&
is_countable($array[$key]) &&
Expand Down
4 changes: 2 additions & 2 deletions controllers/admin/AdminStoresController.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ protected function _getDefaultFieldsContent()
return $formFields;
}

protected function _buildOrderedFieldsShop($formFields)
protected function _buildOrderedFieldsShop(array $formFields)
{
// You cannot do that, because the fields must be sorted for the country you've selected.
// Simple example: the current country is France, where we don't display the state. You choose "US" as a country in the form. The state is not dsplayed at the right place...
Expand Down Expand Up @@ -610,7 +610,7 @@ public function updateOptionPsShopStateId($value)
*
* @return array
*/
protected function adaptHoursFormat($value)
protected function adaptHoursFormat(array $value)
{
$separator = array_fill(0, count($value), ' | ');

Expand Down
2 changes: 1 addition & 1 deletion controllers/admin/AdminTaxRulesGroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ protected function validateTaxRule(TaxRule $tr)
*
* @return TaxRulesGroup
*/
protected function updateTaxRulesGroup($object)
protected function updateTaxRulesGroup(TaxRulesGroup $object)
{
static $tax_rules_group = null;
if ($tax_rules_group === null) {
Expand Down

0 comments on commit 28602bf

Please sign in to comment.