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

LimitAdapter::transformPage()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 4
nop 2
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
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