CamelMutatorTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 7
c 2
b 0
f 0
dl 0
loc 18
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setAttribute() 0 7 2
A getAttribute() 0 7 2
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