Skip to content

Commit c2fb10e

Browse files
committedFeb 13, 2022
refactoring
1 parent aad0d60 commit c2fb10e

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed
 

Diff for: ‎src/Exceptions/PresenterException.php

+15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Coderflex\LaravelPresenter\Exceptions;
44

55
use Exception;
6+
use Illuminate\Database\Eloquent\Model;
67

78
class PresenterException extends Exception
89
{
@@ -19,4 +20,18 @@ class PresenterException extends Exception
1920
* @var int
2021
*/
2122
protected $code = 500;
23+
24+
/**
25+
* Method for Presenter Implementation absence on the model
26+
* @param Model $model
27+
* @return self
28+
*/
29+
public static function interfaceNotImplemented(Model $model): self
30+
{
31+
return new self((__(':model should implements :interface interface', [
32+
'model' => get_class($model),
33+
'interface' => '\Coderflex\LaravelPresenter\Concerns\CanPresent',
34+
])
35+
));
36+
}
2237
}

Diff for: ‎src/Presenter.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@ abstract class Presenter
1717
public function __construct(Model $model)
1818
{
1919
if (! $model instanceof \Coderflex\LaravelPresenter\Concerns\CanPresent) {
20-
throw new PresenterException(
21-
__(':model should implements :interface interface', [
22-
'model' => get_class($model),
23-
'interface' => '\Coderflex\LaravelPresenter\Concerns\CanPresent',
24-
])
25-
);
20+
throw PresenterException::interfaceNotImplemented($model);
2621
}
2722

2823
$this->model = $model;

0 commit comments

Comments
 (0)
Please sign in to comment.