Video   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 71.43%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 21
ccs 5
cts 7
cp 0.7143
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A videoable() 0 4 1
A getEmbed() 0 10 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}");
0 ignored issues
show
Documentation introduced by
The property source does not exist on object<Nwidart\LaravelVideoable\Models\Video>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
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