| Total Complexity | 4 |
| Total Lines | 37 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 20 | abstract class BaseTest extends TestCase |
||
| 21 | { |
||
| 22 | protected const GRAMMARS = [ |
||
| 23 | /* GRAMMAR => SYNTAX */ |
||
| 24 | ]; |
||
| 25 | |||
| 26 | protected const RENDERS = [ |
||
| 27 | /* RENDERER */ |
||
| 28 | ]; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @param Template $document |
||
| 32 | * @return string |
||
| 33 | */ |
||
| 34 | protected function compile(Template $document): string |
||
| 35 | { |
||
| 36 | $compiler = new Compiler(); |
||
| 37 | foreach (static::RENDERS as $renderer) { |
||
| 38 | $compiler->addRenderer(new $renderer()); |
||
| 39 | } |
||
| 40 | |||
| 41 | return $compiler->compile($document)->getContent(); |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @param string $string |
||
| 46 | * @return Template |
||
| 47 | */ |
||
| 48 | protected function parse(string $string): Template |
||
| 49 | { |
||
| 50 | $parser = new Parser(); |
||
| 51 | |||
| 52 | foreach (static::GRAMMARS as $grammar => $syntax) { |
||
| 53 | $parser->addSyntax(new $grammar(), new $syntax()); |
||
| 54 | } |
||
| 55 | |||
| 56 | return $parser->parse(new StringStream($string)); |
||
| 57 | } |
||
| 59 |