CamelMutatorTrait::setAttribute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 2
b 0
f 0
nc 2
nop 2
dl 0
loc 7
rs 10
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: frowhy
5
 * Date: 2019/2/26
6
 * Time: 11:10 AM.
7
 */
8
9
namespace Modules\Core\Traits;
10
11
use Illuminate\Support\Str;
12
13
trait CamelMutatorTrait
14
{
15
    public function getAttribute($key)
16
    {
17
        if (!method_exists($this, $key)) {
18
            $key = Str::snake($key);
19
        }
20
21
        return parent::getAttribute($key);
22
    }
23
24
    public function setAttribute($key, $value)
25
    {
26
        if (!method_exists($this, $key)) {
27
            $key = Str::snake($key);
28
        }
29
30
        return parent::setAttribute($key, $value);
31
    }
32
}
33