Test Failed
Push — dev ( 1dc13c...3f81c0 )
by Yan
02:20
created

Lincable::addLincableField()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Lincable\Eloquent;
4
5
use Lincable\MediaManager;
6
use Illuminate\Container\Container;
7
use Lincable\Http\File\FileResolver;
8
9
trait Lincable
10
{
11
    /**
12
     * Boot the model statically.
13
     * 
14
     * @return void
15
     */
16
    public static function bootLincable()
17
    {
18
        static::creating(function ($model) {
19
            $model->addLincableFields();
20
        });
21
    }
22
23
    /**
24
     * Add the lincable fields to model fillables.
25
     * 
26
     * @return void
27
     */
28
    public function addLincableField()
29
    {
30
        // Get the model fillable fields.
31
        $fillables = $this->getFillable();
0 ignored issues
show
Bug introduced by
It seems like getFillable() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

31
        /** @scrutinizer ignore-call */ 
32
        $fillables = $this->getFillable();
Loading history...
32
33
        $this->fillable(array_merge($fillables, [$this->getUrlField()]));
0 ignored issues
show
Bug introduced by
It seems like fillable() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
        $this->/** @scrutinizer ignore-call */ 
34
               fillable(array_merge($fillables, [$this->getUrlField()]));
Loading history...
34
    }
35
36
    /**
37
     * Link the model to a file.
38
     * 
39
     * @param  mixed $file
40
     * @return this
41
     */
42
    public function link($file)
43
    {
44
        // Resolve the file object to link the model. It can
45
        // be a symfony uploaded file or a file request, which 
46
        // is preferable for linking. 
47
        $file = FileResolver::resolve($file);
0 ignored issues
show
Unused Code introduced by
The assignment to $file is dead and can be removed.
Loading history...
48
    }
49
50
    /**
51
     * Return the url field to link the model.
52
     * 
53
     * @return string
54
     */
55
    public function getUrlField()
56
    {
57
        return config('lincable.models.url_field');
0 ignored issues
show
Bug Best Practice introduced by
The expression return config('lincable.models.url_field') also could return the type array which is incompatible with the documented return type string.
Loading history...
58
    }
59
60
    /**
61
     * Return a media manager instance.
62
     * 
63
     * @return \Lincable\MediaManager
64
     */
65
    protected function getMediaManager() 
66
    {
67
        return Container::getInstance()->make(MediaManager::class);
68
    }
69
}