granularity = $granularity ?? new Character(); $this->renderer = $renderer ?? new Html(); $this->parser = $parser ?? new Parser($this->granularity); } /** * Returns the granularity object used by the parser. */ public function getGranularity(): GranularityInterface { return $this->parser->getGranularity(); } /** * Set the granularity level of the parser. */ public function setGranularity(GranularityInterface $granularity): void { $this->parser->setGranularity($granularity); } /** * Get the render. */ public function getRenderer(): RendererInterface { return $this->renderer; } /** * Set the renderer. */ public function setRenderer(RendererInterface $renderer): void { $this->renderer = $renderer; } /** * Get the parser responsible for generating the diff/opcodes. */ public function getParser(): ParserInterface { return $this->parser; } /** * Set the parser. */ public function setParser(ParserInterface $parser): void { $this->parser = $parser; } /** * Gets the diff / opcodes between two strings. * * Returns the opcode diff which can be used for example * to generate HTML report of the differences. */ public function getOpcodes(string $from_text, string $to_text): OpcodesInterface { return $this->parser->parse($from_text, $to_text); } /** * Render the difference between two strings. * By default, will return the difference as HTML. */ public function render(string $from_text, string $to_text): string { // First we need the opcodes $opcodes = $this->getOpcodes($from_text, $to_text); return $this->renderer->process($from_text, $opcodes); } }