EntryType   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 41
ccs 0
cts 24
cp 0
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A deleteEntryType() 0 5 1
A upsertEntryType() 0 17 2
1
<?php
2
3
namespace Distilleries\Contentful\Repositories\Traits;
4
5
use Illuminate\Support\Facades\DB;
6
7
trait EntryType
8
{
9
    /**
10
     * Insert / update entry type for given Contentful entry.
11
     *
12
     * @param  array  $entry
13
     * @param  string  $contentfulType
14
     * @return void
15
     */
16
    protected function upsertEntryType(array $entry, string $contentfulType)
17
    {
18
        $pivot = DB::table('entry_types')
19
            ->where('contentful_id', '=', $entry['sys']['id'])
20
            ->first();
21
22
        if (empty($pivot)) {
23
            DB::table('entry_types')
24
                ->insert([
25
                    'contentful_id' => $entry['sys']['id'],
26
                    'contentful_type' => $contentfulType,
27
                ]);
28
        } else {
29
            DB::table('entry_types')
30
                ->where('contentful_id', '=', $entry['sys']['id'])
31
                ->update([
32
                    'contentful_type' => $contentfulType,
33
                ]);
34
        }
35
    }
36
37
    /**
38
     * Delete entry types for given Contentful entry.
39
     *
40
     * @param  string  $entryId
41
     * @return void
42
     */
43
    protected function deleteEntryType(string $entryId)
44
    {
45
        DB::table('entry_types')
46
            ->where('contentful_id', '=', $entryId)
47
            ->delete();
48
    }
49
}
50