Completed
Pull Request — master (#25)
by Karl
05:00
created

CustomDatabaseNotification   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 29
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A search() 0 4 1
A save() 0 10 3
1
<?php namespace JobApis\JobsToMail\Models;
2
3
use Illuminate\Notifications\DatabaseNotification;
4
5
class CustomDatabaseNotification extends DatabaseNotification
6
{
7
    /**
8
     * Defines the relationship to Search model
9
     *
10
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
11
     */
12 1
    public function search()
13
    {
14 1
        return $this->belongsTo(Search::class);
15
    }
16
17
    /**
18
     * Overrides the save method so that search IDs can be added to the Notification
19
     * in the database
20
     *
21
     * @param array $options
22
     */
23 2
    public function save(array $options = [])
24
    {
25
        // Set the jobs and search id into their own fields
26 2
        $data = $this->data;
27 2
        if (isset($data['search_id']) && isset($data['jobs'])) {
28 1
            $this->data = $data['jobs'];
29 1
            $this->search_id = $data['search_id'];
30
        }
31 2
        parent::save();
32 2
    }
33
}
34