Test Setup Failed
Push — a-simpler-manager ( cc67c7...cc5aa5 )
by Ben
07:45
created

FragmentModel   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 17
c 1
b 0
f 0
dl 0
loc 47
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A dynamicDocumentKey() 0 3 1
A fields() 0 3 1
A managedModelKey() 0 3 1
A dynamicLocales() 0 3 1
A isOffline() 0 3 1
A isOnline() 0 4 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Thinktomorrow\Chief\Fragments\Database;
5
6
use Thinktomorrow\AssetLibrary\HasAsset;
7
use Thinktomorrow\AssetLibrary\AssetTrait;
8
use Thinktomorrow\Chief\ManagedModels\Fields\Fields;
9
use Illuminate\Database\Eloquent\Model;
10
use Thinktomorrow\Chief\ManagedModels\ManagedModel;
11
use Thinktomorrow\DynamicAttributes\HasDynamicAttributes;
12
use Thinktomorrow\Chief\ManagedModels\Assistants\ManagedModelDefaults;
13
14
final class FragmentModel extends Model implements ManagedModel, HasAsset
15
{
16
    use ManagedModelDefaults;
0 ignored issues
show
Bug introduced by
The trait Thinktomorrow\Chief\Mana...ts\ManagedModelDefaults requires the property $title which is not provided by Thinktomorrow\Chief\Frag...\Database\FragmentModel.
Loading history...
17
    use HasDynamicAttributes;
0 ignored issues
show
Bug introduced by
The trait Thinktomorrow\DynamicAtt...es\HasDynamicAttributes requires the property $dynamicLocales which is not provided by Thinktomorrow\Chief\Frag...\Database\FragmentModel.
Loading history...
18
    use AssetTrait;
0 ignored issues
show
introduced by
The trait Thinktomorrow\AssetLibrary\AssetTrait requires some properties which are not provided by Thinktomorrow\Chief\Frag...\Database\FragmentModel: $assetRelation, $pivot, $fallbackPath, $assetFallbackLocale, $each, $locale, $mediaConversionRegistrations, $forceDeleting, $useAssetFallbackLocale, $fallbackUrl, $media, $collection_name
Loading history...
19
20
    public $table = 'context_fragments';
21
    public $guarded = [];
22
23
    // Allow for uuid
24
    protected $keyType = 'string';
25
    public $incrementing = false;
26
27
    public $dynamicKeys = ['*'];
28
    public $dynamicKeysBlacklist = [
29
        'id', 'context_id', 'model_reference', 'order', 'created_at', 'updated_at',
30
    ];
31
32
    public static function managedModelKey(): string
33
    {
34
        return 'fragments';
35
    }
36
37
    public function fields(): Fields
38
    {
39
        return new Fields();
40
    }
41
42
    protected function dynamicDocumentKey(): string
43
    {
44
        return 'data';
45
    }
46
47
    protected function dynamicLocales(): array
48
    {
49
        return config('chief.locales', []);
50
    }
51
52
    public function isOnline(): bool
53
    {
54
        // Default is online, except explicitly set offline
55
        return (null === $this->online_status || $this->online_status != 0);
0 ignored issues
show
Bug introduced by
The property online_status does not seem to exist on Thinktomorrow\Chief\Frag...\Database\FragmentModel. 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...
56
    }
57
58
    public function isOffline(): bool
59
    {
60
        return !$this->isOnline();
61
    }
62
}
63