From f494b3abd15c55a5050498d95c1222c522191407 Mon Sep 17 00:00:00 2001 From: DigiLive Date: Thu, 17 Dec 2020 07:28:05 +0100 Subject: [PATCH] Add deprecation notice for missing method If a used sub renderer, which extends the main renderer, a deprecation notice will be thrown when the sub renderer is missing method `generateLinesIgnore`. --- lib/jblond/Diff/Renderer/MainRenderer.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/jblond/Diff/Renderer/MainRenderer.php b/lib/jblond/Diff/Renderer/MainRenderer.php index b24459f..05e71cf 100644 --- a/lib/jblond/Diff/Renderer/MainRenderer.php +++ b/lib/jblond/Diff/Renderer/MainRenderer.php @@ -65,7 +65,23 @@ public function renderOutput(array $changes, object $subRenderer) strlen($this->options['equalityMarkers'][1]) ); + $deprecationTriggered = false; foreach ($blocks as $change) { + if ( + $subRenderer instanceof MainRenderer && + !method_exists($subRenderer, 'generateLinesIgnore') && + $change['tag'] == 'ignore' + ) { + if (!$deprecationTriggered) { + trigger_error( + 'The use of a subRenderer without method generateLinesIgnore() is deprecated!', + E_USER_DEPRECATED + ); + $deprecationTriggered = true; + } + $change['tag'] = + (count($change['base']['lines']) > count($change['changed']['lines'])) ? 'delete' : 'insert'; + } $output .= $subRenderer->generateBlockHeader($change); switch ($change['tag']) { case 'equal':