From 40eb05aeac208d0ec7e10d91b6da5f3fc36958ed Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Mon, 19 Oct 2020 17:25:04 +0200 Subject: [PATCH] Fixed errors on PHPStan Level 4 --- classes/Carrier.php | 2 +- classes/Cart.php | 4 +- classes/CartRule.php | 2 +- classes/Context.php | 10 +- classes/ObjectModel.php | 2 +- classes/PrestaShopCollection.php | 2 +- classes/SpecificPriceRule.php | 7 +- classes/Tools.php | 4 +- classes/controller/Controller.php | 2 +- classes/order/Order.php | 2 +- classes/shop/Shop.php | 2 +- composer.json | 1 + phpstan.neon.dist | 1 - .../Admin/AbstractAdminQueryBuilder.php | 4 +- src/Adapter/Admin/PagePreference.php | 10 +- .../GetCmsPageCategoryForEditingHandler.php | 14 +- .../UpdateCartAddressesHandler.php | 12 +- .../BulkDeleteCartRuleHandler.php | 2 +- .../CommandHandler/DeleteCartRuleHandler.php | 2 +- .../BulkDeleteCatalogPriceRuleHandler.php | 2 +- .../DeleteCatalogPriceRuleHandler.php | 2 +- src/Adapter/Category/CategoryDataProvider.php | 23 ++- src/Adapter/Configuration.php | 16 +- .../CommandHandler/EditCustomerHandler.php | 11 +- src/Adapter/Debug/DebugMode.php | 27 ++-- src/Adapter/Debug/DebugModeConfiguration.php | 4 +- .../Domain/AbstractObjectModelHandler.php | 6 +- src/Adapter/EntityMapper.php | 2 +- src/Adapter/Hook/HookDispatcher.php | 5 +- .../Import/Handler/ProductImportHandler.php | 2 +- src/Adapter/Import/ImportDataFormatter.php | 4 +- src/Adapter/LegacyContext.php | 4 +- .../Module/AdminModuleDataProvider.php | 4 +- .../Configuration/ModuleSelfConfigurator.php | 2 +- src/Adapter/Module/ModuleZipManager.php | 4 +- .../GetNotificationLastElementsHandler.php | 3 - .../AddOrderFromBackOfficeHandler.php | 3 +- .../UpdateProductInOrderHandler.php | 4 +- src/Adapter/Order/OrderAmountUpdater.php | 2 +- .../GetOrderForViewingHandler.php | 2 +- .../QueryHandler/GetOrderPreviewHandler.php | 2 +- src/Adapter/Order/Refund/OrderSlipCreator.php | 82 +++++++--- .../Presenter/Product/ProductLazyArray.php | 4 - src/Adapter/Product/AdminProductWrapper.php | 5 +- src/Adapter/Product/ProductDataProvider.php | 19 ++- .../GetProductForEditingHandler.php | 8 +- src/Adapter/StockManager.php | 4 +- src/Adapter/SymfonyContainer.php | 2 +- .../Addon/Module/ModuleManagerBuilder.php | 18 ++- src/Core/Addon/Module/ModuleRepository.php | 5 +- src/Core/Cart/Calculator.php | 2 +- src/Core/Cart/Fees.php | 4 +- src/Core/Currency/ExchangeRateProvider.php | 4 +- .../Command/AddManufacturerAddressCommand.php | 2 +- .../EditManufacturerAddressCommand.php | 2 +- .../Currency/ValueObject/ExchangeRate.php | 2 +- .../Customer/Command/EditCustomerCommand.php | 4 +- ...nerateThemeMailTemplatesCommandHandler.php | 2 - .../Command/AddCartRuleToOrderCommand.php | 2 +- .../Command/AbstractProfileCommand.php | 11 +- .../Domain/Profile/ValueObject/ProfileId.php | 2 +- .../Tax/Command/ToggleTaxStatusCommand.php | 2 +- src/Core/Email/EmailLister.php | 4 +- src/Core/Filter/HashMapWhitelistFilter.php | 2 +- src/Core/Foundation/Filesystem/FileSystem.php | 27 ++-- src/Core/Foundation/Version.php | 2 +- .../Language/LanguageRepositoryInterface.php | 2 +- .../CLDR/LocaleDataLayerInterface.php | 2 +- .../Localization/CLDR/LocaleDataSource.php | 2 +- .../Localization/CLDR/LocaleRepository.php | 6 +- src/Core/Localization/CLDR/Reader.php | 16 +- .../Loader/RemoteLocalizationPackLoader.php | 7 +- src/Core/Product/Search/SortOrder.php | 11 +- .../Builder/RepositoryFiltersBuilder.php | 3 - src/Core/Search/SearchParameters.php | 2 - src/Core/Util/BoolParser.php | 2 +- .../Command/UpdateEUTaxruleGroupsCommand.php | 4 +- .../Component/CsvResponse.php | 2 +- .../Admin/CombinationController.php | 2 +- .../AdvancedParameters/ImportController.php | 2 +- .../Improve/Design/MailThemeController.php | 4 - .../International/CurrencyController.php | 2 +- .../Admin/Improve/ModuleController.php | 9 +- .../SearchParametersResolver.php | 1 - .../Entity/Repository/LangRepository.php | 15 +- .../Entity/Repository/LogRepository.php | 4 - .../Entity/Repository/NormalizeFieldTrait.php | 2 +- .../EventListener/ModuleActivatedListener.php | 5 - src/PrestaShopBundle/Install/Install.php | 149 +++++++++--------- src/PrestaShopBundle/Install/Upgrade.php | 21 +-- src/PrestaShopBundle/Install/XmlLoader.php | 8 +- .../Kernel/ModuleRepositoryFactory.php | 2 +- .../config/services/adapter/admin.yml | 1 + .../Security/Annotation/AdminSecurity.php | 4 +- .../Security/Annotation/ModuleActivated.php | 8 +- .../Service/ProductService.php | 8 +- .../Service/TranslationService.php | 6 +- .../Translation/View/TreeBuilder.php | 3 +- .../Twig/TranslationsExtension.php | 4 +- 99 files changed, 382 insertions(+), 377 deletions(-) diff --git a/classes/Carrier.php b/classes/Carrier.php index 0067290b1eb20..daeec982c145b 100644 --- a/classes/Carrier.php +++ b/classes/Carrier.php @@ -1327,7 +1327,7 @@ public function getTaxesRate(Address $address = null) * * @param Address $address Address * - * @return TaxCalculator Tax calculator object + * @return TaxCalculator|AverageTaxOfProductsTaxCalculator Tax calculator object */ public function getTaxCalculator(Address $address, $id_order = null, $use_average_tax_of_products = false) { diff --git a/classes/Cart.php b/classes/Cart.php index c700a048d1d94..965490c7173ad 100755 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -1328,7 +1328,7 @@ public function containsProduct($id_product, $id_product_attribute = 0, $id_cust * @param bool $skipAvailabilityCheckOutOfStock * @param bool $preserveGiftRemoval * - * @return bool Whether the quantity has been successfully updated + * @return bool|int Whether the quantity has been successfully updated */ public function updateQty( $quantity, @@ -4268,7 +4268,7 @@ public static function replaceZeroByShopName($echo, $tr) /** * Duplicate this Cart in the database. * - * @return array Duplicated cart, with success bool + * @return array|bool Duplicated cart, with success bool */ public function duplicate() { diff --git a/classes/CartRule.php b/classes/CartRule.php index aa13eefd18599..e6c9d5e3d65e2 100755 --- a/classes/CartRule.php +++ b/classes/CartRule.php @@ -269,7 +269,7 @@ public function delete() $r &= Db::getInstance()->delete('cart_rule_product_rule_value', 'NOT EXISTS (SELECT 1 FROM `' . _DB_PREFIX_ . 'cart_rule_product_rule` WHERE `' . _DB_PREFIX_ . 'cart_rule_product_rule_value`.`id_product_rule` = `' . _DB_PREFIX_ . 'cart_rule_product_rule`.`id_product_rule`)'); - return $r; + return (bool) $r; } /** diff --git a/classes/Context.php b/classes/Context.php index 8f853599fdc8d..1ecad6d73929b 100644 --- a/classes/Context.php +++ b/classes/Context.php @@ -58,7 +58,7 @@ class ContextCore /** @var Country */ public $country; - /** @var Employee */ + /** @var Employee|null */ public $employee; /** @var AdminController|FrontController */ @@ -70,13 +70,13 @@ class ContextCore /** @var Language|InstallLanguage */ public $language; - /** @var Currency */ + /** @var Currency|null */ public $currency; /** * Current locale instance. * - * @var Locale + * @var Locale|null */ public $currentLocale; @@ -245,7 +245,7 @@ public function getDevice() } /** - * @return Locale + * @return Locale|null */ public function getCurrentLocale() { @@ -287,7 +287,7 @@ protected function checkMobileContext() /** * Get a singleton instance of Context object. * - * @return Context + * @return Context|null */ public static function getContext() { diff --git a/classes/ObjectModel.php b/classes/ObjectModel.php index 80960c945ef93..0ea087406b83d 100644 --- a/classes/ObjectModel.php +++ b/classes/ObjectModel.php @@ -1095,7 +1095,7 @@ public function validateFieldsLang($die = true, $errorReturn = false) * @param array $skip array of fields to skip * @param bool $human_errors if true, uses more descriptive, translatable error strings * - * @return true|string true or error message string + * @return bool|string true or error message string * * @throws PrestaShopException */ diff --git a/classes/PrestaShopCollection.php b/classes/PrestaShopCollection.php index 491e10cfa9625..055b86f78f34f 100644 --- a/classes/PrestaShopCollection.php +++ b/classes/PrestaShopCollection.php @@ -389,7 +389,7 @@ public function getAll($display_query = false) /** * Retrieve the first result. * - * @return ObjectModel|false + * @return ObjectModel|bool */ public function getFirst() { diff --git a/classes/SpecificPriceRule.php b/classes/SpecificPriceRule.php index bd27eb7301f4e..fe72e46ab05b3 100644 --- a/classes/SpecificPriceRule.php +++ b/classes/SpecificPriceRule.php @@ -73,12 +73,17 @@ class SpecificPriceRuleCore extends ObjectModel ], ]; + /** + * @return bool + * + * @throws PrestaShopException + */ public function delete() { $this->deleteConditions(); Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . 'specific_price WHERE id_specific_price_rule=' . (int) $this->id); - return parent::delete(); + return (bool) parent::delete(); } public function deleteConditions() diff --git a/classes/Tools.php b/classes/Tools.php index 39488ed16dae7..88f14b00a797e 100644 --- a/classes/Tools.php +++ b/classes/Tools.php @@ -858,12 +858,12 @@ public static function displayPriceSmarty($params, &$smarty) * * @deprecated since 1.7.4 use convertPriceToCurrency() * - * @param float $price Product price + * @param float|null $price Product price * @param object|array $currency Current currency object * @param bool $to_currency convert to currency or from currency to default currency * @param Context $context * - * @return float Price + * @return float|null Price */ public static function convertPrice($price, $currency = null, $to_currency = true, Context $context = null) { diff --git a/classes/controller/Controller.php b/classes/controller/Controller.php index 23e79ea8561bf..3635e14ad87e4 100644 --- a/classes/controller/Controller.php +++ b/classes/controller/Controller.php @@ -808,7 +808,7 @@ public function getParameter($parameterId) /** * Gets the dependency container. * - * @return ContainerBuilder + * @return ContainerBuilder|null */ public function getContainer() { diff --git a/classes/order/Order.php b/classes/order/Order.php index 7ee5c3ef76401..9d86da390b8a4 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -2327,7 +2327,7 @@ public function getWarehouseList() /** * @since 1.5.0.4 * - * @return OrderState or null if Order haven't a state + * @return OrderState|null null if Order haven't a state */ public function getCurrentOrderState() { diff --git a/classes/shop/Shop.php b/classes/shop/Shop.php index f8b5dc01613d1..101adf8a393e8 100644 --- a/classes/shop/Shop.php +++ b/classes/shop/Shop.php @@ -832,7 +832,7 @@ public static function getShopsCollection($active = true, $id_shop_group = null) * * @param int $shop_id * - * @return array + * @return array|bool */ public static function getShop($shop_id) { diff --git a/composer.json b/composer.json index 8ece2d7cd1852..7b19c128b4194 100644 --- a/composer.json +++ b/composer.json @@ -12,6 +12,7 @@ "ext-intl": "*", "ext-json": "*", "ext-mbstring": "*", + "ext-simplexml": "*", "ext-zip": "*", "beberlei/doctrineextensions": "^1.0", "composer/ca-bundle": "^1.0", diff --git a/phpstan.neon.dist b/phpstan.neon.dist index bc15872b37023..d120134498201 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -6,7 +6,6 @@ parameters: - src ignoreErrors: - '#^Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition\:\:#' - - '#^Property ContextCore::\$smarty \(Smarty\) does not accept null\.#' - '#^Unsafe usage of new static\(\)\.$#' universalObjectCratesClasses: - Cookie diff --git a/src/Adapter/Admin/AbstractAdminQueryBuilder.php b/src/Adapter/Admin/AbstractAdminQueryBuilder.php index c99697cd656bf..ca0c206b4375e 100644 --- a/src/Adapter/Admin/AbstractAdminQueryBuilder.php +++ b/src/Adapter/Admin/AbstractAdminQueryBuilder.php @@ -117,7 +117,7 @@ private function compileSqlWhere(array $whereArray) * Format example for $order: * $order = array('name ASC', 'id_product DESC'); * - * @param array> $select + * @param array|string> $select * @param array $table * @param array $where * @param array $groupBy @@ -135,7 +135,7 @@ protected function compileSqlQuery(array $select, array $table, array $where = [ // SELECT $s = []; foreach ($select as $alias => $field) { - $a = is_string($alias) ? ' AS `' . $alias . '`' : ''; + $a = ' AS `' . $alias . '`'; if (is_array($field)) { if (isset($field['table'])) { $s[] = ' ' . $field['table'] . '.`' . $field['field'] . '` ' . $a; diff --git a/src/Adapter/Admin/PagePreference.php b/src/Adapter/Admin/PagePreference.php index a98b0b701c75c..e964ee2bd1add 100644 --- a/src/Adapter/Admin/PagePreference.php +++ b/src/Adapter/Admin/PagePreference.php @@ -44,12 +44,17 @@ */ class PagePreference implements AdminPagePreferenceInterface { + /** + * @var bool + */ + private $isDebug; + /** * @var SessionInterface */ private $session; - public function __construct(SessionInterface $session) + public function __construct(SessionInterface $session, bool $isDebug = _PS_MODE_DEV_) { if ($session->isStarted()) { $this->session = $session; @@ -57,6 +62,7 @@ public function __construct(SessionInterface $session) $sessionClass = get_class($session); $this->session = new $sessionClass(new PhpBridgeSessionStorage()); } + $this->isDebug = $isDebug; } /** @@ -93,7 +99,7 @@ public function setTemporaryShouldUseLegacyPage($page, $useLegacy) public function getTemporaryShouldAllowUseLegacyPage($page = null) { // Dev mode: always shown - if (_PS_MODE_DEV_) { + if ($this->isDebug) { return true; } diff --git a/src/Adapter/CMS/PageCategory/QueryHandler/GetCmsPageCategoryForEditingHandler.php b/src/Adapter/CMS/PageCategory/QueryHandler/GetCmsPageCategoryForEditingHandler.php index b654d32ae7c8f..2df16abfc6c4c 100644 --- a/src/Adapter/CMS/PageCategory/QueryHandler/GetCmsPageCategoryForEditingHandler.php +++ b/src/Adapter/CMS/PageCategory/QueryHandler/GetCmsPageCategoryForEditingHandler.php @@ -55,20 +55,20 @@ public function handle(GetCmsPageCategoryForEditing $query) throw new CmsPageCategoryNotFoundException(sprintf('Cms category object with id "%s" has not been found', $query->getCmsPageCategoryId()->getValue())); } - $shopIds = is_array($cmsPageCategory->getAssociatedShops()) ? $cmsPageCategory->getAssociatedShops() : []; + $shopIds = $cmsPageCategory->getAssociatedShops(); } catch (PrestaShopException $exception) { throw new CmsPageCategoryException(sprintf('An error occurred when retrieving cms page category data with id %s', $query->getCmsPageCategoryId()->getValue()), 0, $exception); } return new EditableCmsPageCategory( - is_array($cmsPageCategory->name) ? $cmsPageCategory->name : [], + $cmsPageCategory->name, $cmsPageCategory->active, (int) $cmsPageCategory->id_parent, - is_array($cmsPageCategory->description) ? $cmsPageCategory->description : [], - is_array($cmsPageCategory->meta_description) ? $cmsPageCategory->meta_description : [], - is_array($cmsPageCategory->meta_keywords) ? $cmsPageCategory->meta_keywords : [], - is_array($cmsPageCategory->meta_title) ? $cmsPageCategory->meta_title : [], - is_array($cmsPageCategory->link_rewrite) ? $cmsPageCategory->link_rewrite : [], + $cmsPageCategory->description, + $cmsPageCategory->meta_description, + $cmsPageCategory->meta_keywords, + $cmsPageCategory->meta_title, + $cmsPageCategory->link_rewrite, $shopIds ); } diff --git a/src/Adapter/Cart/CommandHandler/UpdateCartAddressesHandler.php b/src/Adapter/Cart/CommandHandler/UpdateCartAddressesHandler.php index 683f0acd7b47d..c497e9f7ca339 100644 --- a/src/Adapter/Cart/CommandHandler/UpdateCartAddressesHandler.php +++ b/src/Adapter/Cart/CommandHandler/UpdateCartAddressesHandler.php @@ -75,14 +75,10 @@ public function handle(UpdateCartAddressesCommand $command) */ private function fillCartWithCommandData(Cart $cart, UpdateCartAddressesCommand $command): void { - if ($command->getNewDeliveryAddressId()) { - // updateDeliveryAddressId() will actually allow the address change to be impacted on all - // other data linked to the cart delivery address (and it doesn't modify the invoice address) - $cart->updateDeliveryAddressId((int) $cart->id_address_delivery, $command->getNewDeliveryAddressId()->getValue()); - } + // updateDeliveryAddressId() will actually allow the address change to be impacted on all + // other data linked to the cart delivery address (and it doesn't modify the invoice address) + $cart->updateDeliveryAddressId((int) $cart->id_address_delivery, $command->getNewDeliveryAddressId()->getValue()); - if ($command->getNewInvoiceAddressId()) { - $cart->id_address_invoice = $command->getNewInvoiceAddressId()->getValue(); - } + $cart->id_address_invoice = $command->getNewInvoiceAddressId()->getValue(); } } diff --git a/src/Adapter/CartRule/CommandHandler/BulkDeleteCartRuleHandler.php b/src/Adapter/CartRule/CommandHandler/BulkDeleteCartRuleHandler.php index 7bcfcd6b4e60f..d1b75079539b7 100644 --- a/src/Adapter/CartRule/CommandHandler/BulkDeleteCartRuleHandler.php +++ b/src/Adapter/CartRule/CommandHandler/BulkDeleteCartRuleHandler.php @@ -50,7 +50,7 @@ public function handle(BulkDeleteCartRuleCommand $command): void try { $cartRule = $this->getCartRule($cartRuleId); - if (null === $this->deleteCartRule($cartRule)) { + if (!$this->deleteCartRule($cartRule)) { $errors[] = $cartRuleId->getValue(); } } catch (CartRuleException $e) { diff --git a/src/Adapter/CartRule/CommandHandler/DeleteCartRuleHandler.php b/src/Adapter/CartRule/CommandHandler/DeleteCartRuleHandler.php index 71f7a0108f059..4206a005d4ca7 100644 --- a/src/Adapter/CartRule/CommandHandler/DeleteCartRuleHandler.php +++ b/src/Adapter/CartRule/CommandHandler/DeleteCartRuleHandler.php @@ -46,7 +46,7 @@ public function handle(DeleteCartRuleCommand $command): void $cartRuleId = $command->getCartRuleId(); $cartRule = $this->getCartRule($cartRuleId); - if (null === $this->deleteCartRule($cartRule)) { + if (!$this->deleteCartRule($cartRule)) { throw new CannotDeleteCartRuleException( sprintf( 'Cannot delete SpecificPriceRule object with id "%s".', diff --git a/src/Adapter/CatalogPriceRule/CommandHandler/BulkDeleteCatalogPriceRuleHandler.php b/src/Adapter/CatalogPriceRule/CommandHandler/BulkDeleteCatalogPriceRuleHandler.php index 7f5efe1994f59..48bd217504fc7 100644 --- a/src/Adapter/CatalogPriceRule/CommandHandler/BulkDeleteCatalogPriceRuleHandler.php +++ b/src/Adapter/CatalogPriceRule/CommandHandler/BulkDeleteCatalogPriceRuleHandler.php @@ -44,7 +44,7 @@ public function handle(BulkDeleteCatalogPriceRuleCommand $command) foreach ($catalogPriceRuleId = $command->getCatalogPriceRuleIds() as $catalogPriceRuleId) { $specificPriceRule = $this->getSpecificPriceRule($catalogPriceRuleId); - if (null === $this->deleteSpecificPriceRule($specificPriceRule)) { + if (!$this->deleteSpecificPriceRule($specificPriceRule)) { throw new CannotDeleteCatalogPriceRuleException(sprintf('Cannot delete SpecificPriceRule object with id "%s".', $catalogPriceRuleId->getValue()), CannotDeleteCatalogPriceRuleException::FAILED_BULK_DELETE); } } diff --git a/src/Adapter/CatalogPriceRule/CommandHandler/DeleteCatalogPriceRuleHandler.php b/src/Adapter/CatalogPriceRule/CommandHandler/DeleteCatalogPriceRuleHandler.php index 4b606d2f94eac..842db7cfc9101 100644 --- a/src/Adapter/CatalogPriceRule/CommandHandler/DeleteCatalogPriceRuleHandler.php +++ b/src/Adapter/CatalogPriceRule/CommandHandler/DeleteCatalogPriceRuleHandler.php @@ -44,7 +44,7 @@ public function handle(DeleteCatalogPriceRuleCommand $command) $catalogPriceRuleId = $command->getCatalogPriceRuleId(); $specificPriceRule = $this->getSpecificPriceRule($catalogPriceRuleId); - if (null === $this->deleteSpecificPriceRule($specificPriceRule)) { + if (!$this->deleteSpecificPriceRule($specificPriceRule)) { throw new CannotDeleteCatalogPriceRuleException(sprintf('Cannot delete SpecificPriceRule object with id "%s".', $catalogPriceRuleId->getValue()), CannotDeleteCatalogPriceRuleException::FAILED_DELETE); } } diff --git a/src/Adapter/Category/CategoryDataProvider.php b/src/Adapter/Category/CategoryDataProvider.php index 81ac418792280..472a1d608ca60 100644 --- a/src/Adapter/Category/CategoryDataProvider.php +++ b/src/Adapter/Category/CategoryDataProvider.php @@ -28,6 +28,7 @@ use Category; use Context; +use LogicException; use ObjectModel; use PrestaShop\PrestaShop\Adapter\LegacyContext; use Shop; @@ -60,25 +61,22 @@ public function __construct(LegacyContext $context) /** * Get a category. * - * @param null $idCategory - * @param null $idLang - * @param null $idShop + * @param int|null $idCategory + * @param int|null $idLang + * @param int|null $idShop * - * @throws \LogicException If the category id is not set + * @throws LogicException If the category id is not set * * @return Category */ public function getCategory($idCategory = null, $idLang = null, $idShop = null) { if (!$idCategory) { - throw new \LogicException('You need to provide a category id', 5002); + throw new LogicException('You need to provide a category id', 5002); } $category = new Category($idCategory, $idLang, $idShop); - - if ($category) { - $category->image = Context::getContext()->link->getCatImageLink($category->name, $category->id); - } + $category->image = Context::getContext()->link->getCatImageLink($category->name, $category->id); return $category; } @@ -229,10 +227,9 @@ public function getAjaxCategories($query, $limit, $nameAsBreadCrumb = false) $query = "AND cl.name LIKE '%" . pSQL($query) . "%'"; } + $limitParam = ''; if (is_int($limit)) { - $limit = 'LIMIT ' . $limit; - } else { - $limit = ''; + $limitParam = 'LIMIT ' . $limit; } $searchCategories = Category::getAllCategoriesName( @@ -243,7 +240,7 @@ public function getAjaxCategories($query, $limit, $nameAsBreadCrumb = false) true, $query, '', - $limit + $limitParam ); $results = []; diff --git a/src/Adapter/Configuration.php b/src/Adapter/Configuration.php index 524d5564fe8db..a21d5a4efeb62 100644 --- a/src/Adapter/Configuration.php +++ b/src/Adapter/Configuration.php @@ -125,12 +125,13 @@ public function get($key, $default = null, ShopConstraint $shopConstraint = null } $hasKey = ConfigurationLegacy::hasKey($key, null, $shopGroupId); - if ($hasKey || $isStrict) { - return $hasKey ? ConfigurationLegacy::get($key, null, $shopGroupId) : null; + if ($hasKey) { + return ConfigurationLegacy::get($key, null, $shopGroupId); } - if ($hasKey = ConfigurationLegacy::hasKey($key) || $isStrict) { - return $hasKey ? ConfigurationLegacy::get($key) : null; + $hasKey = ConfigurationLegacy::hasKey($key); + if ($hasKey) { + return ConfigurationLegacy::get($key); } return $default; @@ -180,7 +181,10 @@ public function set($key, $value, ShopConstraint $shopConstraint = null, array $ } /** - * {@inheritdoc} + * @param string $key + * @param ShopConstraint|null $shopConstraint + * + * @return bool */ public function has($key, ShopConstraint $shopConstraint = null) { @@ -194,7 +198,7 @@ public function has($key, ShopConstraint $shopConstraint = null) } $hasKey = ConfigurationLegacy::hasKey($key, null, $shopGroupId); - if ($hasKey || $isStrict) { + if ($hasKey) { return $hasKey; } diff --git a/src/Adapter/Customer/CommandHandler/EditCustomerHandler.php b/src/Adapter/Customer/CommandHandler/EditCustomerHandler.php index f67af9637620d..d37591198300d 100644 --- a/src/Adapter/Customer/CommandHandler/EditCustomerHandler.php +++ b/src/Adapter/Customer/CommandHandler/EditCustomerHandler.php @@ -238,16 +238,7 @@ private function assertCustomerCanAccessDefaultGroup(Customer $customer, EditCus return; } - $defaultGroupId = null !== $command->getDefaultGroupId() ? - $command->getDefaultGroupId() : - $customer->id_default_group - ; - $groupIds = null !== $command->getGroupIds() ? - $command->getGroupIds() : - $customer->getGroups() - ; - - if (!in_array($defaultGroupId, $groupIds)) { + if (!in_array($command->getDefaultGroupId(), $command->getGroupIds())) { throw new CustomerDefaultGroupAccessException(sprintf('Customer default group with id "%s" must be in access groups', $command->getDefaultGroupId())); } } diff --git a/src/Adapter/Debug/DebugMode.php b/src/Adapter/Debug/DebugMode.php index ddb53bfb199c0..1edccd334eee9 100644 --- a/src/Adapter/Debug/DebugMode.php +++ b/src/Adapter/Debug/DebugMode.php @@ -139,7 +139,7 @@ private function updateDebugModeValueInMainFile($value) * * @param string $value should be "true" or "false" * - * @return int|void Debug mode + * @return int Debug mode */ private function updateDebugModeValueInCustomFile($value) { @@ -147,19 +147,20 @@ private function updateDebugModeValueInCustomFile($value) $cleanedFileContent = php_strip_whitespace($customFileName); $fileContent = Tools::file_get_contents($customFileName); - if (!empty($cleanedFileContent) && preg_match('/define\(\'_PS_MODE_DEV_\', ([a-zA-Z]+)\);/Ui', $cleanedFileContent)) { - $fileContent = preg_replace('/define\(\'_PS_MODE_DEV_\', ([a-zA-Z]+)\);/Ui', 'define(\'_PS_MODE_DEV_\', ' . $value . ');', $fileContent); - - if (!@file_put_contents($customFileName, $fileContent)) { - return self::DEBUG_MODE_ERROR_NO_WRITE_ACCESS_CUSTOM; - } + if (!preg_match('/define\(\'_PS_MODE_DEV_\', ([a-zA-Z]+)\);/Ui', $cleanedFileContent)) { + return self::DEBUG_MODE_ERROR_NO_DEFINITION_FOUND; + } + $fileContent = preg_replace('/define\(\'_PS_MODE_DEV_\', ([a-zA-Z]+)\);/Ui', 'define(\'_PS_MODE_DEV_\', ' . $value . ');', $fileContent); - if (function_exists('opcache_invalidate')) { - opcache_invalidate($customFileName); - } + if (!@file_put_contents($customFileName, $fileContent)) { + return self::DEBUG_MODE_ERROR_NO_WRITE_ACCESS_CUSTOM; + } - return self::DEBUG_MODE_SUCCEEDED; + if (function_exists('opcache_invalidate')) { + opcache_invalidate($customFileName); } + + return self::DEBUG_MODE_SUCCEEDED; } /** @@ -178,8 +179,8 @@ private function changePsModeDevValue($value) if ($this->isMainDefinesReadable()) { return $this->updateDebugModeValueInMainFile($value); - } else { - return self::DEBUG_MODE_ERROR_NO_READ_ACCESS; } + + return self::DEBUG_MODE_ERROR_NO_READ_ACCESS; } } diff --git a/src/Adapter/Debug/DebugModeConfiguration.php b/src/Adapter/Debug/DebugModeConfiguration.php index b9335985cfb1f..12ba3a4d2aea3 100644 --- a/src/Adapter/Debug/DebugModeConfiguration.php +++ b/src/Adapter/Debug/DebugModeConfiguration.php @@ -148,7 +148,7 @@ public function validateConfiguration(array $configuration) * * @param bool $enableStatus * - * @return int|void Status of update + * @return int|null Status of update */ private function updateDebugMode($enableStatus) { @@ -157,5 +157,7 @@ private function updateDebugMode($enableStatus) if ($enableStatus !== $currentDebugMode) { return (true === $enableStatus) ? $this->debugMode->enable() : $this->debugMode->disable(); } + + return null; } } diff --git a/src/Adapter/Domain/AbstractObjectModelHandler.php b/src/Adapter/Domain/AbstractObjectModelHandler.php index 51fd4f0c0e00a..d8084b6cb321a 100644 --- a/src/Adapter/Domain/AbstractObjectModelHandler.php +++ b/src/Adapter/Domain/AbstractObjectModelHandler.php @@ -70,10 +70,8 @@ protected function associateWithShops(ObjectModel $objectModel, array $shopAssoc } } - $excludeShopsCondtion = $excludeIds ? - ' AND id_shop NOT IN (' . implode(', ', array_map('intval', $excludeIds)) . ')' : - '' - ; + $excludeShopsCondtion = + ' AND id_shop NOT IN (' . implode(', ', array_map('intval', $excludeIds)) . ')'; Db::getInstance()->delete( $tableName . '_shop', diff --git a/src/Adapter/EntityMapper.php b/src/Adapter/EntityMapper.php index f9037c23bdd13..12a8e83620ec5 100644 --- a/src/Adapter/EntityMapper.php +++ b/src/Adapter/EntityMapper.php @@ -45,7 +45,7 @@ class EntityMapper * @param int $id * @param int $id_lang * @param ObjectModel $entity - * @param array $entity_defs + * @param array $entity_defs * @param int $id_shop * @param bool $should_cache_objects * diff --git a/src/Adapter/Hook/HookDispatcher.php b/src/Adapter/Hook/HookDispatcher.php index 8cfe1fc78c788..c2f0292f46d16 100644 --- a/src/Adapter/Hook/HookDispatcher.php +++ b/src/Adapter/Hook/HookDispatcher.php @@ -140,10 +140,7 @@ protected function doDispatch($listeners, $eventName, Event $event) if ($event instanceof RenderingHookEvent) { $listenerName = $event->popListener() ?: $listener[1]; - $eventContent = $event->popContent(); - $this->renderingContent[$listenerName] = (!is_string($eventContent) || strlen($eventContent) > strlen($obContent)) - ? $eventContent - : $obContent; + $this->renderingContent[$listenerName] = $event->popContent(); } if ($event->isPropagationStopped()) { $this->propagationStoppedCalledBy = $listener; diff --git a/src/Adapter/Import/Handler/ProductImportHandler.php b/src/Adapter/Import/Handler/ProductImportHandler.php index aea7dc1bd15ea..961d6938a404c 100644 --- a/src/Adapter/Import/Handler/ProductImportHandler.php +++ b/src/Adapter/Import/Handler/ProductImportHandler.php @@ -1323,7 +1323,7 @@ private function saveStock(Product $product, $validateOnly, $productExists) if ($product->depends_on_stock == 1) { $stockManager = StockManagerFactory::getManager(); $price = str_replace(',', '.', $product->wholesale_price); - if (!is_array($price) && $price == 0) { + if ($price == 0) { $price = 0.000001; } $price = round(floatval($price), 6); diff --git a/src/Adapter/Import/ImportDataFormatter.php b/src/Adapter/Import/ImportDataFormatter.php index bd910cb976d9a..087365b0434de 100644 --- a/src/Adapter/Import/ImportDataFormatter.php +++ b/src/Adapter/Import/ImportDataFormatter.php @@ -97,7 +97,7 @@ public function createMultiLangField($field) /** * Split the field by separator. * - * @param string $field + * @param string|null $field * @param string $separator * * @return array @@ -108,7 +108,7 @@ public function split($field, $separator) return []; } - if (is_null($separator) || trim($separator) == '') { + if (trim($separator) == '') { $separator = ','; } diff --git a/src/Adapter/LegacyContext.php b/src/Adapter/LegacyContext.php index e526137747c43..54c839dd6e1dc 100644 --- a/src/Adapter/LegacyContext.php +++ b/src/Adapter/LegacyContext.php @@ -44,7 +44,7 @@ */ class LegacyContext { - /** @var Currency */ + /** @var Currency|null */ private $employeeCurrency; /** @var string Contains the base uri for mail themes (by default https://domain.com/mails/themes/). Used for mails assets. */ @@ -282,7 +282,7 @@ public function getEmployeeLanguageIso() /** * Returns Currency set for the current employee. * - * @return Currency + * @return Currency|null */ public function getEmployeeCurrency() { diff --git a/src/Adapter/Module/AdminModuleDataProvider.php b/src/Adapter/Module/AdminModuleDataProvider.php index 13b362590c8cd..7695034c1b05c 100644 --- a/src/Adapter/Module/AdminModuleDataProvider.php +++ b/src/Adapter/Module/AdminModuleDataProvider.php @@ -103,12 +103,12 @@ class AdminModuleDataProvider implements ModuleInterface private $moduleProvider; /** - * @var CacheProvider + * @var CacheProvider|null */ private $cacheProvider; /** - * @var Employee + * @var Employee|null */ private $employee; diff --git a/src/Adapter/Module/Configuration/ModuleSelfConfigurator.php b/src/Adapter/Module/Configuration/ModuleSelfConfigurator.php index 835d3e29579f6..de0e221bf3c18 100644 --- a/src/Adapter/Module/Configuration/ModuleSelfConfigurator.php +++ b/src/Adapter/Module/Configuration/ModuleSelfConfigurator.php @@ -285,7 +285,7 @@ protected function convertRelativeToAbsolutePaths($file) * Finds and returns filepath from a config key in the YML config file. * Can be a string of a value of "file" key. * - * @param array $data + * @param array|string $data * * @return string * diff --git a/src/Adapter/Module/ModuleZipManager.php b/src/Adapter/Module/ModuleZipManager.php index c9a07bf27de1b..375fe15199cac 100644 --- a/src/Adapter/Module/ModuleZipManager.php +++ b/src/Adapter/Module/ModuleZipManager.php @@ -98,7 +98,7 @@ public function getName($source) $sandboxPath = $this->getSandboxPath($source); $zip = new ZipArchive(); - if ($zip->open($source) === false || !$zip->extractTo($sandboxPath) || !$zip->close()) { + if ($zip->open($source) !== true || !$zip->extractTo($sandboxPath) || !$zip->close()) { throw new Exception($this->translator->trans('Cannot extract module in %path% to get its name. %error%', ['%path%' => $sandboxPath, '%error%' => $zip->getStatusString()], 'Admin.Modules.Notification')); } @@ -174,7 +174,7 @@ public function storeInModulesFolder($source) /** * @param string $source * - * @return string|null + * @return string */ private function getSandboxPath($source) { diff --git a/src/Adapter/Notification/QueryHandler/GetNotificationLastElementsHandler.php b/src/Adapter/Notification/QueryHandler/GetNotificationLastElementsHandler.php index 83f24e2b2cd71..9577bcb1600ea 100644 --- a/src/Adapter/Notification/QueryHandler/GetNotificationLastElementsHandler.php +++ b/src/Adapter/Notification/QueryHandler/GetNotificationLastElementsHandler.php @@ -104,13 +104,10 @@ protected function isDisplayed(string $type): bool switch ($type) { case 'customer': return $this->configuration['show_notifs_new_customers'] ?: false; - break; case 'customer_message': return $this->configuration['show_notifs_new_messages'] ?: false; - break; case 'order': return $this->configuration['show_notifs_new_orders'] ?: false; - break; } return false; diff --git a/src/Adapter/Order/CommandHandler/AddOrderFromBackOfficeHandler.php b/src/Adapter/Order/CommandHandler/AddOrderFromBackOfficeHandler.php index 714a2b2659afd..77190f9b9305b 100644 --- a/src/Adapter/Order/CommandHandler/AddOrderFromBackOfficeHandler.php +++ b/src/Adapter/Order/CommandHandler/AddOrderFromBackOfficeHandler.php @@ -72,7 +72,6 @@ public function __construct(ContextStateManager $contextStateManager) */ public function handle(AddOrderFromBackOfficeCommand $command) { - /** @var PaymentModule $paymentModule */ $paymentModule = !Configuration::get('PS_CATALOG_MODE') ? Module::getInstanceByName($command->getPaymentModuleName()) : new BoOrderCore(); @@ -80,7 +79,7 @@ public function handle(AddOrderFromBackOfficeCommand $command) if (false === $paymentModule) { throw new OrderException(sprintf('Payment method "%s" does not exist.', $paymentModule)); } - + /** @var PaymentModule $paymentModule */ $cart = new Cart($command->getCartId()->getValue()); $this->assertAddressesAreNotDisabled($cart); diff --git a/src/Adapter/Order/CommandHandler/UpdateProductInOrderHandler.php b/src/Adapter/Order/CommandHandler/UpdateProductInOrderHandler.php index 2d6d72a3c2e72..d97414811439c 100644 --- a/src/Adapter/Order/CommandHandler/UpdateProductInOrderHandler.php +++ b/src/Adapter/Order/CommandHandler/UpdateProductInOrderHandler.php @@ -157,9 +157,7 @@ private function assertProductCanBeUpdated( throw new OrderException('Invalid price'); } - if (!is_array($command->getQuantity()) - && !Validate::isUnsignedInt($command->getQuantity()) - ) { + if (!Validate::isUnsignedInt($command->getQuantity())) { throw new OrderException('Invalid quantity'); } diff --git a/src/Adapter/Order/OrderAmountUpdater.php b/src/Adapter/Order/OrderAmountUpdater.php index f28e6b243f656..2daba48962c6f 100644 --- a/src/Adapter/Order/OrderAmountUpdater.php +++ b/src/Adapter/Order/OrderAmountUpdater.php @@ -436,7 +436,7 @@ private function updateOrderInvoices(Order $order, Cart $cart, int $computingPre // Shipping are computed on first invoice only $carrierId = $order->id_carrier; - $totalMethod = ($firstInvoice === null || $firstInvoice->id == $invoice->id) ? Cart::BOTH : Cart::BOTH_WITHOUT_SHIPPING; + $totalMethod = ($firstInvoice === false || $firstInvoice->id == $invoice->id) ? Cart::BOTH : Cart::BOTH_WITHOUT_SHIPPING; $invoice->total_paid_tax_excl = Tools::ps_round( (float) $cart->getOrderTotal(false, $totalMethod, $currentInvoiceProducts, $carrierId), $computingPrecision diff --git a/src/Adapter/Order/QueryHandler/GetOrderForViewingHandler.php b/src/Adapter/Order/QueryHandler/GetOrderForViewingHandler.php index 7ef63a5e2fcf4..a615d85574533 100644 --- a/src/Adapter/Order/QueryHandler/GetOrderForViewingHandler.php +++ b/src/Adapter/Order/QueryHandler/GetOrderForViewingHandler.php @@ -400,7 +400,7 @@ private function getOrderDocuments(Order $order): OrderDocumentsForViewing $currency->iso_code ); $numericAmount = $document->total_shipping_tax_incl; - } elseif (OrderDocumentType::CREDIT_SLIP) { + } elseif (OrderDocumentType::CREDIT_SLIP === $type) { $number = sprintf( '%s%06d', Configuration::get('PS_CREDIT_SLIP_PREFIX', $this->contextLanguageId), diff --git a/src/Adapter/Order/QueryHandler/GetOrderPreviewHandler.php b/src/Adapter/Order/QueryHandler/GetOrderPreviewHandler.php index b873bef8fd605..2b21364ce7ed9 100644 --- a/src/Adapter/Order/QueryHandler/GetOrderPreviewHandler.php +++ b/src/Adapter/Order/QueryHandler/GetOrderPreviewHandler.php @@ -133,7 +133,7 @@ private function getInvoiceDetails(Order $order): OrderPreviewInvoiceDetails $address->postcode, $stateName, $country->name[$order->id_lang], - $customer ? $customer->email : null, + $customer->email, $address->phone ); } diff --git a/src/Adapter/Order/Refund/OrderSlipCreator.php b/src/Adapter/Order/Refund/OrderSlipCreator.php index f1a9d4ff73aa9..1afeb125d72f3 100644 --- a/src/Adapter/Order/Refund/OrderSlipCreator.php +++ b/src/Adapter/Order/Refund/OrderSlipCreator.php @@ -192,16 +192,6 @@ private function createOrderSlip( $orderSlip->id_order = (int) $order->id; $orderSlip->conversion_rate = $currency->conversion_rate; - if ($add_tax) { - $add_or_remove = 'add'; - $inc_or_ex_1 = 'excl'; - $inc_or_ex_2 = 'incl'; - } else { - $add_or_remove = 'remove'; - $inc_or_ex_1 = 'incl'; - $inc_or_ex_2 = 'excl'; - } - $orderSlip->total_shipping_tax_excl = 0; $orderSlip->total_shipping_tax_incl = 0; $orderSlip->partial = 0; @@ -212,12 +202,21 @@ private function createOrderSlip( // @todo: define if we use invoice or delivery address, or we use configuration PS_TAX_ADDRESS_TYPE $address = Address::initialize($order->id_address_delivery, false); $tax_calculator = $carrier->getTaxCalculator($address); - $orderSlip->{'total_shipping_tax_' . $inc_or_ex_1} = $shipping_cost; - if ($tax_calculator instanceof TaxCalculator) { - $orderSlip->{'total_shipping_tax_' . $inc_or_ex_2} = Tools::ps_round($tax_calculator->{$add_or_remove . 'Taxes'}($orderSlip->{'total_shipping_tax_' . $inc_or_ex_1}), $precision); + if ($add_tax) { + $orderSlip->total_shipping_tax_excl = $shipping_cost; + if ($tax_calculator instanceof TaxCalculator) { + $orderSlip->total_shipping_tax_incl = Tools::ps_round($tax_calculator->addTaxes($orderSlip->total_shipping_tax_excl), $precision); + } else { + $orderSlip->total_shipping_tax_incl = $orderSlip->total_shipping_tax_excl; + } } else { - $orderSlip->{'total_shipping_tax_' . $inc_or_ex_2} = $orderSlip->{'total_shipping_tax_' . $inc_or_ex_1}; + $orderSlip->total_shipping_tax_incl = $shipping_cost; + if ($tax_calculator instanceof TaxCalculator) { + $orderSlip->total_shipping_tax_excl = Tools::ps_round($tax_calculator->removeTaxes($orderSlip->total_shipping_tax_incl), $precision); + } else { + $orderSlip->total_shipping_tax_excl = $orderSlip->total_shipping_tax_incl; + } } } else { $orderSlip->shipping_cost = 0; @@ -238,7 +237,11 @@ private function createOrderSlip( $id_tax_rules_group = (int) $order_detail->id_tax_rules_group; $tax_calculator = $order_detail->getTaxCalculator(); - $orderSlip->{'total_products_tax_' . $inc_or_ex_1} += $price * $quantity; + if ($add_tax) { + $orderSlip->total_products_tax_excl += $price * $quantity; + } else { + $orderSlip->total_products_tax_incl += $price * $quantity; + } if (in_array($this->configuration->get('PS_ROUND_TYPE'), [Order::ROUND_ITEM, Order::ROUND_LINE])) { if (!isset($total_products[$id_tax_rules_group])) { @@ -250,10 +253,18 @@ private function createOrderSlip( } } - $product_tax_incl_line = Tools::ps_round($tax_calculator->{$add_or_remove . 'Taxes'}($price) * $quantity, $precision); + if ($add_tax) { + $product_tax_incl_line = Tools::ps_round($tax_calculator->addTaxes($price) * $quantity, $precision); + } else { + $product_tax_incl_line = Tools::ps_round($tax_calculator->removeTaxes($price) * $quantity, $precision); + } switch ($this->configuration->get('PS_ROUND_TYPE')) { case Order::ROUND_ITEM: - $product_tax_incl = Tools::ps_round($tax_calculator->{$add_or_remove . 'Taxes'}($price), $precision) * $quantity; + if ($add_tax) { + $product_tax_incl = Tools::ps_round($tax_calculator->addTaxes($price), $precision) * $quantity; + } else { + $product_tax_incl = Tools::ps_round($tax_calculator->removeTaxes($price), $precision) * $quantity; + } $total_products[$id_tax_rules_group] += $product_tax_incl; break; case Order::ROUND_LINE: @@ -268,10 +279,17 @@ private function createOrderSlip( $product_tax_incl = 0; } - $product['unit_price_tax_' . $inc_or_ex_1] = $price; - $product['unit_price_tax_' . $inc_or_ex_2] = Tools::ps_round($tax_calculator->{$add_or_remove . 'Taxes'}($price), $precision); - $product['total_price_tax_' . $inc_or_ex_1] = Tools::ps_round($price * $quantity, $precision); - $product['total_price_tax_' . $inc_or_ex_2] = Tools::ps_round($product_tax_incl, $precision); + if ($add_tax) { + $product['unit_price_tax_excl'] = $price; + $product['unit_price_tax_incl'] = Tools::ps_round($tax_calculator->addTaxes($price), $precision); + $product['total_price_tax_excl'] = Tools::ps_round($price * $quantity, $precision); + $product['total_price_tax_incl'] = Tools::ps_round($product_tax_incl, $precision); + } else { + $product['unit_price_tax_incl'] = $price; + $product['unit_price_tax_excl'] = Tools::ps_round($tax_calculator->removeTaxes($price), $precision); + $product['total_price_tax_incl'] = Tools::ps_round($price * $quantity, $precision); + $product['total_price_tax_excl'] = Tools::ps_round($product_tax_incl, $precision); + } } unset($product); @@ -281,14 +299,28 @@ private function createOrderSlip( $tmp = explode('_', $key); $address = Address::initialize((int) $tmp[1], true); $tax_calculator = TaxManagerFactory::getManager($address, $tmp[0])->getTaxCalculator(); - $orderSlip->{'total_products_tax_' . $inc_or_ex_2} += Tools::ps_round($tax_calculator->{$add_or_remove . 'Taxes'}($price), $precision); + + if ($add_tax) { + $orderSlip->total_products_tax_incl += Tools::ps_round($tax_calculator->addTaxes($price), $precision); + } else { + $orderSlip->total_products_tax_excl += Tools::ps_round($tax_calculator->removeTaxes($price), $precision); + } } else { - $orderSlip->{'total_products_tax_' . $inc_or_ex_2} += $price; + if ($add_tax) { + $orderSlip->total_products_tax_incl += $price; + } else { + $orderSlip->total_products_tax_excl += $price; + } } } - $orderSlip->{'total_products_tax_' . $inc_or_ex_2} -= $amount && !$amount_choosen ? $amount : 0; - $orderSlip->amount = $amount_choosen ? $amount : $orderSlip->{'total_products_tax_' . $inc_or_ex_1}; + if ($add_tax) { + $orderSlip->total_products_tax_incl -= $amount && !$amount_choosen ? $amount : 0; + $orderSlip->amount = $amount_choosen ? $amount : $orderSlip->total_products_tax_excl; + } else { + $orderSlip->total_products_tax_excl -= $amount && !$amount_choosen ? $amount : 0; + $orderSlip->amount = $amount_choosen ? $amount : $orderSlip->total_products_tax_incl; + } $orderSlip->shipping_cost_amount = $orderSlip->total_shipping_tax_incl; if ((float) $amount && !$amount_choosen) { diff --git a/src/Adapter/Presenter/Product/ProductLazyArray.php b/src/Adapter/Presenter/Product/ProductLazyArray.php index c62898e45df28..c9c147ed96b0c 100644 --- a/src/Adapter/Presenter/Product/ProductLazyArray.php +++ b/src/Adapter/Presenter/Product/ProductLazyArray.php @@ -233,16 +233,12 @@ public function getCondition() 'label' => $this->translator->trans('Used', [], 'Shop.Theme.Catalog'), 'schema_url' => 'https://schema.org/UsedCondition', ]; - - break; case 'refurbished': return [ 'type' => 'refurbished', 'label' => $this->translator->trans('Refurbished', [], 'Shop.Theme.Catalog'), 'schema_url' => 'https://schema.org/RefurbishedCondition', ]; - - break; default: return false; } diff --git a/src/Adapter/Product/AdminProductWrapper.php b/src/Adapter/Product/AdminProductWrapper.php index c483b06d0b365..b416bec56efe3 100644 --- a/src/Adapter/Product/AdminProductWrapper.php +++ b/src/Adapter/Product/AdminProductWrapper.php @@ -778,7 +778,7 @@ public function processDeleteVirtualProductFile($product) $id_product_download = ProductDownload::getIdFromIdProduct((int) $product->id, false); $download = new ProductDownload($id_product_download ? $id_product_download : null); - if ($download && !empty($download->filename)) { + if (!empty($download->filename)) { unlink(_PS_DOWNLOAD_DIR_ . $download->filename); Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'product_download` SET filename = "" WHERE `id_product_download` = ' . (int) $download->id); } @@ -793,8 +793,7 @@ public function processDeleteVirtualProduct($product) { $id_product_download = ProductDownload::getIdFromIdProduct((int) $product->id, false); $download = new ProductDownload($id_product_download ? $id_product_download : null); - - if ($download) { + if (Validate::isLoadedObject($download)) { $download->delete(true); } } diff --git a/src/Adapter/Product/ProductDataProvider.php b/src/Adapter/Product/ProductDataProvider.php index 59783c1e6931e..68a8dd66b78ca 100644 --- a/src/Adapter/Product/ProductDataProvider.php +++ b/src/Adapter/Product/ProductDataProvider.php @@ -39,7 +39,7 @@ class ProductDataProvider /** * Get a new ProductCore instance. * - * @param null $idProduct + * @param int|null $idProduct * * @return Product */ @@ -72,17 +72,16 @@ public function getProduct($id_product, $full = false, $id_lang = null, $id_shop } $product = new Product($id_product, $full, $id_lang, $id_shop, $context); - if ($product) { - if (!is_array($product->link_rewrite)) { - $linkRewrite = $product->link_rewrite; - } else { - $linkRewrite = $product->link_rewrite[$id_lang ? $id_lang : key($product->link_rewrite)]; - } - - $cover = Product::getCover($product->id); - $product->image = Context::getContext()->link->getImageLink($linkRewrite, $cover ? $cover['id_image'] : '', 'home_default'); + + if (!is_array($product->link_rewrite)) { + $linkRewrite = $product->link_rewrite; + } else { + $linkRewrite = $product->link_rewrite[$id_lang ? $id_lang : key($product->link_rewrite)]; } + $cover = Product::getCover($product->id); + $product->image = Context::getContext()->link->getImageLink($linkRewrite, $cover ? $cover['id_image'] : '', 'home_default'); + return $product; } diff --git a/src/Adapter/Product/QueryHandler/GetProductForEditingHandler.php b/src/Adapter/Product/QueryHandler/GetProductForEditingHandler.php index bb49bacf63966..046e5783c1d26 100644 --- a/src/Adapter/Product/QueryHandler/GetProductForEditingHandler.php +++ b/src/Adapter/Product/QueryHandler/GetProductForEditingHandler.php @@ -273,14 +273,16 @@ private function getCustomizationOptions(Product $product): ProductCustomization switch ((int) $product->customizable) { case ProductCustomizabilitySettings::ALLOWS_CUSTOMIZATION: - return ProductCustomizationOptions::createAllowsCustomization($textFieldsCount, $fileFieldsCount); + $options = ProductCustomizationOptions::createAllowsCustomization($textFieldsCount, $fileFieldsCount); break; case ProductCustomizabilitySettings::REQUIRES_CUSTOMIZATION: - return ProductCustomizationOptions::createRequiresCustomization($textFieldsCount, $fileFieldsCount); + $options = ProductCustomizationOptions::createRequiresCustomization($textFieldsCount, $fileFieldsCount); break; default: - return ProductCustomizationOptions::createNotCustomizable(); + $options = ProductCustomizationOptions::createNotCustomizable(); } + + return $options; } /** diff --git a/src/Adapter/StockManager.php b/src/Adapter/StockManager.php index 8f235615d15ba..3e6da97daa816 100644 --- a/src/Adapter/StockManager.php +++ b/src/Adapter/StockManager.php @@ -44,7 +44,7 @@ class StockManager implements StockInterface * * @param object $product * @param null $id_product_attribute - * @param null $id_shop + * @param int|null $id_shop * * @return StockAvailable */ @@ -178,7 +178,7 @@ private function updateReservedProductQuantity($shopId, $errorState, $cancellati /** * Instance a new StockAvailable. * - * @param null $stockAvailableId + * @param bool|int|null $stockAvailableId * * @return StockAvailable */ diff --git a/src/Adapter/SymfonyContainer.php b/src/Adapter/SymfonyContainer.php index 799b6f3e0f74b..06d2fd1e07f83 100644 --- a/src/Adapter/SymfonyContainer.php +++ b/src/Adapter/SymfonyContainer.php @@ -42,7 +42,7 @@ final class SymfonyContainer /** * Get a singleton instance of SymfonyContainer. * - * @return ContainerInterface; + * @return ContainerInterface|null; */ public static function getInstance() { diff --git a/src/Core/Addon/Module/ModuleManagerBuilder.php b/src/Core/Addon/Module/ModuleManagerBuilder.php index 8f267264a033c..898d474bca481 100644 --- a/src/Core/Addon/Module/ModuleManagerBuilder.php +++ b/src/Core/Addon/Module/ModuleManagerBuilder.php @@ -78,6 +78,11 @@ class ModuleManagerBuilder public static $instance = null; public static $cacheProvider = null; + /** + * @var bool + */ + private $isDebug; + /** * @return ModuleManagerBuilder|null */ @@ -145,8 +150,12 @@ public function buildRepository() return self::$modulesRepository; } - private function __construct() + /** + * @param bool $isDebug + */ + private function __construct(bool $isDebug = _PS_MODE_DEV_) { + $this->isDebug = $isDebug; /** * If the Symfony container is available, it will be used for the other methods * build & buildRepository. No need to init manually all the dependancies. @@ -187,10 +196,7 @@ private function __construct() self::$addonsDataProvider = new AddonsDataProvider($marketPlaceClient, self::$moduleZipManager); $kernelDir = realpath($this->getConfigDir() . '/../../var'); - self::$addonsDataProvider->cacheDir = $kernelDir . '/cache/prod'; - if (_PS_MODE_DEV_) { - self::$addonsDataProvider->cacheDir = $kernelDir . '/cache/dev'; - } + self::$addonsDataProvider->cacheDir = $kernelDir . ($this->isDebug ? '/cache/dev' : '/cache/prod'); self::$cacheProvider = new FilesystemCache(self::$addonsDataProvider->cacheDir . '/doctrine'); @@ -233,7 +239,7 @@ private function __construct() private function getSymfonyRouter() { // get the environment to load the good routing file - $routeFileName = _PS_MODE_DEV_ === true ? 'routing_dev.yml' : 'routing.yml'; + $routeFileName = $this->isDebug === true ? 'routing_dev.yml' : 'routing.yml'; $routesDirectory = $this->getConfigDir(); $locator = new FileLocator([$routesDirectory]); $loader = new YamlFileLoader($locator); diff --git a/src/Core/Addon/Module/ModuleRepository.php b/src/Core/Addon/Module/ModuleRepository.php index 3f70d55f0aed9..5987b51d5f44d 100644 --- a/src/Core/Addon/Module/ModuleRepository.php +++ b/src/Core/Addon/Module/ModuleRepository.php @@ -89,7 +89,7 @@ class ModuleRepository implements ModuleRepositoryInterface private $modulePath; /** - * @var PrestaTrustChecker + * @var PrestaTrustChecker|null */ private $prestaTrustChecker = null; @@ -110,7 +110,7 @@ class ModuleRepository implements ModuleRepositoryInterface /** * Optionnal Doctrine cache provider. * - * @var \Doctrine\Common\Cache\CacheProvider + * @var CacheProvider|null */ private $cacheProvider; @@ -458,7 +458,6 @@ public function getModule($name, $skip_main_class_attributes = false) $this->cache[$name]['disk']['filemtime'] === $current_filemtime ) { // OK, cache can be loaded and used directly - $attributes = array_merge($attributes, $this->cache[$name]['attributes']); $disk = $this->cache[$name]['disk']; } else { diff --git a/src/Core/Cart/Calculator.php b/src/Core/Cart/Calculator.php index 079edbcb30605..040ca8701d6e3 100644 --- a/src/Core/Cart/Calculator.php +++ b/src/Core/Cart/Calculator.php @@ -228,7 +228,7 @@ public function getDiscountTotal() $allowedMaxDiscount = $this->getRowTotalWithoutDiscount(); - if (null !== $this->getFees()->getInitialShippingFees() && null !== $this->getFees()->getFinalShippingFees()) { + if (null !== $this->getFees()->getFinalShippingFees()) { $shippingDiscount = (new AmountImmutable()) ->add($this->getFees()->getInitialShippingFees()) ->sub($this->getFees()->getFinalShippingFees()) diff --git a/src/Core/Cart/Fees.php b/src/Core/Cart/Fees.php index 799335b8130cc..66afd1b82ef8f 100644 --- a/src/Core/Cart/Fees.php +++ b/src/Core/Cart/Fees.php @@ -43,7 +43,7 @@ class Fees protected $shippingFees; /** - * @var AmountImmutable + * @var AmountImmutable|null */ protected $finalShippingFees; @@ -151,7 +151,7 @@ public function getInitialShippingFees() } /** - * @return AmountImmutable + * @return AmountImmutable|null */ public function getFinalShippingFees() { diff --git a/src/Core/Currency/ExchangeRateProvider.php b/src/Core/Currency/ExchangeRateProvider.php index d1b39c6b15176..938c219ca1304 100644 --- a/src/Core/Currency/ExchangeRateProvider.php +++ b/src/Core/Currency/ExchangeRateProvider.php @@ -227,8 +227,8 @@ private function getCachedCurrencyFeed() * * @return bool */ - private function isValidXMLFeed(SimpleXMLElement $xmlFeed) + private function isValidXMLFeed(SimpleXMLElement $xmlFeed): bool { - return $xmlFeed && $xmlFeed->list && count($xmlFeed->list->currency) && $xmlFeed->source; + return (bool) count($xmlFeed->list->currency); } } diff --git a/src/Core/Domain/Address/Command/AddManufacturerAddressCommand.php b/src/Core/Domain/Address/Command/AddManufacturerAddressCommand.php index 315550511e870..60f9cc7fa0860 100644 --- a/src/Core/Domain/Address/Command/AddManufacturerAddressCommand.php +++ b/src/Core/Domain/Address/Command/AddManufacturerAddressCommand.php @@ -251,7 +251,7 @@ public function getDni() } /** - * @param int $value + * @param mixed $value * * @throws AddressConstraintException */ diff --git a/src/Core/Domain/Address/Command/EditManufacturerAddressCommand.php b/src/Core/Domain/Address/Command/EditManufacturerAddressCommand.php index 7de97e45d6a77..93d1cba6713d3 100644 --- a/src/Core/Domain/Address/Command/EditManufacturerAddressCommand.php +++ b/src/Core/Domain/Address/Command/EditManufacturerAddressCommand.php @@ -342,7 +342,7 @@ public function setDni($dni) } /** - * @param int $value + * @param mixed $value * * @throws AddressConstraintException */ diff --git a/src/Core/Domain/Currency/ValueObject/ExchangeRate.php b/src/Core/Domain/Currency/ValueObject/ExchangeRate.php index 7b63759fd48ba..eb958d99e1056 100644 --- a/src/Core/Domain/Currency/ValueObject/ExchangeRate.php +++ b/src/Core/Domain/Currency/ValueObject/ExchangeRate.php @@ -71,7 +71,7 @@ public function getValue() } /** - * @param float|int $exchangeRate + * @param mixed $exchangeRate * * @throws CurrencyConstraintException */ diff --git a/src/Core/Domain/Customer/Command/EditCustomerCommand.php b/src/Core/Domain/Customer/Command/EditCustomerCommand.php index 7c624394302f4..332a2f4a9d789 100644 --- a/src/Core/Domain/Customer/Command/EditCustomerCommand.php +++ b/src/Core/Domain/Customer/Command/EditCustomerCommand.php @@ -296,7 +296,7 @@ public function setGenderId($genderId) } /** - * @return bool + * @return bool|null */ public function isNewsletterSubscribed() { @@ -332,7 +332,7 @@ public function setIsEnabled($isEnabled) } /** - * @return bool + * @return bool|null */ public function isPartnerOffersSubscribed() { diff --git a/src/Core/Domain/MailTemplate/CommandHandler/GenerateThemeMailTemplatesCommandHandler.php b/src/Core/Domain/MailTemplate/CommandHandler/GenerateThemeMailTemplatesCommandHandler.php index fb6e15e6a55d8..25679a619ec89 100644 --- a/src/Core/Domain/MailTemplate/CommandHandler/GenerateThemeMailTemplatesCommandHandler.php +++ b/src/Core/Domain/MailTemplate/CommandHandler/GenerateThemeMailTemplatesCommandHandler.php @@ -28,7 +28,6 @@ use PrestaShop\PrestaShop\Core\Domain\MailTemplate\Command\GenerateThemeMailTemplatesCommand; use PrestaShop\PrestaShop\Core\Exception\InvalidArgumentException; -use PrestaShop\PrestaShop\Core\Language\LanguageInterface; use PrestaShop\PrestaShop\Core\Language\LanguageRepositoryInterface; use PrestaShop\PrestaShop\Core\MailTemplate\MailTemplateGenerator; use PrestaShop\PrestaShop\Core\MailTemplate\ThemeCatalogInterface; @@ -89,7 +88,6 @@ public function __construct( */ public function handle(GenerateThemeMailTemplatesCommand $command) { - /** @var LanguageInterface $language */ $language = $this->languageRepository->getOneByLocaleOrIsoCode($command->getLanguage()); if (null === $language) { throw new InvalidArgumentException(sprintf('Could not find Language for locale: %s', $command->getLanguage())); diff --git a/src/Core/Domain/Order/Command/AddCartRuleToOrderCommand.php b/src/Core/Domain/Order/Command/AddCartRuleToOrderCommand.php index 6f3ccce29ec2f..e29108997c2cb 100644 --- a/src/Core/Domain/Order/Command/AddCartRuleToOrderCommand.php +++ b/src/Core/Domain/Order/Command/AddCartRuleToOrderCommand.php @@ -67,7 +67,7 @@ class AddCartRuleToOrderCommand * @param string $cartRuleName * @param string $cartRuleType * @param string|null $value - * @param null $orderInvoiceId + * @param int|null $orderInvoiceId */ public function __construct( int $orderId, diff --git a/src/Core/Domain/Profile/Command/AbstractProfileCommand.php b/src/Core/Domain/Profile/Command/AbstractProfileCommand.php index 5f5d08fac7dfc..a3c29bf0ea661 100644 --- a/src/Core/Domain/Profile/Command/AbstractProfileCommand.php +++ b/src/Core/Domain/Profile/Command/AbstractProfileCommand.php @@ -63,12 +63,19 @@ public function getLocalizedNames() } /** - * @param string $name + * @param mixed $name */ protected function assertNameIsStringAndRequiredLength($name) { if (null !== $name && !is_string($name) || strlen($name) > ProfileSettings::NAME_MAX_LENGTH) { - throw new ProfileConstraintException(sprintf('Profile name should not exceed %d characters length but %s given', ProfileSettings::NAME_MAX_LENGTH, var_export($name, true)), ProfileConstraintException::INVALID_NAME); + throw new ProfileConstraintException( + sprintf( + 'Profile name should not exceed %d characters length but %s given', + ProfileSettings::NAME_MAX_LENGTH, + var_export($name, true) + ), + ProfileConstraintException::INVALID_NAME + ); } } } diff --git a/src/Core/Domain/Profile/ValueObject/ProfileId.php b/src/Core/Domain/Profile/ValueObject/ProfileId.php index 7be08013c977f..fab0db6316b66 100644 --- a/src/Core/Domain/Profile/ValueObject/ProfileId.php +++ b/src/Core/Domain/Profile/ValueObject/ProfileId.php @@ -62,7 +62,7 @@ public function getValue() } /** - * @param int $profileId + * @param mixed $profileId * * @throws ProfileException */ diff --git a/src/Core/Domain/Tax/Command/ToggleTaxStatusCommand.php b/src/Core/Domain/Tax/Command/ToggleTaxStatusCommand.php index fce66567ca764..c51ac79152e75 100644 --- a/src/Core/Domain/Tax/Command/ToggleTaxStatusCommand.php +++ b/src/Core/Domain/Tax/Command/ToggleTaxStatusCommand.php @@ -77,7 +77,7 @@ public function getTaxId() /** * Validates that value is of type boolean * - * @param string $value + * @param mixed $value * * @throws TaxConstraintException */ diff --git a/src/Core/Email/EmailLister.php b/src/Core/Email/EmailLister.php index 44dffaaa8aeaf..6dc3d3957973f 100644 --- a/src/Core/Email/EmailLister.php +++ b/src/Core/Email/EmailLister.php @@ -62,7 +62,7 @@ public function getAvailableMails($dir) $tmp = explode('.', $mail->getFilename()); // Check for filename existence (left part) and if extension is html (right part) - if (($tmp === false || !isset($tmp[0])) || (isset($tmp[1]) && $tmp[1] !== 'html')) { + if (!isset($tmp[0]) || (isset($tmp[1]) && $tmp[1] !== 'html')) { continue; } @@ -86,7 +86,7 @@ public function getCleanedMailName($mail_name) if (strpos($mail_name, '.') !== false) { $tmp = explode('.', $mail_name); - if ($tmp === false || !isset($tmp[0])) { + if (!isset($tmp[0])) { return $mail_name; } diff --git a/src/Core/Filter/HashMapWhitelistFilter.php b/src/Core/Filter/HashMapWhitelistFilter.php index 5976951a38a3a..568842874502e 100644 --- a/src/Core/Filter/HashMapWhitelistFilter.php +++ b/src/Core/Filter/HashMapWhitelistFilter.php @@ -152,7 +152,7 @@ public function getFilters() /** * Filters the subject. * - * @param array $subject + * @param array|AbstractLazyArray $subject * * @return array The filtered subject * diff --git a/src/Core/Foundation/Filesystem/FileSystem.php b/src/Core/Foundation/Filesystem/FileSystem.php index 89f8f16988074..bdfc047580e25 100644 --- a/src/Core/Foundation/Filesystem/FileSystem.php +++ b/src/Core/Foundation/Filesystem/FileSystem.php @@ -64,24 +64,25 @@ public function joinPaths() { if (func_num_args() < 2) { throw new Exception('joinPaths requires at least 2 arguments.'); - } elseif (func_num_args() === 2) { + } + if (func_num_args() === 2) { $arg_O = func_get_arg(0); $arg_1 = func_get_arg(1); return $this->joinTwoPaths($arg_O, $arg_1); - } elseif (func_num_args() > 2) { - $func_args = func_get_args(); - $arg_0 = func_get_arg(0); - - return $this->joinPaths( - $arg_0, - call_user_func_array( - [$this, - 'joinPaths', ], - array_slice($func_args, 1) - ) - ); } + + $func_args = func_get_args(); + $arg_0 = func_get_arg(0); + + return $this->joinPaths( + $arg_0, + call_user_func_array( + [$this, + 'joinPaths', ], + array_slice($func_args, 1) + ) + ); } /** diff --git a/src/Core/Foundation/Version.php b/src/Core/Foundation/Version.php index 5d9f17bdda88e..b14f5b5e8c800 100644 --- a/src/Core/Foundation/Version.php +++ b/src/Core/Foundation/Version.php @@ -381,7 +381,7 @@ private function versionCompare($version, $operator) * @param string $version * @param string $majorVersionString * - * @return bool|string + * @return string */ private function removeLegacyPrefix($version, $majorVersionString) { diff --git a/src/Core/Language/LanguageRepositoryInterface.php b/src/Core/Language/LanguageRepositoryInterface.php index a85adcb6f3cae..0109cd6b1f0e5 100644 --- a/src/Core/Language/LanguageRepositoryInterface.php +++ b/src/Core/Language/LanguageRepositoryInterface.php @@ -57,7 +57,7 @@ public function getOneByIsoCode($isoCode); * * @param string $locale * - * @return LanguageInterface + * @return LanguageInterface|null */ public function getOneByLocaleOrIsoCode($locale); } diff --git a/src/Core/Localization/CLDR/LocaleDataLayerInterface.php b/src/Core/Localization/CLDR/LocaleDataLayerInterface.php index 4517fdfeca3a8..73b5389e47735 100644 --- a/src/Core/Localization/CLDR/LocaleDataLayerInterface.php +++ b/src/Core/Localization/CLDR/LocaleDataLayerInterface.php @@ -41,7 +41,7 @@ interface LocaleDataLayerInterface * Combination of ISO 639-1 (2-letters language code) and ISO 3166-2 (2-letters region code) * eg: fr-FR, en-US * - * @return LocaleData The searched locale's CLDR data + * @return LocaleData|null The searched locale's CLDR data */ public function read($localeCode); diff --git a/src/Core/Localization/CLDR/LocaleDataSource.php b/src/Core/Localization/CLDR/LocaleDataSource.php index 9f302d6173375..5d27e7f60bbd2 100644 --- a/src/Core/Localization/CLDR/LocaleDataSource.php +++ b/src/Core/Localization/CLDR/LocaleDataSource.php @@ -55,7 +55,7 @@ public function __construct(CldrLocaleDataLayerInterface $topLayer) /** * @param string $localeCode * - * @return LocaleData + * @return LocaleData|null */ public function getLocaleData($localeCode) { diff --git a/src/Core/Localization/CLDR/LocaleRepository.php b/src/Core/Localization/CLDR/LocaleRepository.php index 1bafdf027c457..ace18317d28a3 100644 --- a/src/Core/Localization/CLDR/LocaleRepository.php +++ b/src/Core/Localization/CLDR/LocaleRepository.php @@ -49,11 +49,9 @@ public function __construct(LocaleDataSource $dataSource) /** * Get a CLDR Locale by simplified IETF tag. * - * @param string $localeCode - * e.g.: fr-FR, en-US... + * @param string $localeCode e.g.: fr-FR, en-US... * - * @return CldrLocale|null - * A CldrLocale object. Null if not found + * @return CldrLocale|null A CldrLocale object. Null if not found */ public function getLocale($localeCode) { diff --git a/src/Core/Localization/CLDR/Reader.php b/src/Core/Localization/CLDR/Reader.php index a9e3aca15ed82..3bc036dcb3e43 100644 --- a/src/Core/Localization/CLDR/Reader.php +++ b/src/Core/Localization/CLDR/Reader.php @@ -205,12 +205,7 @@ protected function getParentLocale($localeCode) // The common case with truncation $pos = strrpos($localeCode, '_'); if (false !== $pos) { - $parent = substr($localeCode, 0, $pos); - if (false === $parent) { - throw new LocalizationException(sprintf('Invalid locale code: "%s"', $localeCode)); - } - - return $parent; + return substr($localeCode, 0, $pos); } // The "top level" case. When only language code is left in $localeCode: 'en', 'fr'... then parent is "root". @@ -410,8 +405,7 @@ protected function mapLocaleData(SimpleXMLElement $xmlLocaleData, $supplementalD $numberSystem = (string) $format['numberSystem']; // If alias is set, we just copy data from another numbering system: $alias = $format->alias; - if ($alias - && preg_match( + if (isset($alias['path']) && preg_match( "#^\.\.\/decimalFormats\[@numberSystem='([^)]+)'\]$#", (string) $alias['path'], $matches @@ -443,8 +437,7 @@ protected function mapLocaleData(SimpleXMLElement $xmlLocaleData, $supplementalD $numberSystem = (string) $format['numberSystem']; // If alias is set, we just copy data from another numbering system: $alias = $format->alias; - if ($alias - && preg_match( + if (isset($alias['path']) && preg_match( "#^\.\.\/percentFormats\[@numberSystem='([^)]+)'\]$#", (string) $alias['path'], $matches @@ -479,8 +472,7 @@ protected function mapLocaleData(SimpleXMLElement $xmlLocaleData, $supplementalD $numberSystem = (string) $format['numberSystem']; // If alias is set, we just copy data from another numbering system: $alias = $format->alias; - if ($alias - && preg_match( + if (isset($alias['path']) && preg_match( "#^\.\.\/currencyFormats\[@numberSystem='([^)]+)'\]$#", (string) $alias['path'], $matches diff --git a/src/Core/Localization/Pack/Loader/RemoteLocalizationPackLoader.php b/src/Core/Localization/Pack/Loader/RemoteLocalizationPackLoader.php index 6d451db3e7b5f..6113c5f4269b9 100644 --- a/src/Core/Localization/Pack/Loader/RemoteLocalizationPackLoader.php +++ b/src/Core/Localization/Pack/Loader/RemoteLocalizationPackLoader.php @@ -77,11 +77,6 @@ public function getLocalizationPack($countryIso) $apiUrl = $this->configuration->get('_PS_API_URL_'); $localizationPackUrl = sprintf('%s/localization/%s/%s.xml', $apiUrl, $this->version->getMajorVersion(), $countryIso); - $pack = $this->loadXml($localizationPackUrl); - if (false === $pack) { - return null; - } - - return $pack; + return $this->loadXml($localizationPackUrl); } } diff --git a/src/Core/Product/Search/SortOrder.php b/src/Core/Product/Search/SortOrder.php index 9dd899334bd2c..fd822e8258d89 100644 --- a/src/Core/Product/Search/SortOrder.php +++ b/src/Core/Product/Search/SortOrder.php @@ -220,7 +220,7 @@ public function getDirection() } /** - * @return string|void Returns the order way using legacy prefix + * @return string Returns the order way using legacy prefix */ private function getLegacyPrefix() { @@ -233,12 +233,15 @@ private function getLegacyPrefix() $this->setField('name'); return 'm.'; - } else { - return 'p.'; } - } elseif ($this->entity === 'manufacturer') { + + return 'p.'; + } + if ($this->entity === 'manufacturer') { return 'm.'; } + + return ''; } /** diff --git a/src/Core/Search/Builder/RepositoryFiltersBuilder.php b/src/Core/Search/Builder/RepositoryFiltersBuilder.php index e895f384c284e..ccde3481b645e 100644 --- a/src/Core/Search/Builder/RepositoryFiltersBuilder.php +++ b/src/Core/Search/Builder/RepositoryFiltersBuilder.php @@ -27,7 +27,6 @@ namespace PrestaShop\PrestaShop\Core\Search\Builder; use PrestaShop\PrestaShop\Core\Search\Filters; -use PrestaShopBundle\Entity\AdminFilter; /** * This builder is able to get the employee saved filter: @@ -69,14 +68,12 @@ private function getParametersFromRepository($filterId) } if (!empty($filterId)) { - /** @var AdminFilter $adminFilter */ $adminFilter = $this->adminFilterRepository->findByEmployeeAndFilterId( $this->employeeProvider->getId(), $this->shopId, $filterId ); } else { - /** @var AdminFilter $adminFilter */ $adminFilter = $this->adminFilterRepository->findByEmployeeAndRouteParams( $this->employeeProvider->getId(), $this->shopId, diff --git a/src/Core/Search/SearchParameters.php b/src/Core/Search/SearchParameters.php index 54617724d7a28..a7c54c6f2cc48 100644 --- a/src/Core/Search/SearchParameters.php +++ b/src/Core/Search/SearchParameters.php @@ -26,7 +26,6 @@ namespace PrestaShop\PrestaShop\Core\Search; -use PrestaShopBundle\Entity\AdminFilter; use PrestaShopBundle\Entity\Repository\AdminFilterRepository; use Symfony\Component\HttpFoundation\Request; @@ -72,7 +71,6 @@ public function getFiltersFromRequest(Request $request, $filterClass) */ public function getFiltersFromRepository($employeeId, $shopId, $controller, $action, $filterClass) { - /** @var AdminFilter $adminFilter */ $adminFilter = $this->adminFilterRepository->findByEmployeeAndRouteParams( $employeeId, $shopId, diff --git a/src/Core/Util/BoolParser.php b/src/Core/Util/BoolParser.php index ea090f61958d4..098608e8e5e35 100644 --- a/src/Core/Util/BoolParser.php +++ b/src/Core/Util/BoolParser.php @@ -29,7 +29,7 @@ class BoolParser { /** - * @param string|int $value + * @param string|int|bool $value * * @return bool */ diff --git a/src/PrestaShopBundle/Command/UpdateEUTaxruleGroupsCommand.php b/src/PrestaShopBundle/Command/UpdateEUTaxruleGroupsCommand.php index 22ba67fc9c1a1..c7b6267f40e0c 100644 --- a/src/PrestaShopBundle/Command/UpdateEUTaxruleGroupsCommand.php +++ b/src/PrestaShopBundle/Command/UpdateEUTaxruleGroupsCommand.php @@ -102,7 +102,7 @@ public function execute(InputInterface $input, OutputInterface $output) $localizationPack = @simplexml_load_file($localizationPackFile); // Some packs do not have taxes - if (!$localizationPack || !$localizationPack->taxes->tax) { + if (!($localizationPack instanceof SimpleXMLElement) || !isset($localizationPack->taxes->tax)) { continue; } @@ -195,7 +195,7 @@ protected function addTax(SimpleXMLElement $taxes, SimpleXMLElement $tax, array $newTax = new SimpleXMLElement(''); $taxRulesGroups = $taxes->xpath('//taxRulesGroup[1]'); - $insertBefore = $taxRulesGroups[0]; + $insertBefore = $taxRulesGroups[0] ?? false; if (!$insertBefore) { return $this->output->writeln("Could not find any `taxRulesGroup`, don't know where to append the tax."); diff --git a/src/PrestaShopBundle/Component/CsvResponse.php b/src/PrestaShopBundle/Component/CsvResponse.php index 68f7011ed9a42..407f3766ba88a 100644 --- a/src/PrestaShopBundle/Component/CsvResponse.php +++ b/src/PrestaShopBundle/Component/CsvResponse.php @@ -38,7 +38,7 @@ class CsvResponse extends StreamedResponse const MODE_OFFSET = 2; /** - * @var array() CSV content + * @var array|callable CSV content */ private $data; diff --git a/src/PrestaShopBundle/Controller/Admin/CombinationController.php b/src/PrestaShopBundle/Controller/Admin/CombinationController.php index 8e550e4d56b4a..3d78feb51a2b9 100644 --- a/src/PrestaShopBundle/Controller/Admin/CombinationController.php +++ b/src/PrestaShopBundle/Controller/Admin/CombinationController.php @@ -45,7 +45,7 @@ public function generateCombinationFormAction($combinationIds) $response = new Response(); $combinationIds = explode('-', $combinationIds); - if ($combinationIds === false || count($combinationIds) == 0) { + if (count($combinationIds) === 0) { return $response; } diff --git a/src/PrestaShopBundle/Controller/Admin/Configure/AdvancedParameters/ImportController.php b/src/PrestaShopBundle/Controller/Admin/Configure/AdvancedParameters/ImportController.php index 1cee6c225f3af..f51d354d972d7 100644 --- a/src/PrestaShopBundle/Controller/Admin/Configure/AdvancedParameters/ImportController.php +++ b/src/PrestaShopBundle/Controller/Admin/Configure/AdvancedParameters/ImportController.php @@ -368,7 +368,7 @@ private function checkImportFormSubmitPermissions($legacyController) * * @param ImportDirectory $importDir * - * @return array|bool + * @return bool */ private function checkImportDirectory(ImportDirectory $importDir) { diff --git a/src/PrestaShopBundle/Controller/Admin/Improve/Design/MailThemeController.php b/src/PrestaShopBundle/Controller/Admin/Improve/Design/MailThemeController.php index 2b531d5819b52..ddee6dfdf0b04 100644 --- a/src/PrestaShopBundle/Controller/Admin/Improve/Design/MailThemeController.php +++ b/src/PrestaShopBundle/Controller/Admin/Improve/Design/MailThemeController.php @@ -35,7 +35,6 @@ use PrestaShop\PrestaShop\Core\Exception\FileNotFoundException; use PrestaShop\PrestaShop\Core\Exception\InvalidArgumentException; use PrestaShop\PrestaShop\Core\Form\FormHandlerInterface; -use PrestaShop\PrestaShop\Core\Language\LanguageInterface; use PrestaShop\PrestaShop\Core\Language\LanguageRepositoryInterface; use PrestaShop\PrestaShop\Core\MailTemplate\Layout\LayoutInterface; use PrestaShop\PrestaShop\Core\MailTemplate\MailTemplateInterface; @@ -298,7 +297,6 @@ public function sendTestMailAction($theme, $layout, $locale, $module = '') /** @var LanguageRepositoryInterface $languageRepository */ $languageRepository = $this->get('prestashop.core.admin.lang.repository'); - /** @var LanguageInterface $language */ $language = $languageRepository->getOneByLocaleOrIsoCode($locale); if (null === $language) { throw new InvalidArgumentException(sprintf('Cannot find Language with locale or isoCode %s', $locale)); @@ -471,7 +469,6 @@ private function renderLayout($themeName, $layoutName, $type, $locale = '', $mod if (empty($locale)) { $locale = $this->getContext()->language->locale; } - /** @var LanguageInterface $language */ $language = $languageRepository->getOneByLocaleOrIsoCode($locale); if (null === $language) { throw new InvalidArgumentException(sprintf('Cannot find Language with locale or isoCode %s', $locale)); @@ -496,7 +493,6 @@ private function renderLayout($themeName, $layoutName, $type, $locale = '', $mod break; default: throw new NotFoundHttpException(sprintf('Requested type %s is not managed, please use one of these: %s', $type, implode(',', [MailTemplateInterface::HTML_TYPE, MailTemplateInterface::TXT_TYPE]))); - break; } return $renderedLayout; diff --git a/src/PrestaShopBundle/Controller/Admin/Improve/International/CurrencyController.php b/src/PrestaShopBundle/Controller/Admin/Improve/International/CurrencyController.php index 742cd6ce2cde6..f7ae8065b3464 100644 --- a/src/PrestaShopBundle/Controller/Admin/Improve/International/CurrencyController.php +++ b/src/PrestaShopBundle/Controller/Admin/Improve/International/CurrencyController.php @@ -195,7 +195,7 @@ public function editAction($currencyId, Request $request) return $this->render('@PrestaShop/Admin/Improve/International/Currency/edit.html.twig', [ 'isShopFeatureEnabled' => $multiStoreFeature->isUsed(), - 'currencyForm' => null !== $currencyForm ? $currencyForm->createView() : null, + 'currencyForm' => $currencyForm->createView(), 'languages' => $this->getLanguagesData($currencyForm->getData()['iso_code']), ]); } diff --git a/src/PrestaShopBundle/Controller/Admin/Improve/ModuleController.php b/src/PrestaShopBundle/Controller/Admin/Improve/ModuleController.php index 88aaca128d117..b4bb6a8e2fb96 100755 --- a/src/PrestaShopBundle/Controller/Admin/Improve/ModuleController.php +++ b/src/PrestaShopBundle/Controller/Admin/Improve/ModuleController.php @@ -531,6 +531,7 @@ public function importModuleAction(Request $request) $moduleManager = $this->get('prestashop.module.manager'); $moduleZipManager = $this->get('prestashop.module.zip.manager'); $serverParams = new ServerParams(); + $moduleName = ''; try { if ($serverParams->hasPostMaxSizeBeenExceeded()) { @@ -787,7 +788,7 @@ private function constructJsonCatalogCategoriesMenuResponse(array $categories) * * @param array $pageVoter * - * @return void|JsonResponse + * @return JsonResponse|null */ private function checkPermissions(array $pageVoter) { @@ -803,12 +804,14 @@ private function checkPermissions(array $pageVoter) ] ); } + + return null; } /** * @param string $pageVoter * - * @return JsonResponse|void + * @return JsonResponse|null */ private function checkPermission($pageVoter) { @@ -820,6 +823,8 @@ private function checkPermission($pageVoter) ] ); } + + return null; } /** diff --git a/src/PrestaShopBundle/Controller/ArgumentResolver/SearchParametersResolver.php b/src/PrestaShopBundle/Controller/ArgumentResolver/SearchParametersResolver.php index a3ad126b03186..38d11c991c7aa 100644 --- a/src/PrestaShopBundle/Controller/ArgumentResolver/SearchParametersResolver.php +++ b/src/PrestaShopBundle/Controller/ArgumentResolver/SearchParametersResolver.php @@ -139,7 +139,6 @@ public function resolve(Request $request, ArgumentMetadata $argument) */ private function overrideWithSavedFilters(Filters $filters, $controller, $action) { - /** @var Filters $savedFilters */ $savedFilters = $this->searchParameters->getFiltersFromRepository( $this->employee->getId(), $this->shopId, diff --git a/src/PrestaShopBundle/Entity/Repository/LangRepository.php b/src/PrestaShopBundle/Entity/Repository/LangRepository.php index 5c36f0914ce7a..f933f0e0f304a 100644 --- a/src/PrestaShopBundle/Entity/Repository/LangRepository.php +++ b/src/PrestaShopBundle/Entity/Repository/LangRepository.php @@ -59,7 +59,9 @@ public function getLocaleByIsoCode($isoCode) } /** - * {@inheritdoc} + * @param string $locale + * + * @return Lang|null */ public function getOneByLocale($locale) { @@ -67,7 +69,9 @@ public function getOneByLocale($locale) } /** - * {@inheritdoc} + * @param string $isoCode + * + * @return Lang|null */ public function getOneByIsoCode($isoCode) { @@ -75,7 +79,9 @@ public function getOneByIsoCode($isoCode) } /** - * {@inheritdoc} + * @param string $locale + * + * @return Lang|null */ public function getOneByLocaleOrIsoCode($locale) { @@ -93,7 +99,7 @@ public function getOneByLocaleOrIsoCode($locale) * @param string $key * @param string $value * - * @return Lang + * @return Lang|null */ private function searchLanguage($key, $value) { @@ -101,7 +107,6 @@ private function searchLanguage($key, $value) return $this->matches[$key][$value]; } - /** @var Lang $language */ $language = $this->findOneBy([$key => $value]); if ($language) { $this->matches[self::ISO_CODE][$language->getIsoCode()] = $language; diff --git a/src/PrestaShopBundle/Entity/Repository/LogRepository.php b/src/PrestaShopBundle/Entity/Repository/LogRepository.php index 0e6052d7d774f..248f7f66e2344 100644 --- a/src/PrestaShopBundle/Entity/Repository/LogRepository.php +++ b/src/PrestaShopBundle/Entity/Repository/LogRepository.php @@ -255,10 +255,6 @@ private function buildGridQuery(SearchCriteriaInterface $searchCriteria) ->from($this->logTable, 'l') ->leftJoin('l', $employeeTable, 'e', 'l.id_employee = e.id_employee'); - if (null === $searchCriteria) { - return $qb; - } - $filters = $searchCriteria->getFilters(); foreach ($filters as $filterName => $filterValue) { if (empty($filterValue)) { diff --git a/src/PrestaShopBundle/Entity/Repository/NormalizeFieldTrait.php b/src/PrestaShopBundle/Entity/Repository/NormalizeFieldTrait.php index 954d628d4c1ec..d76be32285cce 100644 --- a/src/PrestaShopBundle/Entity/Repository/NormalizeFieldTrait.php +++ b/src/PrestaShopBundle/Entity/Repository/NormalizeFieldTrait.php @@ -66,7 +66,7 @@ protected function castIdsToArray($rows) /** * @param string $columnName - * @param string $columnValue + * @param string|null $columnValue * * @return bool */ diff --git a/src/PrestaShopBundle/EventListener/ModuleActivatedListener.php b/src/PrestaShopBundle/EventListener/ModuleActivatedListener.php index 6875439090002..70a5aa9b70153 100644 --- a/src/PrestaShopBundle/EventListener/ModuleActivatedListener.php +++ b/src/PrestaShopBundle/EventListener/ModuleActivatedListener.php @@ -117,12 +117,7 @@ public function onKernelController(FilterControllerEvent $event) return; } - /** @var Module $module */ $module = $this->moduleRepository->getModule($moduleActivated->getModuleName()); - if (null === $module) { - return; - } - if (!$module->isActive()) { $this->showNotificationMessage($moduleActivated); $url = $this->router->generate($moduleActivated->getRedirectRoute()); diff --git a/src/PrestaShopBundle/Install/Install.php b/src/PrestaShopBundle/Install/Install.php index 0fd11637785b9..99cff6c2b76e0 100644 --- a/src/PrestaShopBundle/Install/Install.php +++ b/src/PrestaShopBundle/Install/Install.php @@ -87,6 +87,11 @@ class Install extends AbstractInstall */ protected $settingsFile = null; + /** + * @var bool + */ + protected $isDebug = null; + public function __construct($settingsFile = null, $bootstrapFile = null) { if ($bootstrapFile === null) { @@ -99,6 +104,7 @@ public function __construct($settingsFile = null, $bootstrapFile = null) $this->settingsFile = $settingsFile; $this->bootstrapFile = $bootstrapFile; + $this->isDebug = _PS_MODE_DEV_; parent::__construct(); } @@ -346,8 +352,8 @@ public function clearDatabase($truncate = false) $instance->execute('SET FOREIGN_KEY_CHECKS=0'); foreach ($instance->executeS('SHOW TABLES') as $row) { $table = current($row); - if (!_DB_PREFIX_ || preg_match('#^' . _DB_PREFIX_ . '#i', $table)) { - $instance->execute((($truncate) ? 'TRUNCATE TABLE ' : 'DROP TABLE ') . '`' . $table . '`'); + if (empty(_DB_PREFIX_) || preg_match('#^' . _DB_PREFIX_ . '#i', $table)) { + $instance->execute(($truncate ? 'TRUNCATE TABLE ' : 'DROP TABLE ') . '`' . $table . '`'); } } @@ -631,7 +637,11 @@ public function installLanguages($languages_list = null) Tools::clearCache(); if (!$id_lang = EntityLanguage::getIdByIso($iso, true)) { - throw new PrestashopInstallerException($this->translator->trans('Cannot install language "%iso%"', ['%iso%' => ($xml->name ? $xml->name : $iso)], 'Install')); + throw new PrestashopInstallerException($this->translator->trans( + 'Cannot install language "%iso%"', + ['%iso%' => (string) $xml->name], + 'Install' + )); } $languages[$id_lang] = $iso; @@ -810,7 +820,7 @@ public function configureShop(array $data = []) } // Disable cache for debug mode - if (_PS_MODE_DEV_) { + if ($this->isDebug) { Configuration::updateGlobalValue('PS_SMARTY_CACHE', 1); } @@ -879,76 +889,65 @@ public function configureShop(array $data = []) public function getModulesList() { - $modules = []; - if (false) { - foreach (scandir(_PS_MODULE_DIR_, SCANDIR_SORT_NONE) as $module) { - if ($module[0] != '.' && is_dir(_PS_MODULE_DIR_ . $module) && file_exists(_PS_MODULE_DIR_ . $module . '/' . $module . '.php')) { - $modules[] = $module; - } - } - } else { - $modules = [ - 'contactform', - 'dashactivity', - 'dashgoals', - 'dashproducts', - 'dashtrends', - 'graphnvd3', - 'gridhtml', - 'gsitemap', - 'pagesnotfound', - 'productcomments', - 'ps_banner', - 'ps_categorytree', - 'ps_checkpayment', - 'ps_contactinfo', - 'ps_crossselling', - 'ps_currencyselector', - 'ps_customeraccountlinks', - 'ps_customersignin', - 'ps_customtext', - 'ps_dataprivacy', - 'ps_emailsubscription', - 'ps_facetedsearch', - 'ps_faviconnotificationbo', - 'ps_featuredproducts', - 'ps_imageslider', - 'ps_languageselector', - 'ps_linklist', - 'ps_mainmenu', - 'ps_searchbar', - 'ps_sharebuttons', - 'ps_shoppingcart', - 'ps_socialfollow', - 'ps_themecusto', - 'ps_wirepayment', - 'sekeywords', - 'statsbestcategories', - 'statsbestcustomers', - 'statsbestproducts', - 'statsbestsuppliers', - 'statsbestvouchers', - 'statscarrier', - 'statscatalog', - 'statscheckup', - 'statsdata', - 'statsequipment', - 'statsforecast', - 'statslive', - 'statsnewsletter', - 'statsorigin', - 'statspersonalinfos', - 'statsproduct', - 'statsregistrations', - 'statssales', - 'statssearch', - 'statsstock', - 'statsvisits', - 'welcome', - ]; - } - - return $modules; + return [ + 'contactform', + 'dashactivity', + 'dashgoals', + 'dashproducts', + 'dashtrends', + 'graphnvd3', + 'gridhtml', + 'gsitemap', + 'pagesnotfound', + 'productcomments', + 'ps_banner', + 'ps_categorytree', + 'ps_checkpayment', + 'ps_contactinfo', + 'ps_crossselling', + 'ps_currencyselector', + 'ps_customeraccountlinks', + 'ps_customersignin', + 'ps_customtext', + 'ps_dataprivacy', + 'ps_emailsubscription', + 'ps_facetedsearch', + 'ps_faviconnotificationbo', + 'ps_featuredproducts', + 'ps_imageslider', + 'ps_languageselector', + 'ps_linklist', + 'ps_mainmenu', + 'ps_searchbar', + 'ps_sharebuttons', + 'ps_shoppingcart', + 'ps_socialfollow', + 'ps_themecusto', + 'ps_wirepayment', + 'sekeywords', + 'statsbestcategories', + 'statsbestcustomers', + 'statsbestproducts', + 'statsbestsuppliers', + 'statsbestvouchers', + 'statscarrier', + 'statscatalog', + 'statscheckup', + 'statsdata', + 'statsequipment', + 'statsforecast', + 'statslive', + 'statsnewsletter', + 'statsorigin', + 'statspersonalinfos', + 'statsproduct', + 'statsregistrations', + 'statssales', + 'statssearch', + 'statsstock', + 'statsvisits', + 'welcome', + ]; } public function getAddonsModulesList($params = []) @@ -1044,7 +1043,7 @@ public function installModulesAddons($module = null) * PROCESS : installModules * Download module from addons and Install all modules in ~/modules/ directory. * - * @param string|null $module Module to install. If not provided, installs all modules. + * @param array|string|null $module Module to install. If not provided, installs all modules. * * @return bool */ diff --git a/src/PrestaShopBundle/Install/Upgrade.php b/src/PrestaShopBundle/Install/Upgrade.php index dc202324ff0de..a672d0dd79de8 100644 --- a/src/PrestaShopBundle/Install/Upgrade.php +++ b/src/PrestaShopBundle/Install/Upgrade.php @@ -326,22 +326,18 @@ private function initContext() private function getConfValue($name) { - $full = version_compare('1.5.0.10', AppKernel::VERSION) < 0; - $sql = 'SELECT IF(cl.`id_lang` IS NULL, c.`value`, cl.`value`) AS value FROM `' . _DB_PREFIX_ . 'configuration` c LEFT JOIN `' . _DB_PREFIX_ . 'configuration_lang` cl ON (c.`id_configuration` = cl.`id_configuration`) WHERE c.`name`=\'' . pSQL($name) . '\''; - if ($full) { - $id_shop = Shop::getContextShopID(true); - $id_shop_group = Shop::getContextShopGroupID(true); - if ($id_shop) { - $sql .= ' AND c.`id_shop` = ' . (int) $id_shop; - } - if ($id_shop_group) { - $sql .= ' AND c.`id_shop_group` = ' . (int) $id_shop_group; - } + $id_shop = Shop::getContextShopID(true); + $id_shop_group = Shop::getContextShopGroupID(true); + if ($id_shop) { + $sql .= ' AND c.`id_shop` = ' . (int) $id_shop; + } + if ($id_shop_group) { + $sql .= ' AND c.`id_shop_group` = ' . (int) $id_shop_group; } return $this->db->getValue($sql); @@ -362,8 +358,6 @@ private function checkVersion() $this->logError('Current version: %current%. Version to install: %future%.', 27, ['%current%' => $this->oldVersion, '%future%' => _PS_INSTALL_VERSION_]); } elseif ($versionCompare == 0) { $this->logError('You already have the %future% version.', 28, ['%future%' => _PS_INSTALL_VERSION_]); - } elseif ($versionCompare === false) { - $this->logError('There is no older version. Did you delete or rename the app/config/parameters.php file?', 29); } if (strpos(_PS_INSTALL_VERSION_, '.') === false) { @@ -793,6 +787,7 @@ private function updateHtaccess() eval('class Tools2 extends \ToolsCore{}'); } + /* @phpstan-ignore-next-line */ if (class_exists('\Tools2') && method_exists('\Tools2', 'generateHtaccess')) { $url_rewrite = (bool) $this->db->getValue('SELECT `value` FROM `' . _DB_PREFIX_ . 'configuration` WHERE name=\'PS_REWRITING_SETTINGS\''); diff --git a/src/PrestaShopBundle/Install/XmlLoader.php b/src/PrestaShopBundle/Install/XmlLoader.php index 911eb19115c55..2d9937caa3433 100644 --- a/src/PrestaShopBundle/Install/XmlLoader.php +++ b/src/PrestaShopBundle/Install/XmlLoader.php @@ -185,7 +185,7 @@ public function getSortedEntities() $xml = $this->loadEntity($entity); // Store entities dependencies (with field type="relation") - if ($xml->fields) { + if ($xml instanceof \SimpleXMLElement && isset($xml->fields, $xml->fields->field)) { foreach ($xml->fields->field as $field) { if ($field['relation'] && $field['relation'] != $entity) { if (!isset($dependencies[(string) $field['relation']])) { @@ -259,7 +259,7 @@ public function populateEntity($entity) $xml = $this->loadEntity($entity); // Read list of fields - if (!is_object($xml) || !$xml->fields) { + if (!$xml instanceof \SimpleXMLElement && !empty($xml->fields)) { throw new PrestashopInstallerException('List of fields not found for entity ' . $entity); } @@ -407,13 +407,13 @@ public function populateEntityTag() * @param string $entity Name of the entity to load (eg. 'tab') * @param string|null $iso Language in which to load said entity. If not found, will fall back to default language. * - * @return \SimpleXMLElement|void + * @return \SimpleXMLElement|null */ protected function loadEntity($entity, $iso = null) { if (!isset($this->cache_xml_entity[$this->path_type][$entity][$iso])) { if (substr($entity, 0, 1) == '.' || substr($entity, 0, 1) == '_') { - return; + return null; } $path = $this->data_path . $entity . '.xml'; diff --git a/src/PrestaShopBundle/Kernel/ModuleRepositoryFactory.php b/src/PrestaShopBundle/Kernel/ModuleRepositoryFactory.php index e6a25b0ced28a..beb77c7c8429d 100644 --- a/src/PrestaShopBundle/Kernel/ModuleRepositoryFactory.php +++ b/src/PrestaShopBundle/Kernel/ModuleRepositoryFactory.php @@ -40,7 +40,7 @@ class ModuleRepositoryFactory { /** - * @var self + * @var self|null */ private static $instance; diff --git a/src/PrestaShopBundle/Resources/config/services/adapter/admin.yml b/src/PrestaShopBundle/Resources/config/services/adapter/admin.yml index ae9624130ed08..586440ba6f081 100644 --- a/src/PrestaShopBundle/Resources/config/services/adapter/admin.yml +++ b/src/PrestaShopBundle/Resources/config/services/adapter/admin.yml @@ -6,6 +6,7 @@ services: class: PrestaShop\PrestaShop\Adapter\Admin\PagePreference arguments: - "@session" + - !php/const _PS_MODE_DEV_ decorates: prestashop.core.admin.page_preference_interface public: false diff --git a/src/PrestaShopBundle/Security/Annotation/AdminSecurity.php b/src/PrestaShopBundle/Security/Annotation/AdminSecurity.php index 4e584a191c31b..6500df250c424 100644 --- a/src/PrestaShopBundle/Security/Annotation/AdminSecurity.php +++ b/src/PrestaShopBundle/Security/Annotation/AdminSecurity.php @@ -50,7 +50,7 @@ class AdminSecurity extends Security * * @todo: Once the onboarding page is migrated, set default to his route name. * - * @var string + * @var string|null */ protected $redirectRoute; @@ -86,7 +86,7 @@ public function setDomain($domain) } /** - * @return string + * @return string|null */ public function getRedirectRoute() { diff --git a/src/PrestaShopBundle/Security/Annotation/ModuleActivated.php b/src/PrestaShopBundle/Security/Annotation/ModuleActivated.php index 55f994572a779..ecfecd4c03d16 100644 --- a/src/PrestaShopBundle/Security/Annotation/ModuleActivated.php +++ b/src/PrestaShopBundle/Security/Annotation/ModuleActivated.php @@ -52,14 +52,14 @@ class ModuleActivated extends ConfigurationAnnotation /** * The route for the redirection. * - * @var string + * @var string|null */ protected $redirectRoute; /** * The module name to check. * - * @var string + * @var string|null */ protected $moduleName; @@ -96,7 +96,7 @@ public function setMessage($message) } /** - * @return string + * @return string|null */ public function getRedirectRoute() { @@ -124,7 +124,7 @@ public function getAliasName() /** * Returns the name of the module to check. * - * @return string + * @return string|null */ public function getModuleName() { diff --git a/src/PrestaShopBundle/Service/ProductService.php b/src/PrestaShopBundle/Service/ProductService.php index 8882721674628..14696fa6c4a72 100644 --- a/src/PrestaShopBundle/Service/ProductService.php +++ b/src/PrestaShopBundle/Service/ProductService.php @@ -31,7 +31,9 @@ class ProductService { - /** @var ProductDataProvider */ + /** + * @var ProductDataProvider + */ protected $dataProvider; public function __construct(ProductDataProvider $dataProvider) @@ -46,9 +48,7 @@ public function cleanupOldTempProducts() foreach ($oldProducts as $oldProduct) { $id_product = $oldProduct['id_product']; $product = $this->dataProvider->getProduct($id_product); - if ($product) { - $product->delete(); - } + $product->delete(); } } } diff --git a/src/PrestaShopBundle/Service/TranslationService.php b/src/PrestaShopBundle/Service/TranslationService.php index 953933adb690b..ba416c9d99084 100644 --- a/src/PrestaShopBundle/Service/TranslationService.php +++ b/src/PrestaShopBundle/Service/TranslationService.php @@ -148,8 +148,8 @@ private function requiresThemeTranslationsFactory($theme, $type) * @param string $locale * @param string $domain * @param string|null $theme - * @param null $search - * @param null $module + * @param string|null $search + * @param string|null $module * * @return array */ @@ -212,7 +212,7 @@ public function listDomainTranslation($locale, $domain, $theme = null, $search = /** * Check if data contains search word. * - * @param string|array $search + * @param string|array|null $search * @param array $data * * @return bool diff --git a/src/PrestaShopBundle/Translation/View/TreeBuilder.php b/src/PrestaShopBundle/Translation/View/TreeBuilder.php index f4ca054e67d9c..b09576574dfa3 100644 --- a/src/PrestaShopBundle/Translation/View/TreeBuilder.php +++ b/src/PrestaShopBundle/Translation/View/TreeBuilder.php @@ -108,7 +108,7 @@ public function makeTranslationArray(AbstractProvider $provider, $search = null) /** * Check if data contains search word. * - * @param string|array $search + * @param string|array|null $search * @param array $data * * @return bool @@ -149,6 +149,7 @@ public function makeTranslationsTree($catalogue) $tableisedDomain = Inflector::tableize($domain); // the third component of the domain may have underscores, so we need to limit pieces to 3 $parts = explode('_', $tableisedDomain, 3); + /** @var array $subtree */ $subtree = &$translationsTree; foreach ($parts as $part) { diff --git a/src/PrestaShopBundle/Twig/TranslationsExtension.php b/src/PrestaShopBundle/Twig/TranslationsExtension.php index bf0b0374fb49d..fe543b3b22cc0 100644 --- a/src/PrestaShopBundle/Twig/TranslationsExtension.php +++ b/src/PrestaShopBundle/Twig/TranslationsExtension.php @@ -515,7 +515,7 @@ protected function replaceWarningPlaceholder($output, $subtree) /** * @param array $subtree * - * @return mixed + * @return string */ protected function parseDomain($subtree) { @@ -541,7 +541,7 @@ protected function getNavigation($id) /** * @param string $subject * @param bool $isLastChild - * @param null $id + * @param string|null $id * * @return string */