| Conditions | 3 |
| Paths | 3 |
| Total Lines | 14 |
| Code Lines | 6 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 7 |
| CRAP Score | 3 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 35 | 3 | public function averageRate(int $round = 2): float |
|
| 36 | { |
||
| 37 | 3 | if (!$this->canBeRated()) { |
|
| 38 | 1 | return 0; |
|
| 39 | } |
||
| 40 | |||
| 41 | /** @var Builder $rates */ |
||
| 42 | 2 | $rates = $this->comments()->approvedComments(); |
|
| 43 | |||
| 44 | 2 | if (!$rates->exists()) { |
|
| 45 | 2 | return 0; |
|
| 46 | } |
||
| 47 | |||
| 48 | 2 | return round((float)$rates->avg('rate'), $round); |
|
| 49 | } |
||
| 60 |