Conditions | 3 |
Paths | 4 |
Total Lines | 12 |
Code Lines | 5 |
Lines | 0 |
Ratio | 0 % |
Tests | 4 |
CRAP Score | 3.072 |
Changes | 0 |
1 | <?php |
||
30 | 8 | protected function getCountAttribute($field) |
|
31 | { |
||
32 | // if relation is not loaded already, let's do it first |
||
33 | 8 | if (!array_key_exists($field, $this->relations)) { |
|
|
|||
34 | $this->load($field); |
||
35 | } |
||
36 | |||
37 | 8 | $related = $this->getRelation($field); |
|
38 | |||
39 | // then return the count directly |
||
40 | 8 | return ($related) ? (int) $related->aggregate : 0; |
|
41 | } |
||
42 | |||
61 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: