Skip to content

Commit 3111605

Browse files
committed
Let text renderers throw exception for renderArray()
Signed-off-by: Jack Cherng <jfcherng@gmail.com>
1 parent 8235504 commit 3111605

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Jfcherng\Diff\Exception;
6+
7+
final class UnsupportedFunctionException extends \Exception
8+
{
9+
public function __construct(string $funcName = '', int $code = 0, \Throwable $previous = null)
10+
{
11+
parent::__construct("Unsupported function: {$funcName}", $code, $previous);
12+
}
13+
}

src/Renderer/RendererInterface.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Jfcherng\Diff\Renderer;
66

77
use Jfcherng\Diff\Differ;
8+
use Jfcherng\Diff\Exception\UnsupportedFunctionException;
89

910
/**
1011
* Renderer Interface.
@@ -22,13 +23,13 @@ public function getResultForIdenticals(): string;
2223
* @param Differ $differ the Differ object to be rendered
2324
*/
2425
public function render(Differ $differ): string;
25-
26+
2627
/**
2728
* Render the differ array and return the result.
2829
*
2930
* @param array $differArray the Differ array to be rendered
3031
*
31-
* @return string
32+
* @throws UnsupportedFunctionException if the renderer does not support this method
3233
*/
3334
public function renderArray(array $differArray): string;
3435
}

src/Renderer/Text/AbstractText.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Jfcherng\Diff\Renderer\Text;
66

7+
use Jfcherng\Diff\Exception\UnsupportedFunctionException;
78
use Jfcherng\Diff\Renderer\AbstractRenderer;
89

910
/**
@@ -23,20 +24,24 @@ public function getResultForIdenticalsDefault(): string
2324
{
2425
return '';
2526
}
26-
27+
2728
/**
2829
* {@inheritdoc}
2930
*/
3031
public function renderArrayWoker(array $differArray): string
3132
{
33+
throw new UnsupportedFunctionException(__METHOD__);
34+
3235
return '';
3336
}
34-
37+
3538
/**
3639
* {@inheritdoc}
3740
*/
3841
public function baseWoker(array $changes): string
3942
{
43+
throw new UnsupportedFunctionException(__METHOD__);
44+
4045
return '';
4146
}
4247
}

0 commit comments

Comments
 (0)