Skip to content
This repository has been archived by the owner on Jan 21, 2021. It is now read-only.

Commit

Permalink
Add exception and remove trait
Browse files Browse the repository at this point in the history
  • Loading branch information
vinkla committed Nov 17, 2016
1 parent a8c0b94 commit 8d62100
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 22 deletions.
5 changes: 2 additions & 3 deletions src/Translatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Config;
use LogicException;

/**
* This is the translatable trait.
Expand Down Expand Up @@ -166,14 +165,14 @@ public function setAttribute($key, $value)
/**
* Get the translatable attributes array.
*
* @throws \LogicException
* @throws \Vinkla\Translator\TranslatableException
*
* @return array
*/
protected function getTranslatable(): array
{
if (!property_exists($this, 'translatable')) {
throw new LogicException('Missing property [translatable].');
throw new TranslatableException('Missing property [translatable].');
}

return $this->translatable;
Expand Down
13 changes: 4 additions & 9 deletions src/IsTranslatable.php → src/TranslatableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,14 @@

namespace Vinkla\Translator;

use Illuminate\Database\Eloquent\Relations\HasMany;
use LogicException;

/**
* This is the is translatable interface.
* This is the translatable exception class.
*
* @author Vincent Klaiber <hello@vinkla.com>
*/
interface IsTranslatable
class TranslatableException extends LogicException
{
/**
* Get the translations relation.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function translations(): HasMany;
//
}
3 changes: 1 addition & 2 deletions tests/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Vinkla\Translator\IsTranslatable;
use Vinkla\Translator\Translatable;

/**
* This is the article eloquent model class.
*
* @author Vincent Klaiber <hello@vinkla.com>
*/
class Article extends Model implements IsTranslatable
class Article extends Model
{
use Translatable;

Expand Down
8 changes: 0 additions & 8 deletions tests/TranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\DB;
use ReflectionClass;
use Vinkla\Translator\IsTranslatable;

/**
* This is the translator test class.
Expand All @@ -23,13 +22,6 @@
*/
class TranslatorTest extends AbstractTestCase
{
public function testInterface()
{
$article = new ReflectionClass(Article::class);

$this->assertTrue($article->implementsInterface(IsTranslatable::class));
}

public function testHasMany()
{
$article = Article::first();
Expand Down

0 comments on commit 8d62100

Please sign in to comment.