Skip to content

Commit

Permalink
Merge pull request PrestaShop#35972 from jolelievre/update-cs-fixer
Browse files Browse the repository at this point in the history
Update CS fixer for PHP 8.3
  • Loading branch information
jolelievre authored Apr 19, 2024
2 parents 3191ec7 + 82100b3 commit 0e129d2
Show file tree
Hide file tree
Showing 797 changed files with 5,475 additions and 5,065 deletions.
6 changes: 6 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
'yoda_style' => false,
'single_line_throw' => false,
'no_alias_language_construct_call' => false,
'no_null_property_initialization' => false,
'global_namespace_import' => [
'import_classes' => true,
'import_constants' => false,
'import_functions' => false,
],
])
->setFinder($finder)
->setCacheFile(__DIR__.'/var/.php_cs.cache');
6 changes: 3 additions & 3 deletions app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function registerBundles(): iterable
if (!empty($installedModules)) {
try {
$this->enableComposerAutoloaderOnModules($installedModules);
} catch (\Exception $e) {
} catch (Exception $e) {
}
}

Expand Down Expand Up @@ -194,7 +194,7 @@ public function getCacheDir(): string
/**
* {@inheritdoc}
*
* @throws \Exception
* @throws Exception
*/
public function registerContainerConfiguration(LoaderInterface $loader)
{
Expand Down Expand Up @@ -419,6 +419,6 @@ protected function unlockCacheStream($lockStream): void
*/
public function getAppType(): string
{
return $this instanceof \FrontKernel ? 'front' : 'admin';
return $this instanceof FrontKernel ? 'front' : 'admin';
}
}
14 changes: 7 additions & 7 deletions app/config/set_parameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@
}

if (!array_key_exists('parameters', $parameters)) {
throw new \Exception('Missing "parameters" key in "parameters.php" configuration file');
throw new Exception('Missing "parameters" key in "parameters.php" configuration file');
}

if (!defined('_PS_IN_TEST_') && isset($_SERVER['argv'])) {
$input = new \Symfony\Component\Console\Input\ArgvInput();
$input = new Symfony\Component\Console\Input\ArgvInput();
$env = $input->getParameterOption(['--env', '-e'], getenv('SYMFONY_ENV') ?: 'dev');

if ($env === 'test') {
define('_PS_IN_TEST_', 1);
}
}

