Passed
Push — dependabot/npm_and_yarn/docs/u... ( 28266c )
by
unknown
10:55 queued 02:13
created

Block::translatedInput()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
c 0
b 0
f 0
nc 4
nop 2
dl 0
loc 11
rs 10
1
<?php
2
3
namespace A17\Twill\Models;
4
5
use A17\Twill\Models\Behaviors\HasFiles;
6
use A17\Twill\Models\Behaviors\HasMedias;
7
use A17\Twill\Models\Behaviors\HasPresenter;
8
use A17\Twill\Models\Behaviors\HasRelated;
9
use Illuminate\Database\Eloquent\Model as BaseModel;
10
11
class Block extends BaseModel
12
{
13
    use HasMedias, HasFiles, HasPresenter, HasRelated;
0 ignored issues
show
introduced by
The trait A17\Twill\Models\Behaviors\HasFiles requires some properties which are not provided by A17\Twill\Models\Block: $role, $pivot, $uuid, $files, $locale
Loading history...
introduced by
The trait A17\Twill\Models\Behaviors\HasMedias requires some properties which are not provided by A17\Twill\Models\Block: $medias, $role, $pivot, $metadatas, $uuid, $height, $lqip_data, $crop_h, $locale, $video, $crop, $crop_w, $width
Loading history...
introduced by
The trait A17\Twill\Models\Behaviors\HasRelated requires some properties which are not provided by A17\Twill\Models\Block: $relatedItems, $related
Loading history...
14
15
    public $timestamps = false;
16
17
    protected $fillable = [
18
        'blockable_id',
19
        'blockable_type',
20
        'position',
21
        'content',
22
        'type',
23
        'child_key',
24
        'parent_id',
25
        'editor_name',
26
    ];
27
28
    protected $casts = [
29
        'content' => 'array',
30
    ];
31
32
    protected $with = ['medias'];
33
34
    public function scopeEditor($query, $name = 'default')
35
    {
36
        return $name === 'default' ?
37
            $query->where('editor_name', $name)->orWhereNull('editor_name') :
38
            $query->where('editor_name', $name);
39
    }
40
41
    public function blockable()
42
    {
43
        return $this->morphTo();
44
    }
45
46
    public function children()
47
    {
48
        return $this->hasMany('A17\Twill\Models\Block', 'parent_id');
49
    }
50
51
    public function input($name)
52
    {
53
        return $this->content[$name] ?? null;
0 ignored issues
show
Bug introduced by
The property content does not seem to exist on A17\Twill\Models\Block. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
54
    }
55
56
    public function translatedInput($name, $forceLocale = null)
57
    {
58
        $value = $this->content[$name] ?? null;
0 ignored issues
show
Bug introduced by
The property content does not seem to exist on A17\Twill\Models\Block. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
59
60
        $locale = $forceLocale ?? (
61
            config('translatable.use_property_fallback', false) && (!array_key_exists(app()->getLocale(), $value ?? []))
0 ignored issues
show
introduced by
The method getLocale() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

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

61
            config('translatable.use_property_fallback', false) && (!array_key_exists(app()->/** @scrutinizer ignore-call */ getLocale(), $value ?? []))
Loading history...
62
            ? config('translatable.fallback_locale')
63
            : app()->getLocale()
64
        );
65
66
        return $value[$locale] ?? null;
67
    }
68
69
    public function browserIds($name)
70
    {
71
        return isset($this->content['browsers']) ? ($this->content['browsers'][$name] ?? []) : [];
0 ignored issues
show
Bug introduced by
The property content does not seem to exist on A17\Twill\Models\Block. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
72
    }
73
74
    public function checkbox($name)
75
    {
76
        return isset($this->content[$name]) && ($this->content[$name][0] ?? $this->content[$name] ?? false);
0 ignored issues
show
Bug introduced by
The property content does not seem to exist on A17\Twill\Models\Block. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
77
    }
78
79
    public function getPresenterAttribute()
80
    {
81
        if (($presenter = config('twill.block_editor.block_presenter_path')) != null) {
82
            return $presenter;
83
        }
84
85
        return null;
86
    }
87
88
    public function getTable()
89
    {
90
        return config('twill.blocks_table', 'twill_blocks');
91
    }
92
}
93