Passed
Push — master ( 766df6...286284 )
by Roman
55s
created

Stdio.php ➔ export()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 29
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 18
nc 1
nop 0
dl 0
loc 29
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace PeacefulBit\Slate\Core\Modules\Stdio;
4
5
use PeacefulBit\Slate\Exceptions\EvaluatorException;
6
use PeacefulBit\Slate\Parser\Nodes\NativeExpression;
7
8
function export()
9
{
10
    return [
11
        '@' => [
12
            'ask' => new NativeExpression(function ($eval, array $arguments) {
13
                if (sizeof($arguments) != 1) {
14
                    throw new EvaluatorException('Function expects one argument, but none given');
15
                }
16
                echo $eval($arguments[0]);
17
                echo ' ';
18
                return trim(fgets(STDIN));
19
            }),
20
            'say' => new NativeExpression(function ($eval, array $arguments) {
21
                array_walk($arguments, function ($argument) use ($eval) {
22
                    echo $eval($argument);
23
                });
24
            }),
25
            'say-n' => new NativeExpression(function ($eval, array $arguments) {
26
                array_walk($arguments, function ($argument) use ($eval) {
27
                    echo $eval($argument);
28
                });
29
                echo PHP_EOL;
30
            }),
31
            'err' => new NativeExpression(function ($eval, array $arguments) {
32
                fwrite(STDERR, implode(' ', array_map($eval, $arguments)) . PHP_EOL);
33
            })
34
        ]
35
    ];
36
}
37