Completed
Push — master ( eddec1...1fdb05 )
by Nicolas
03:17
created

Block::__call()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.4286
cc 2
eloc 6
nc 2
nop 2
1
<?php namespace Modules\Block\Entities;
2
3
use Dimsav\Translatable\Translatable;
4
use Illuminate\Database\Eloquent\Model;
5
use Laracasts\Presenter\PresentableTrait;
6
7
class Block extends Model
8
{
9
    use Translatable, PresentableTrait;
10
11
    protected $presenter = 'Modules\Block\Presenters\BlockPresenter';
12
    protected $table = 'block__blocks';
13
    public $translatedAttributes = ['online', 'body'];
14
    protected $fillable = ['name', 'online', 'body'];
15
    protected $casts = [
16
        'online' => 'bool',
17
    ];
18
19
    public function __call($method, $parameters)
20
    {
21
        #i: Convert array to dot notation
22
        $config = implode('.', ['asgard.block.config.relations', $method]);
23
24
        #i: Relation method resolver
25
        if (config()->has($config)) {
26
            $function = config()->get($config);
27
28
            return $function($this);
29
        }
30
31
        #i: No relation found, return the call to parent (Eloquent) to handle it.
32
        return parent::__call($method, $parameters);
33
    }
34
}
35