Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
90.00% covered (success)
90.00%
9 / 10
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
ConformiteOrganisationConformiteCalculator
90.00% covered (success)
90.00%
9 / 10
50.00% covered (danger)
50.00%
1 / 2
6.04
0.00% covered (danger)
0.00%
0 / 1
 calculEvaluationConformites
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 calculConformite
87.50% covered (warning)
87.50%
7 / 8
0.00% covered (danger)
0.00%
0 / 1
4.03
1<?php
2
3namespace App\Domain\Registry\Calculator;
4
5use App\Domain\Registry\Dictionary\ConformiteOrganisation\ReponseDictionary;
6use App\Domain\Registry\Model\ConformiteOrganisation\Conformite;
7use App\Domain\Registry\Model\ConformiteOrganisation\Evaluation;
8
9class ConformiteOrganisationConformiteCalculator
10{
11    public function calculEvaluationConformites(Evaluation $evaluation)
12    {
13        foreach ($evaluation->getConformites() as $conformite) {
14            $conformite->setConformite($this->calculConformite($conformite));
15        }
16    }
17
18    private function calculConformite(Conformite $conformite): float
19    {
20        $nbReponse = 0;
21        $score     = 0;
22        foreach ($conformite->getReponses() as $reponse) {
23            if (ReponseDictionary::NON_CONCERNE === $reponse->getReponse()) {
24                continue;
25            }
26            $score += $reponse->getReponse();
27            ++$nbReponse;
28        }
29
30        return 0 !== $nbReponse ? round($score / $nbReponse, 2) : 0;
31    }
32}