EloquentWidgetRepository   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 3
c 3
b 0
f 1
lcom 0
cbo 0
dl 0
loc 28
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A findForUser() 0 4 1
A updateOrCreateForUser() 0 10 2
1
<?php namespace Modules\Dashboard\Repositories\Eloquent;
2
3
use Modules\Core\Repositories\Eloquent\EloquentBaseRepository;
4
use Modules\Dashboard\Repositories\WidgetRepository;
5
6
class EloquentWidgetRepository extends EloquentBaseRepository implements WidgetRepository
7
{
8
    /**
9
     * Find the saved state of widgets for the given user id
10
     * @param int $userId
11
     * @return string
12
     */
13
    public function findForUser($userId)
14
    {
15
        return $this->model->whereUserId($userId)->first();
16
    }
17
18
    /**
19
     * Update or create the given widgets for given user
20
     * @param array $widgets
21
     * @return void
22
     */
23
    public function updateOrCreateForUser($widgets, $userId)
24
    {
25
        $widget = $this->findForUser($userId);
26
27
        if ($widget) {
28
            return $this->update($widget, ['widgets' => $widgets]);
29
        }
30
31
        return $this->create(['widgets' => $widgets, 'user_id' => $userId]);
32
    }
33
}
34