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

CmsPageUrlPathChecker   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A check() 0 14 2
1
<?php
2
3
namespace Tkotosz\CatalogRouter\Model\Service\UrlPathUsedChecker;
4
5
use Magento\Cms\Model\ResourceModel\Page\CollectionFactory as CmsPageCollectionFactory;
6
use Tkotosz\CatalogRouter\Api\UrlPathUsedChecker;
7
use Tkotosz\CatalogRouter\Model\UrlPath;
8
use Tkotosz\CatalogRouter\Model\EntityData;
9
10
class CmsPageUrlPathChecker implements UrlPathUsedChecker
11
{
12
    /**
13
     * @var CmsPageCollectionFactory
14
     */
15
    private $cmsPageCollectionFactory;
16
    
17
    /**
18
     * @param CmsPageCollectionFactory $cmsPageCollectionFactory
19
     */
20
    public function __construct(CmsPageCollectionFactory $cmsPageCollectionFactory)
21
    {
22
        $this->cmsPageCollectionFactory = $cmsPageCollectionFactory;
23
    }
24
    
25
    /**
26
     * @param UrlPath $urlPath
27
     * @param int     $storeId
28
     *
29
     * @return EntityData[]
30
     */
31
    public function check(UrlPath $urlPath, int $storeId) : array
32
    {
33
        $result = [];
34
35
        $pageCollection = $this->cmsPageCollectionFactory->create()
36
            ->addStoreFilter($storeId, true)
37
            ->addFieldToFilter('identifier', $urlPath->getLastPart());
38
39
        foreach ($pageCollection as $page) {
40
            $result[] = new EntityData('cms page', $page->getId());    
0 ignored issues
show
Bug introduced by
The call to EntityData::__construct() misses a required argument $urlKey.

This check looks for function calls that miss required arguments.

Loading history...
41
        }
42
43
        return $result;
44
    }
45
}
46