1<?php
2
3namespace LesserPHP\Functions;
4
5use Exception;
6use LesserPHP\Lessc;
7use LesserPHP\Utils\Asserts;
8
9/**
10 * Implements the list functions for LESS
11 *
12 * @link https://lesscss.org/functions/#list-functions
13 */
14class Lists extends AbstractFunctionCollection
15{
16    /** @inheritdoc */
17    public function getFunctions(): array
18    {
19        return [
20            //'length' => [$this, 'length'],
21            'extract' => [$this, 'extract'],
22            //'range' => [$this, 'range'],
23            //'each' => [$this, 'each'],
24        ];
25    }
26
27    // length is missing
28
29    /**
30     * Returns the value at a specified position in a list
31     *
32     * @link https://lesscss.org/functions/#list-functions-extract
33     * @throws Exception
34     */
35    public function extract(array $value)
36    {
37        [$list, $idx] = Asserts::assertArgs($value, 2, 'extract');
38        $idx = Asserts::assertNumber($idx);
39        // 1 indexed
40        if ($list[0] == 'list' && isset($list[2][$idx - 1])) {
41            return $list[2][$idx - 1];
42        }
43
44        // FIXME what is the expected behavior here? Apparently it's not an error?
45    }
46
47    // range is missing
48
49    // each is missing
50}
51