-
Notifications
You must be signed in to change notification settings - Fork 0
/
Evaluator.php
46 lines (37 loc) · 1.03 KB
/
Evaluator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
declare(strict_types=1);
namespace Presta\BehatEvaluator;
use Presta\BehatEvaluator\Adapter\AdapterInterface;
final class Evaluator implements AdapterInterface
{
/**
* @param iterable<AdapterInterface> $adapters
*/
public function __construct(private readonly iterable $adapters)
{
}
public function __invoke(mixed $value): mixed
{
foreach ($this->adapters as $evaluate) {
$value = $evaluate($value);
}
return $value;
}
public static function evaluate(mixed $value, EvaluatorBuilder $builder = new EvaluatorBuilder()): mixed
{
$evaluate = $builder->build();
return $evaluate($value);
}
/**
* @param array<mixed> $values
*
* @return array<mixed>
*/
public static function evaluateMany(array $values, EvaluatorBuilder $builder = new EvaluatorBuilder()): array
{
return \array_map(
static fn (mixed $value): mixed => self::evaluate($value, $builder),
$values,
);
}
}