HasTraitsWithCasts::getCasts()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 0
dl 0
loc 13
ccs 7
cts 7
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace IproSync\Models;
4
5
trait HasTraitsWithCasts
6
{
7 3
    public function getCasts()
8
    {
9 3
        $class = static::class;
10
11 3
        foreach (class_uses_recursive($class) as $trait) {
12 3
            $method = 'get'.class_basename($trait).'CastsAttr';
13
14 3
            if (method_exists($class, $method)) {
15 3
                $this->casts = array_merge($this->casts, $this->{$method}());
0 ignored issues
show
Bug Best Practice introduced by
The property casts does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
16
            }
17
        }
18
19 3
        return parent::getCasts();
20
    }
21
}
22