Passed
Push — develop ( ef2a1c...78fe93 )
by Brent
02:49
created

LimitAdapter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A transformPage() 0 17 3
1
<?php
2
3
namespace Brendt\Stitcher\Adapter;
4
5
use Brendt\Stitcher\Exception\ConfigurationException;
6
use Brendt\Stitcher\Factory\AdapterFactory;
7
use Brendt\Stitcher\Site\Page;
8
9
class LimitAdapter extends AbstractAdapter
10
{
11
    /**
12
     * @param Page        $page
13
     * @param string|null $filter
14
     *
15
     * @return Page[]
16
     */
17
    public function transformPage(Page $page, $filter = null) : array {
18
        $config = $page->getAdapterConfig(AdapterFactory::LIMIT_ADAPTER);
19
        $config = isset($config['variable']) ? [$config['variable'] => $config] : $config;
20
21
        foreach ($config as $variable => $limit) {
22
            $entries = $this->getData($page->getVariable($variable));
23
            $entries = array_slice($entries, 0, $limit);
24
25
            $page->setVariableValue($variable, $entries)
26
                ->setVariableIsParsed($variable);
27
        }
28
29
        /** @var Page[] $result */
30
        $result = [$page->getId() => $page];
31
32
        return $result;
33
    }
34
}
35