Completed
Push — master ( cc3f25...fdac0f )
by Nicolas
02:44
created

Video::getEmbed()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
crap 2
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 4
    public function getEmbed()
19
    {
20 4
        $sourceClass = config("laravel-videoable.sources.{$this->source}");
21
22 4
        if (class_exists($sourceClass) === false) {
23 1
            throw new VideoPresenterNotFound($sourceClass);
24
        }
25
26 3
        return (new $sourceClass(get_object_vars($this)))->getEmbedCode();
27
    }
28
}
29