EntryType::deleteEntryType()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 5
cp 0
crap 2
rs 10
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