if (isset($container) && $container instanceof \Symfony\Component\DependencyInjection\Container) {
if (isset($container) && $container instanceof Symfony\Component\DependencyInjection\Container) {
foreach ($parameters['parameters'] as $key => $value) {
$container->setParameter($key, $value);
}
Expand All @@ -81,10 +81,10 @@
];

if (isset(
$parameters['parameters']['ps_cache_enable'],
$parameters['parameters']['ps_caching'],
$cacheType[$parameters['parameters']['ps_caching']]
)
$parameters['parameters']['ps_cache_enable'],
$parameters['parameters']['ps_caching'],
$cacheType[$parameters['parameters']['ps_caching']]
)
&& true === $parameters['parameters']['ps_cache_enable']
) {
foreach ($cacheType[$parameters['parameters']['ps_caching']] as $type) {
Expand Down
3 changes: 2 additions & 1 deletion classes/Access.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public static function getRoles($idProfile)
* @param string $authSlug Slug
*
* @return string Tab ID
*
* @todo: Find out if we should return an int instead. (breaking change)
*/
public static function findIdTabByAuthSlug($authSlug)
Expand Down Expand Up @@ -375,7 +376,7 @@ public function updateLgcAccess($idProfile, $idTab, $lgcAuth, $enabled, $addFrom
');

if (empty($roles)) {
throw new \Exception('Cannot find role slug');
throw new Exception('Cannot find role slug');
}

$res = [];
Expand Down
1 change: 1 addition & 0 deletions classes/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ public static function getAddressIdBySupplierId($id_supplier)
* @param int $id_customer Customer id
*
* @return false|string|null Amount of aliases found
*
* @todo: Find out if we shouldn't be returning an int instead? (breaking change)
*/
public static function aliasExist($alias, $id_address, $id_customer)
Expand Down
36 changes: 18 additions & 18 deletions classes/AddressFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ protected function _checkValidateClassField($className, $fieldName, $isIdField)
$publicProperties = $reflect->getProperties(ReflectionProperty::IS_PUBLIC);
foreach ($publicProperties as $property) {
$propertyName = $property->getName();
if (($propertyName == $fieldName) && ($isIdField ||
(!preg_match('/\bid\b|id_\w+|\bid[A-Z]\w+/', $propertyName)))) {
if (($propertyName == $fieldName) && ($isIdField
|| (!preg_match('/\bid\b|id_\w+|\bid[A-Z]\w+/', $propertyName)))) {
$isValid = true;
}
}
Expand Down Expand Up @@ -179,8 +179,8 @@ protected function _checkLiableAssociation($patternName)
$this->_errorFormatList[] = $this->trans('This association has too many elements.', [], 'Admin.Notifications.Error');
} elseif ($totalNameUsed == 1) {
$associationName[0] = strtolower($associationName[0]);
if (in_array($associationName[0], self::$forbiddenPropertyList) ||
!$this->_checkValidateClassField('Address', $associationName[0], false)) {
if (in_array($associationName[0], self::$forbiddenPropertyList)
|| !$this->_checkValidateClassField('Address', $associationName[0], false)) {
$this->_errorFormatList[] = $this->trans('This name is not allowed.', [], 'Admin.Notifications.Error') . ': ' .
$associationName[0];
}
Expand Down Expand Up @@ -219,7 +219,7 @@ public function checkFormatFields()

$multipleLineFields = explode(self::FORMAT_NEW_LINE, $this->format);
foreach ($multipleLineFields as $lineField) {
if (($patternsName = preg_split(self::_CLEANING_REGEX_, $lineField, -1, PREG_SPLIT_NO_EMPTY))) {
if ($patternsName = preg_split(self::_CLEANING_REGEX_, $lineField, -1, PREG_SPLIT_NO_EMPTY)) {
if (is_array($patternsName)) {
foreach ($patternsName as $patternName) {
if (!in_array($patternName, $usedKeyList)) {
Expand Down Expand Up @@ -354,7 +354,7 @@ public static function cleanOrderedAddress(&$orderedAddressField)
{
foreach ($orderedAddressField as &$line) {
$cleanedLine = '';
if (($keyList = preg_split(self::_CLEANING_REGEX_, $line, -1, PREG_SPLIT_NO_EMPTY))) {
if ($keyList = preg_split(self::_CLEANING_REGEX_, $line, -1, PREG_SPLIT_NO_EMPTY)) {
foreach ($keyList as $key) {
$cleanedLine .= $key . ' ';
}
Expand Down Expand Up @@ -395,9 +395,9 @@ public static function getFormattedAddressFieldsValues($address, $addressFormat,
$tab[$pattern] = '';

// Check if the property exist in both classes
if (($totalName == 2) && class_exists($associateName[0]) &&
property_exists($associateName[0], $associateName[1]) &&
property_exists($address, 'id_' . strtolower($associateName[0]))) {
if (($totalName == 2) && class_exists($associateName[0])
&& property_exists($associateName[0], $associateName[1])
&& property_exists($address, 'id_' . strtolower($associateName[0]))) {
$idFieldName = 'id_' . strtolower($associateName[0]);

if (!isset($temporyObject[$associateName[0]])) {
Expand Down Expand Up @@ -440,7 +440,7 @@ public static function generateAddress(Address $address, $patternRules = [], $ne

$addressText = '';
foreach ($addressFields as $line) {
if (($patternsList = preg_split(self::_CLEANING_REGEX_, $line, -1, PREG_SPLIT_NO_EMPTY))) {
if ($patternsList = preg_split(self::_CLEANING_REGEX_, $line, -1, PREG_SPLIT_NO_EMPTY)) {
$tmpText = '';
foreach ($patternsList as $pattern) {
if (!array_key_exists('avoid', $patternRules) || !in_array($pattern, $patternRules['avoid'])) {
Expand Down Expand Up @@ -473,10 +473,10 @@ public static function generateAddressSmarty($params, &$smarty)
{
return AddressFormat::generateAddress(
$params['address'],
(isset($params['patternRules']) ? $params['patternRules'] : []),
(isset($params['newLine']) ? $params['newLine'] : self::FORMAT_NEW_LINE),
(isset($params['separator']) ? $params['separator'] : ' '),
(isset($params['style']) ? $params['style'] : [])
isset($params['patternRules']) ? $params['patternRules'] : [],
isset($params['newLine']) ? $params['newLine'] : self::FORMAT_NEW_LINE,
isset($params['separator']) ? $params['separator'] : ' ',
isset($params['style']) ? $params['style'] : []
);
}

Expand All @@ -497,8 +497,8 @@ public static function getValidateFields($className)
$publicProperties = $reflect->getProperties(ReflectionProperty::IS_PUBLIC);
foreach ($publicProperties as $property) {
$propertyName = $property->getName();
if ((!in_array($propertyName, AddressFormat::$forbiddenPropertyList)) &&
(!preg_match('#id|id_\w#', $propertyName))) {
if ((!in_array($propertyName, AddressFormat::$forbiddenPropertyList))
&& (!preg_match('#id|id_\w#', $propertyName))) {
$propertyList[] = $propertyName;
}
}
Expand Down Expand Up @@ -532,8 +532,8 @@ public static function getLiableClass($className)
$propertyName = $property->getName();
if (preg_match('#id_\w#', $propertyName) && strlen($propertyName) > 3) {
$nameObject = ucfirst(substr($propertyName, 3));
if (!in_array($nameObject, self::$forbiddenClassList) &&
class_exists($nameObject)) {
if (!in_array($nameObject, self::$forbiddenClassList)
&& class_exists($nameObject)) {
$objectList[$nameObject] = new $nameObject();
}
}
Expand Down
1 change: 1 addition & 0 deletions classes/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function delete()
* @param array $attachments Attachments
*
* @return bool|int Whether the selection has been successfully deleted
*
* @todo: Find out if $return can be initialized with true. (breaking change)
*/
public function deleteSelection(array $attachments)
Expand Down
10 changes: 5 additions & 5 deletions classes/AttributeGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ public function delete()
if (count($toRemove)) {
if (!Db::getInstance()->execute('
DELETE FROM `' . _DB_PREFIX_ . 'attribute_lang`
WHERE `id_attribute` IN (' . implode(',', $toRemove) . ')') ||
!Db::getInstance()->execute('
WHERE `id_attribute` IN (' . implode(',', $toRemove) . ')')
|| !Db::getInstance()->execute('
DELETE FROM `' . _DB_PREFIX_ . 'attribute_shop`
WHERE `id_attribute` IN (' . implode(',', $toRemove) . ')') ||
!Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'attribute` WHERE `id_attribute_group` = ' . (int) $this->id)) {
WHERE `id_attribute` IN (' . implode(',', $toRemove) . ')')
|| !Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'attribute` WHERE `id_attribute_group` = ' . (int) $this->id)) {
return false;
}
}
Expand Down Expand Up @@ -285,7 +285,7 @@ public function setWsProductOptionValues($values)
{
$ids = [];
foreach ($values as $value) {
$ids[] = (int) ($value['id']);
$ids[] = (int) $value['id'];
}
if (!empty($ids)) {
Db::getInstance()->execute(
Expand Down
2 changes: 1 addition & 1 deletion classes/CMS.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function delete()
*
* @return array
*/
public static function getLinks($idLang, $selection = null, $active = true, Link $link = null)
public static function getLinks($idLang, $selection = null, $active = true, ?Link $link = null)
{
if (!$link) {
$link = Context::getContext()->link;
Expand Down
7 changes: 4 additions & 3 deletions classes/CMSCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function update($null_values = false)
*
* @return array Subcategories lite tree
*/
public function recurseLiteCategTree($max_depth = 3, $currentDepth = 0, $id_lang = null, $excluded_ids_array = null, Link $link = null)
public function recurseLiteCategTree($max_depth = 3, $currentDepth = 0, $id_lang = null, $excluded_ids_array = null, ?Link $link = null)
{
if (!$link) {
$link = Context::getContext()->link;
Expand Down Expand Up @@ -166,7 +166,7 @@ public function recurseLiteCategTree($max_depth = 3, $currentDepth = 0, $id_lang
];
}

public static function getRecurseCategory($id_lang = null, $current = 1, $active = 1, $links = 0, Link $link = null)
public static function getRecurseCategory($id_lang = null, $current = 1, $active = 1, $links = 0, ?Link $link = null)
{
if (!$link) {
$link = Context::getContext()->link;
Expand Down Expand Up @@ -520,7 +520,7 @@ public static function getLinkRewrite($id_cms_category, $id_lang)
return $result['link_rewrite'];
}

public function getLink(Link $link = null)
public function getLink(?Link $link = null)
{
if (!$link) {
$link = Context::getContext()->link;
Expand Down Expand Up @@ -621,6 +621,7 @@ public function updatePosition($way, $position)
if (!isset($moved_category) || !isset($position)) {
return false;
}

// < and > statements rather than BETWEEN operator
// since BETWEEN is treated differently according to databases
return Db::getInstance()->execute('
Expand Down
28 changes: 14 additions & 14 deletions classes/Carrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ public function delete()
}
Carrier::cleanPositions();

return Db::getInstance()->delete('cart_rule_carrier', 'id_carrier = ' . (int) $this->id) &&
Db::getInstance()->delete('module_carrier', 'id_reference = ' . (int) $this->id_reference) &&
$this->deleteTaxRulesGroup(Shop::getShops(true, null, true));
return Db::getInstance()->delete('cart_rule_carrier', 'id_carrier = ' . (int) $this->id)
&& Db::getInstance()->delete('module_carrier', 'id_reference = ' . (int) $this->id_reference)
&& $this->deleteTaxRulesGroup(Shop::getShops(true, null, true));
}

/**
Expand Down Expand Up @@ -708,13 +708,13 @@ public static function getCarriersForOrder($id_zone, $groups = null, $cart = nul
$shipping_method = $carrier->getShippingMethod();
if ($shipping_method != Carrier::SHIPPING_METHOD_FREE) {
// Get only carriers that are compliant with shipping method
if (($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT && $carrier->getMaxDeliveryPriceByWeight($id_zone) === false)) {
if ($shipping_method == Carrier::SHIPPING_METHOD_WEIGHT && $carrier->getMaxDeliveryPriceByWeight($id_zone) === false) {
$error[$carrier->id] = Carrier::SHIPPING_WEIGHT_EXCEPTION;
unset($result[$k]);

continue;
}
if (($shipping_method == Carrier::SHIPPING_METHOD_PRICE && $carrier->getMaxDeliveryPriceByPrice($id_zone) === false)) {
if ($shipping_method == Carrier::SHIPPING_METHOD_PRICE && $carrier->getMaxDeliveryPriceByPrice($id_zone) === false) {
$error[$carrier->id] = Carrier::SHIPPING_PRICE_EXCEPTION;
unset($result[$k]);

Expand Down Expand Up @@ -1046,7 +1046,7 @@ public function copyCarrierData($old_id)
');
}

//Copy default carrier
// Copy default carrier
if (Configuration::get('PS_CARRIER_DEFAULT') == $old_id) {
Configuration::updateValue('PS_CARRIER_DEFAULT', (int) $this->id);
}
Expand Down Expand Up @@ -1193,7 +1193,7 @@ public function getRangeSuffix($currency = null)
*
* @return int TaxrulesGroup ID
*/
public function getIdTaxRulesGroup(Context $context = null)
public function getIdTaxRulesGroup(?Context $context = null)
{
return Carrier::getIdTaxRulesGroupByIdCarrier((int) $this->id, $context);
}
Expand All @@ -1207,7 +1207,7 @@ public function getIdTaxRulesGroup(Context $context = null)
* @return int TaxRulesGroup ID
* false if not found
*/
public static function getIdTaxRulesGroupByIdCarrier($id_carrier, Context $context = null)
public static function getIdTaxRulesGroupByIdCarrier($id_carrier, ?Context $context = null)
{
if (!$context) {
$context = Context::getContext();
Expand Down Expand Up @@ -1271,7 +1271,7 @@ public function setTaxRulesGroup($id_tax_rules_group, $all_shops = false)
*
* @return bool Whether the TaxRulesGroup has been successfully removed from this Carrier
*/
public function deleteTaxRulesGroup(array $shops = null)
public function deleteTaxRulesGroup(?array $shops = null)
{
if (!$shops) {
$shops = Shop::getContextListShopID();
Expand All @@ -1294,7 +1294,7 @@ public function deleteTaxRulesGroup(array $shops = null)
*
* @return float Total Tax rate for this Carrier
*/
public function getTaxesRate(Address $address = null)
public function getTaxesRate(?Address $address = null)
{
if (!$address || !$address->id_country) {
$address = Address::initialize();
Expand Down Expand Up @@ -1460,7 +1460,7 @@ public static function getHigherPosition()
* @param Product $product The id of the product, or an array with at least the package size and weight
* @param int|null $id_warehouse Warehouse ID - not used anymore
* @param int|null $id_address_delivery Delivery Address ID
* @param int|null$id_shop Shop ID
* @param int|null $id_shop Shop ID
* @param CartCore|null $cart Cart object
* @param array|null $error contain an error message if an error occurs
*
Expand Down Expand Up @@ -1522,15 +1522,15 @@ public static function getAvailableCarrierList(Product $product, $id_warehouse =

$carrier_list = [];
if (!empty($carriers_for_product)) {
//the product is linked with carriers
foreach ($carriers_for_product as $carrier) { //check if the linked carriers are available in current zone
// the product is linked with carriers
foreach ($carriers_for_product as $carrier) { // check if the linked carriers are available in current zone
if (Carrier::checkCarrierZone($carrier['id_carrier'], $id_zone)) {
$carrier_list[$carrier['id_carrier']] = $carrier['id_carrier'];
}
}
if (empty($carrier_list)) {
return [];
}//no linked carrier are available for this zone
}// no linked carrier are available for this zone
}

$available_carrier_list = [];
Expand Down
Loading

0 comments on commit 0e129d2

Please sign in to comment.