hanneskod /
readme-tester
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace hanneskod\readmetester\InputLanguage; |
||
| 6 | |||
| 7 | use hanneskod\readmetester\Compiler\CompilerInterface; |
||
| 8 | use hanneskod\readmetester\Example\CombinedExampleStore; |
||
| 9 | use hanneskod\readmetester\Example\ExampleStoreInterface; |
||
| 10 | use hanneskod\readmetester\Exception\InvalidInputException; |
||
| 11 | use hanneskod\readmetester\Exception\InvalidPhpCodeException; |
||
| 12 | |||
| 13 | final class ParsingCompiler implements CompilerInterface |
||
| 14 | { |
||
| 15 | public function __construct( |
||
| 16 | private ParserInterface $parser, |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 17 | ) {} |
||
| 18 | |||
| 19 | public function compile(iterable $inputs): ExampleStoreInterface |
||
| 20 | { |
||
| 21 | $globalStore = new CombinedExampleStore(); |
||
| 22 | |||
| 23 | foreach ($inputs as $input) { |
||
| 24 | try { |
||
| 25 | $template = $this->parser->parseContent($input->getContents()); |
||
| 26 | |||
| 27 | $template->setDefaultNamespace($input->getName()); |
||
| 28 | |||
| 29 | $globalStore->addExampleStore($template->render()); |
||
| 30 | } catch (InvalidPhpCodeException $exception) { |
||
| 31 | throw new InvalidInputException($exception->getMessage(), $input, $exception->getPhpCode()); |
||
| 32 | } catch (\Exception $exception) { |
||
| 33 | throw new InvalidInputException($exception->getMessage(), $input, $exception->getMessage()); |
||
| 34 | } |
||
| 35 | } |
||
| 36 | |||
| 37 | return $globalStore; |
||
| 38 | } |
||
| 39 | } |
||
| 40 |