Completed
Push — master ( 1c4fa3...04dec7 )
by Willem
24s queued 11s
created

PageLayoutUpdateManager   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 11
dl 0
loc 39
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fetchAvailableFiles() 0 8 2
A setFakeFiles() 0 6 2
1
<?php
2
declare(strict_types=1);
3
4
namespace IntegerNet\GlobalCustomLayout\Test\src;
5
6
use Magento\Cms\Api\Data\PageInterface;
7
use Magento\Cms\Model\Page\CustomLayout\CustomLayoutManager;
8
9
/**
10
 * Manager allowing to fake available files.
11
 */
12
class PageLayoutUpdateManager extends CustomLayoutManager
13
{
14
    /**
15
     * @var array Keys are Page IDs, values - file names.
16
     */
17
    private $fakeFiles = [];
18
19
    /**
20
     * Supply fake files for a Page.
21
     *
22
     * @param int $forPageId
23
     * @param string[]|null $files Pass null to reset.
24
     */
25
    public function setFakeFiles(int $forPageId, ?array $files): void
26
    {
27
        if ($files === null) {
0 ignored issues
show
introduced by
The condition $files === null is always false.
Loading history...
28
            unset($this->fakeFiles[$forPageId]);
29
        } else {
30
            $this->fakeFiles[$forPageId] = $files;
31
        }
32
    }
33
34
    /**
35
     * Fetches fake/mock files added through $this->setFakeFiles()
36
     * for current Page and Global (0)
37
     *
38
     * If none found, fall back to original method
39
     *
40
     * @param PageInterface $page
41
     * @return array
42
     */
43
    public function fetchAvailableFiles(PageInterface $page): array
44
    {
45
        return array_unique(
46
            array_merge(
47
                ($this->fakeFiles[$page->getId()] ?? []),
48
                ($this->fakeFiles[0] ?? [])
49
            )
50
        ) ?: parent::fetchAvailableFiles($page);
51
    }
52
}
53