Block   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __call() 0 15 2
A getShortcodeAttribute() 0 4 1
1
<?php
2
3
namespace Modules\Block\Entities;
4
5
use Dimsav\Translatable\Translatable;
6
use Illuminate\Database\Eloquent\Model;
7
use Laracasts\Presenter\PresentableTrait;
8
9
/**
10
 * Class Block
11
 * @property string $name
12
 * @property bool $online
13
 * @property string $body
14
 * @property string $shortcode
15
 */
16
class Block extends Model
17
{
18
    use Translatable, PresentableTrait;
19
20
    protected $presenter = 'Modules\Block\Presenters\BlockPresenter';
21
    protected $table = 'block__blocks';
22
    public $translatedAttributes = ['online', 'body'];
23
    protected $fillable = ['name', 'online', 'body'];
24
    protected $casts = [
25
        'online' => 'bool',
26
    ];
27
28
    public function __call($method, $parameters)
29
    {
30
        #i: Convert array to dot notation
31
        $config = implode('.', ['asgard.block.config.relations', $method]);
32
33
        #i: Relation method resolver
34
        if (config()->has($config)) {
35
            $function = config()->get($config);
36
37
            return $function($this);
38
        }
39
40
        #i: No relation found, return the call to parent (Eloquent) to handle it.
41
        return parent::__call($method, $parameters);
42
    }
43
44
    public function getShortcodeAttribute()
45
    {
46
        return sprintf('[[BLOCK(%s)]]', $this->name);
47
    }
48
}
49