Skip to content

Commit b077bf0

Browse files
committed
The new level 9 of phpstan is pretty crazy. And Magento coding standards don't seem to like the assert function calls for some reason ...
1 parent f370069 commit b077bf0

File tree

14 files changed

+51
-9
lines changed

14 files changed

+51
-9
lines changed

Checker/Catalog/Category/UrlKey/DuplicateUrlKey.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ private function checkForDuplicatedUrlKeyAttributeValues(): array
5959
$categories = $this->urlPathsInfo[$urlPath];
6060

6161
foreach ($categories as $category) {
62+
assert(is_numeric($category->getEntityId()));
63+
6264
$categoriesWithProblems[] = [
6365
'catId' => (int) $category->getEntityId(),
6466
'name' => $category->getName(),

Checker/Catalog/Category/UrlKey/EmptyUrlKey.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ private function getCategoriesWithProblems(int $storeId, CategoryCollection $col
100100
;
101101

102102
if ($isOverridden || $storeId === Store::DEFAULT_STORE_ID) {
103+
assert(is_numeric($category->getEntityId()));
104+
103105
$problems[] = [
104106
'catId' => (int) $category->getEntityId(),
105107
'name' => $category->getName(),

Checker/Catalog/Category/UrlPath.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public function checkForIncorrectUrlPathAttributeValues(): array
7575
if (!$this->doesCategoryUrlPathMatchCalculatedUrlPath($category, $storeId)) {
7676
$correctUrlPath = $this->getCalculatedUrlPathForCategory($category, $storeId);
7777

78+
assert(is_numeric($category->getId()));
79+
7880
$problems[] = [
7981
'catId' => (int) $category->getId(),
8082
'name' => $category->getName(),
@@ -117,6 +119,8 @@ public function getCalculatedUrlPathForCategory(Category $category, int $storeId
117119
$this->fetchAllCategoriesWithUrlPathCalculatedByUrlKey();
118120
}
119121

122+
assert(is_numeric($category->getId()));
123+
120124
$categoryId = (int) $category->getId();
121125
$key = $this->getArrayKeyForCategoryAndStoreId($categoryId, $storeId);
122126

@@ -140,6 +144,8 @@ private function fetchAllCategoriesWithUrlPathCalculatedByUrlKey()
140144

141145
$allCategories = $this->getAllVisibleCategoriesWithStoreId($storeId);
142146
foreach ($allCategories as $category) {
147+
assert(is_numeric($category->getId()));
148+
143149
$categoryId = (int) $category->getId();
144150

145151
$path = $category->getPath() ?: '';

Checker/Catalog/Product/UrlKey/DuplicateUrlKey.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class DuplicateUrlKey
2525
private $progressIndex;
2626
private $productCollectionFactory;
2727
private $attributeScopeOverriddenValueFactory;
28+
/** @var array<string, string> */
2829
private $cachedProductUrlKeyData;
2930
private $cachedProductSkusByIds;
3031

@@ -112,6 +113,8 @@ private function checkForDuplicatedUrlKeyAttributeValues(): array
112113
private function storeProductUrlKeyData(int $storeId, ProductCollection $collection)
113114
{
114115
foreach ($collection as $product) {
116+
assert(is_numeric($product->getEntityId()));
117+
115118
$productId = $product->getEntityId();
116119
$productSku = $product->getSku();
117120
$productUrlKey = $product->getUrlKey();

Checker/Catalog/Product/UrlKey/EmptyUrlKey.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ private function getProductsWithProblems(int $storeId, ProductCollection $collec
122122
;
123123

124124
if ($isOverridden || $storeId === Store::DEFAULT_STORE_ID) {
125+
assert(is_numeric($product->getEntityId()));
126+
125127
$problems[] = [
126128
'productId' => (int) $product->getEntityId(),
127129
'sku' => $product->getSku(),

Checker/Catalog/Product/UrlPath.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ private function getProductsWithProblems(int $storeId, ProductCollection $collec
9191
;
9292

9393
if ($isOverridden || $storeId === Store::DEFAULT_STORE_ID) {
94+
assert(is_numeric($product->getEntityId()));
95+
9496
$problems[] = [
9597
'productId' => (int) $product->getEntityId(),
9698
'sku' => $product->getSku(),

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ check: checkstyle checkquality test
1111
.PHONY: checkstyle
1212
checkstyle:
1313
vendor/bin/php-cs-fixer fix --dry-run --diff --stop-on-violation --allow-risky=yes
14-
vendor/bin/phpcs -s --standard=Magento2 --ignore=./vendor/ .
14+
vendor/bin/phpcs -s --standard=Magento2 --exclude=Magento2.Security.InsecureFunction --ignore=./vendor/ .
1515
vendor/bin/phpcs -s --standard=PHPCompatibility --runtime-set testVersion 7.0- --ignore=./vendor/,./Test/ .
1616
vendor/bin/phpcs -s --standard=PHPCompatibility --runtime-set testVersion 7.1- ./Test/
1717
composer normalize --dry-run

Model/ResourceModel/Catalog/Category/UrlKeyCollection.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ public function loadData($printQuery = false, $logQuery = false)
4343
if (!$this->isLoaded()) {
4444
$urlKeys = $this->storage->read(UrlKeyChecker::STORAGE_IDENTIFIER);
4545
foreach ($urlKeys as $urlKey) {
46-
$this->addItem($this->createDataObject($urlKey));
46+
if (is_array($urlKey)) {
47+
$this->addItem($this->createDataObject($urlKey));
48+
}
4749
}
4850

4951
foreach ($this->_orders as $field => $direction) {
@@ -83,6 +85,7 @@ public function createDataObject(array $arguments = []): DataObject
8385
{
8486
$arguments['hash'] = sha1(json_encode($arguments) ?: '');
8587

88+
/** @var DataObject */
8689
$obj = $this->_entityFactory->create($this->_itemObjectClass, ['data' => $arguments]);
8790

8891
$attributes = [];

Model/ResourceModel/Catalog/Category/UrlPathCollection.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ public function loadData($printQuery = false, $logQuery = false)
4343
if (!$this->isLoaded()) {
4444
$urlPaths = $this->storage->read(UrlPathChecker::STORAGE_IDENTIFIER);
4545
foreach ($urlPaths as $urlPath) {
46-
$this->addItem($this->createDataObject($urlPath));
46+
if (is_array($urlPath)) {
47+
$this->addItem($this->createDataObject($urlPath));
48+
}
4749
}
4850

4951
foreach ($this->_orders as $field => $direction) {
@@ -83,6 +85,7 @@ public function createDataObject(array $arguments = []): DataObject
8385
{
8486
$arguments['hash'] = sha1(json_encode($arguments) ?: '');
8587

88+
/** @var DataObject */
8689
$obj = $this->_entityFactory->create($this->_itemObjectClass, ['data' => $arguments]);
8790

8891
$attributes = [];

Model/ResourceModel/Catalog/Product/UrlKeyCollection.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ public function loadData($printQuery = false, $logQuery = false)
4343
if (!$this->isLoaded()) {
4444
$urlKeys = $this->storage->read(UrlKeyChecker::STORAGE_IDENTIFIER);
4545
foreach ($urlKeys as $urlKey) {
46-
$this->addItem($this->createDataObject($urlKey));
46+
if (is_array($urlKey)) {
47+
$this->addItem($this->createDataObject($urlKey));
48+
}
4749
}
4850

4951
foreach ($this->_orders as $field => $direction) {
@@ -83,6 +85,7 @@ public function createDataObject(array $arguments = []): DataObject
8385
{
8486
$arguments['hash'] = sha1(json_encode($arguments) ?: '');
8587

88+
/** @var DataObject */
8689
$obj = $this->_entityFactory->create($this->_itemObjectClass, ['data' => $arguments]);
8790

8891
$attributes = [];

0 commit comments

Comments
 (0)