Skip to content

Commit

Permalink
Fix warnings and errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ugljesaspx committed Sep 17, 2024
1 parent 3ce60f6 commit 3de71b3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
9 changes: 3 additions & 6 deletions Model/Category/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
namespace Nosto\Tagging\Model\Category;

use Magento\Catalog\Api\Data\CategoryInterface;
use Magento\Catalog\Model\Category;
use Magento\Catalog\Model\CategoryRepository;
use Magento\Catalog\Model\ResourceModel\Category\Collection as CategoryCollection;
use Magento\Framework\Api\SearchCriteriaBuilder;
Expand Down Expand Up @@ -84,7 +85,6 @@ public function getByIds(array $ids)
//@TODO implement

Check warning on line 85 in Model/Category/Repository.php

View workflow job for this annotation

GitHub Actions / Code Sniffer

Comment refers to a TODO task "implement"
}


/**
* @param Store $store
* @param array $categoryIds
Expand All @@ -110,15 +110,13 @@ public function getCategoryCollectionQuery(Store $store, array $categoryIds = []
return $categories;
}


/**
* Gets the parent category ID's for a given category
*
* @param CategoryInterface $category
* @return string[]|null
* @throws ParentCategoryDisabledException
*/
public function resolveParentCategoryIds(CategoryInterface $category)
public function resolveParentCategoryIds(Category $category): ?array
{
if ($this->getParentIdsFromCache($category)) {
return $this->getParentIdsFromCache($category);
Expand All @@ -135,14 +133,13 @@ public function resolveParentCategoryIds(CategoryInterface $category)

$parentCategoryIds = null;
if ($category->getLevel() >= 1) {
//@TODO: get parents from root category, check if this works
$parentCategoryIds = $category->getParentIds();
$this->saveParentIdsToCache($category, $parentCategoryIds);
}

return $parentCategoryIds;
}


/**
* Get parent ids from cache. Return null if the cache is not available
*
Expand Down
10 changes: 5 additions & 5 deletions Model/ResourceModel/Magento/Category/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,27 @@

namespace Nosto\Tagging\Model\ResourceModel\Magento\Category;

//use Magento\Catalog\Model\Category\Attribute\Source\Status;
use Magento\Catalog\Model\ResourceModel\Category\Collection as MagentoCategoryCollection;
use Magento\Framework\Exception\LocalizedException;

class Collection extends MagentoCategoryCollection
{
/**
* @return Collection
* @throws LocalizedException
*/
public function addActiveFilter()
public function addActiveFilter(): Collection
{
// @TODO: Here should be included in the menu
return $this->addAttributeToFilter('status', ['eq' => 1]);
}

/**
* @param array $ids
* @return Collection
* @throws LocalizedException
*/
public function addIdsToFilter(array $ids)
public function addIdsToFilter(array $ids): Collection
{

return $this->addAttributeToFilter($this->getIdFieldName(), ['in' => $ids]);
}
}
3 changes: 2 additions & 1 deletion Model/Service/Update/CategoryUpdateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

use Exception;
use Magento\Catalog\Api\Data\CategoryInterface;

Check warning on line 40 in Model/Service/Update/CategoryUpdateService.php

View workflow job for this annotation

GitHub Actions / Phan Analysis

Possibly zero references to use statement for classlike/namespace CategoryInterface (\Magento\Catalog\Api\Data\CategoryInterface)
use Magento\Catalog\Model\Category;
use Magento\Store\Model\Store;
use Nosto\NostoException;
use Nosto\Tagging\Exception\ParentCategoryDisabledException;
Expand Down Expand Up @@ -124,7 +125,7 @@ public function addCollectionToUpdateMessageQueue(CategoryCollection $collection
private function toParentCategoryIds(CategoryCollection $collection): array
{
$categoryIds = [];
/** @var CategoryInterface $category */
/** @var Category $category */
foreach ($collection->getItems() as $category) {
try {
$parents = $this->nostoCategoryRepository->resolveParentCategoryIds($category);

Check notice on line 131 in Model/Service/Update/CategoryUpdateService.php

View workflow job for this annotation

GitHub Actions / Phan Analysis

Argument 1 ($category) is $category of type \ArrayAccess|\Magento\Framework\DataObject but \Nosto\Tagging\Model\Category\Repository::resolveParentCategoryIds() takes \Magento\Catalog\Model\Category defined at Model/Category/Repository.php:119 (expected type to be the same or a subtype, but saw a supertype instead)
Expand Down

0 comments on commit 3de71b3

Please sign in to comment.