Passed
Push — master ( fc7dfd...a70edc )
by Tibor
02:21
created

CategoryUrlPathValidatorObserver   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 32
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getCurrentEntityType() 0 4 1
A getEntity() 0 4 1
A getEntityStoreIds() 0 14 3
A getEntityUrlPath() 0 4 1
1
<?php
2
3
namespace Tkotosz\CatalogRouter\Observer;
4
5
use Magento\Framework\Event\Observer;
6
use Magento\Framework\Model\AbstractModel;
7
use Tkotosz\CatalogRouter\Model\UrlPath;
8
use Tkotosz\CatalogRouter\Observer\PathValidatorObserver;
9
10
class CategoryUrlPathValidatorObserver extends PathValidatorObserver
11
{
12
    protected function getCurrentEntityType()
13
    {
14
        return 'category';
15
    }
16
17
    protected function getEntity(Observer $observer)
18
    {
19
        return $observer->getEvent()->getCategory();
20
    }
21
22
    protected function getEntityStoreIds(AbstractModel $entity)
23
    {
24
        $storeIds = [];
25
26
        foreach ($entity->getStoreIds() as $storeId) {
27
            if ($storeId == 0) {
28
                continue;
29
            }
30
31
            $storeIds[] = $storeId;
32
        }
33
34
        return $storeIds;
35
    }
36
37
    protected function getEntityUrlPath(AbstractModel $entity, int $storeId)
38
    {
39
        return $this->urlPathProvider->getCategoryUrlPath($entity->getId(), $storeId);
40
    }
41
}
42