Passed
Push — activity-logs ( 8cf388 )
by Fèvre
06:45
created

ActivityLogRepository   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 23
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A update() 0 13 1
1
<?php
2
namespace Xetaravel\Models\Repositories;
3
4
use Xetaravel\Models\ActivityLog;
5
6
class ActivityLogRepository
7
{
8
    /**
9
     * Update the activity log if it exist or create and save it.
10
     *
11
     * @param array $data The data used to update/create the log.
12
     * @param int $id The user id related to the activity log.
13
     *
14
     * @return \Xetaravel\Models\ActivityLog
15
     */
16
    public static function update(array $data, int $id): ActivityLog
17
    {
18
        return ActivityLog::updateOrCreate(
19
            [
20
                'user_id' => $id
21
            ],
22
            [
23
                'user_id' => $id,
24
                'method' => $data['method'],
25
                'ip' => $data['ip'],
26
                'url' => $data['url'],
27
                'user_agent' => $data['user_agent'],
28
                'last_activity' => $data['last_activity']
29
            ]
30
        );
31
    }
32
}
33