Completed
Push — master ( 1b6da9...0cf1ab )
by Nicolas
07:59
created

Video::getEmbed()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 8
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
crap 6
1
<?php
2
3
namespace Nwidart\LaravelVideoable\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Nwidart\LaravelVideoable\Exceptions\VideoPresenterNotFound;
7
8
class Video extends Model
9
{
10
    protected $table = 'laravel_videoables';
11
    protected $fillable = ['source', 'code', 'title', 'width', 'height', 'videoable_id', 'videoable_type'];
12
13
    public function videoable()
14
    {
15
        return $this->morphTo();
16
    }
17
18
    public function getEmbed()
19
    {
20
        $sourceClass = config("laravel-videoable.sources.{$this->source}");
21
22
        if (class_exists($sourceClass) === false) {
23
            throw new VideoPresenterNotFound($sourceClass);
24
        }
25
26
        return (new $sourceClass(get_object_vars($this)))->getEmbedCode();
27
    }
28
}
29