Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
QueryCompiler
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
3 / 3
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 compile
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 build
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3declare(strict_types=1);
4
5namespace Cosray\Finder;
6
7use Cosray\Context;
8use Cosray\Finder\Output\Output;
9
10final class QueryCompiler
11{
12    use CompilesField;
13
14    /** @param array<string, string> $builtins */
15    public function __construct(
16        private readonly Context $context,
17        private readonly array $builtins,
18    ) {}
19
20    public function compile(string $query): string
21    {
22        $parser = new QueryParser($this->context, $this->builtins);
23
24        return $this->build($parser->parse($query));
25    }
26
27    /** @param list<Output> $parserOutput */
28    private function build(array $parserOutput): string
29    {
30        if (count($parserOutput) === 0) {
31            return '';
32        }
33
34        $clause = '';
35
36        foreach ($parserOutput as $output) {
37            $clause .= $output->get();
38        }
39
40        return $clause;
41    }
42}