EntryRelationship   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 53
ccs 0
cts 8
cp 0
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A getRelatedEntry() 0 10 2
1
<?php
2
3
namespace Distilleries\Contentful\Models;
4
5
use Distilleries\Contentful\Models\Base\ContentfulModel;
6
7
/**
8
 * @property string $locale
9
 * @property string $country
10
 * @property string $source_contentful_id
11
 * @property string $source_contentful_type
12
 * @property string $related_contentful_id
13
 * @property string $related_contentful_type
14
 * @property integer $order
15
 * @property string $relation
16
 */
17
class EntryRelationship extends ContentfulModel
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22
    protected $table = 'entry_relationships';
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    protected $primaryKey = null;
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public $incrementing = false;
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    protected $fillable = [
38
        'locale',
39
        'country',
40
        'source_contentful_id',
41
        'source_contentful_type',
42
        'related_contentful_id',
43
        'related_contentful_type',
44
        'order',
45
        'relation',
46
    ];
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    protected $casts = [
52
        'order' => 'integer'
53
    ];
54
55
    /**
56
     * Get Contentful related entry.
57
     *
58
     * @return mixed
59
     */
60
    public function getRelatedEntry()
61
    {
62
        $localModel = rtrim(config('contentful.namespaces.model'), '\\') . '\\' . ucfirst($this->source_contentful_type);
63
        if (! class_exists($localModel)) {
64
            return null;
65
        }
66
67
        $model = (new $localModel);
68
69
        return $model->locale()->where($model->getKeyName(), '=', $this->source_contentful_type)->first();
70
    }
71
}
72