Test Failed
Pull Request — master (#1)
by Tibor
02:26
created

CategoryUrlPathChecker::resolveParentCategoryId()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
3
namespace Tkotosz\CatalogRouter\Model\Service\UrlPathUsedChecker;
4
5
use Magento\Store\Model\StoreManagerInterface;
6
use Tkotosz\CatalogRouter\Api\CategoryResolverInterface;
7
use Tkotosz\CatalogRouter\Api\ProductResolverInterface;
8
use Tkotosz\CatalogRouter\Api\UrlPathUsedChecker;
9
use Tkotosz\CatalogRouter\Model\UrlPath;
10
use Tkotosz\CatalogRouter\Model\EntityData;
11
12
class CategoryUrlPathChecker implements UrlPathUsedChecker
13
{
14
    /**
15
     * @var CategoryResolverInterface
16
     */
17
    private $categoryResolver;
18
    
19
    /**
20
     * @var StoreManagerInterface
21
     */
22
    private $storeManager;
23
    
24
    /**
25
     * @param CategoryResolverInterface $categoryResolver
26
     * @param StoreManagerInterface     $storeManager
27
     */
28
    public function __construct(CategoryResolverInterface $categoryResolver, StoreManagerInterface $storeManager)
29
    {
30
        $this->categoryResolver = $categoryResolver;
31
        $this->storeManager = $storeManager;
32
    }
33
    
34
    /**
35
     * @param UrlPath $urlPath
36
     * @param int     $storeId
37
     *
38
     * @return EntityData[]
39
     */
40
    public function check(UrlPath $urlPath, int $storeId) : array
41
    {
42
        $parentCategoryId = $this->resolveParentCategoryId($urlPath, $storeId);
43
44
        return $this->categoryResolver->resolveAllByUrlKey($urlPath->getLastPart(), $storeId, $parentCategoryId);
0 ignored issues
show
Bug introduced by
The method resolveAllByUrlKey() does not exist on Tkotosz\CatalogRouter\Ap...tegoryResolverInterface. Did you maybe mean resolveByUrlKey()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
45
    }
46
47
    /**
48
     * @param UrlPath $urlPath
49
     * @param int     $storeId
50
     *
51
     * @return int
52
     */
53 View Code Duplication
    private function resolveParentCategoryId(UrlPath $urlPath, int $storeId) : int
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
    {
55
        $parentCategoryId = $this->storeManager->getStore($storeId)->getRootCategoryId();
56
57
        foreach ($urlPath->getBeginningParts() as $urlKey) {
58
            $parentCategoryId = $this->categoryResolver->resolveByUrlKey($urlKey, $storeId, $parentCategoryId)->getId();
59
        }
60
61
        return $parentCategoryId;
62
    }
63
}
64