Skip to content

Commit

Permalink
Fixed errors on PHPStan Level 4
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Dec 16, 2020
1 parent f50db30 commit 40eb05a
Show file tree
Hide file tree
Showing 99 changed files with 382 additions and 377 deletions.
2 changes: 1 addition & 1 deletion classes/Carrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions classes/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
{
Expand Down
2 changes: 1 addition & 1 deletion classes/CartRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
10 changes: 5 additions & 5 deletions classes/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class ContextCore
/** @var Country */
public $country;

/** @var Employee */
/** @var Employee|null */
public $employee;

/** @var AdminController|FrontController */
Expand All @@ -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;

Expand Down Expand Up @@ -245,7 +245,7 @@ public function getDevice()
}

/**
* @return Locale
* @return Locale|null
*/
public function getCurrentLocale()
{
Expand Down Expand Up @@ -287,7 +287,7 @@ protected function checkMobileContext()
/**
* Get a singleton instance of Context object.
*
* @return Context
* @return Context|null
*/
public static function getContext()
{
Expand Down
2 changes: 1 addition & 1 deletion classes/ObjectModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion classes/PrestaShopCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ public function getAll($display_query = false)
/**
* Retrieve the first result.
*
* @return ObjectModel|false
* @return ObjectModel|bool
*/
public function getFirst()
{
Expand Down
7 changes: 6 additions & 1 deletion classes/SpecificPriceRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions classes/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion classes/controller/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ public function getParameter($parameterId)
/**
* Gets the dependency container.
*
* @return ContainerBuilder
* @return ContainerBuilder|null
*/
public function getContainer()
{
Expand Down
2 changes: 1 addition & 1 deletion classes/order/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
2 changes: 1 addition & 1 deletion classes/shop/Shop.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"ext-intl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"ext-simplexml": "*",
"ext-zip": "*",
"beberlei/doctrineextensions": "^1.0",
"composer/ca-bundle": "^1.0",
Expand Down
1 change: 0 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Adapter/Admin/AbstractAdminQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private function compileSqlWhere(array $whereArray)
* Format example for $order:
* $order = array('name ASC', 'id_product DESC');
*
* @param array<array<mixed>> $select
* @param array<string,array<string,string>|string> $select
* @param array<mixed> $table
* @param array<mixed> $where
* @param array<string> $groupBy
Expand All @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions src/Adapter/Admin/PagePreference.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,25 @@
*/
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;
} else {
$sessionClass = get_class($session);
$this->session = new $sessionClass(new PhpBridgeSessionStorage());
}
$this->isDebug = $isDebug;
}

/**
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
Expand Down
12 changes: 4 additions & 8 deletions src/Adapter/Cart/CommandHandler/UpdateCartAddressesHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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".',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
23 changes: 10 additions & 13 deletions src/Adapter/Category/CategoryDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

use Category;
use Context;
use LogicException;
use ObjectModel;
use PrestaShop\PrestaShop\Adapter\LegacyContext;
use Shop;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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(
Expand All @@ -243,7 +240,7 @@ public function getAjaxCategories($query, $limit, $nameAsBreadCrumb = false)
true,
$query,
'',
$limit
$limitParam
);

$results = [];
Expand Down
Loading

0 comments on commit 40eb05a

Please sign in to comment.