Completed
Push — master ( fe8823...ee74ca )
by Michael
01:24
created

EfficientUuid   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 32
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 4 1
A set() 0 6 1
1
<?php
2
3
namespace Dyrynda\Database\Casts;
4
5
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
6
7
class EfficientUuid implements CastsAttributes
8
{
9
    /**
10
     * Transform the attribute from the underlying model values.
11
     *
12
     * @param  \Illuminate\Database\Eloquent\Model  $model
13
     * @param  string  $key
14
     * @param  mixed  $value
15
     * @param  array  $attributes
16
     * @return mixed
17
     */
18
    public function get($model, string $key, $value, array $attributes)
19
    {
20
        return $model->resolveUuid()->fromBytes($value)->toString();
21
    }
22
23
    /**
24
     * Transform the attribute to its underlying model values.
25
     *
26
     * @param  \Illuminate\Database\Eloquent\Model  $model
27
     * @param  string  $key
28
     * @param  mixed  $value
29
     * @param  array  $attributes
30
     * @return array
31
     */
32
    public function set($model, string $key, $value, array $attributes)
33
    {
34
        return [
35
            $key => $model->resolveUuid()->fromString(strtolower($value))->getBytes(),
36
        ];
37
    }
38
}
39