Skip to content

Commit

Permalink
Add deprecation notice for missing method
Browse files Browse the repository at this point in the history
If a used sub renderer, which extends the main renderer, a deprecation
notice will be thrown when the sub renderer is missing method
`generateLinesIgnore`.
  • Loading branch information
DigiLive authored and DigiLive committed Dec 18, 2020
1 parent 19634bb commit 9403eba
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/jblond/Diff/Renderer/MainRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down

0 comments on commit 9403eba

Please sign in to comment.