Passed
Pull Request — master (#12)
by
unknown
02:23 queued 19s
created

ExpoDatabaseDriver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 44
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A store() 0 9 1
A retrieve() 0 4 1
A forget() 0 4 1
1
<?php
2
3
namespace NotificationChannels\ExpoPushNotifications\Repositories;
4
5
use ExponentPhpSDK\ExpoRepository;
6
use NotificationChannels\ExpoPushNotifications\Models\Interest;
7
8
class ExpoDatabaseDriver implements ExpoRepository
9
{
10
    /**
11
     * Stores an Expo token with a given identifier.
12
     *
13
     * @param $key
14
     * @param $value
15
     *
16
     * @return bool
17
     */
18
    public function store($key, $value): bool
19
    {
20
        $interest = Interest::firstOrCreate([
21
            'key' => $key,
22
            'value' => $value,
23
        ]);
24
25
        return $interest instanceof Interest;
26
    }
27
28
    /**
29
     * Retrieves an Expo token with a given identifier.
30
     *
31
     * @param string $key
32
     *
33
     * @return string|null
34
     */
35
    public function retrieve(string $key)
36
    {
37
        return Interest::where('key', $key)->pluck('value')->toArray();
38
    }
39
40
    /**
41
     * Removes an Expo token with a given identifier.
42
     *
43
     * @param string $key
44
     *
45
     * @return bool
46
     */
47
    public function forget(string $key): bool
48
    {
49
        return Interest::where('key', $key)->delete();
50
    }
51
}