Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
43.75% covered (danger)
43.75%
7 / 16
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
ReponseMesureProtectionDictionary
43.75% covered (danger)
43.75%
7 / 16
66.67% covered (warning)
66.67%
2 / 3
27.80
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getReponses
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
4
 getPoidsIndexFromReponse
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
30
1<?php
2
3declare(strict_types=1);
4
5namespace App\Domain\AIPD\Dictionary;
6
7use App\Application\Dictionary\SimpleDictionary;
8use App\Domain\AIPD\Model\AnalyseImpact;
9use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
10
11class ReponseMesureProtectionDictionary extends SimpleDictionary
12{
13    public const INSATISFAISANT      = 'insatisfaisant';
14    public const BESOIN_AMELIORATION = 'besoin_amelioration';
15    public const SATISFAISANT        = 'satisfaisant';
16
17    protected AnalyseImpact $aipd;
18
19    public function __construct(AnalyseImpact $aipd)
20    {
21        parent::__construct('reponse_mesure_protection', self::getReponses($aipd));
22        $this->aipd = $aipd;
23    }
24
25    public static function getReponses(AnalyseImpact $aipd)
26    {
27        return [
28            self::INSATISFAISANT      => $aipd->getLabelInsatisfaisant() ? $aipd->getLabelInsatisfaisant() : 'Insatisfaisant',
29            self::BESOIN_AMELIORATION => $aipd->getLabelAmeliorationPrevue() ? $aipd->getLabelAmeliorationPrevue() : 'Amélioration Prévue',
30            self::SATISFAISANT        => $aipd->getLabelSatisfaisant() ? $aipd->getLabelSatisfaisant() : 'Satisfaisant',
31        ];
32    }
33
34    public static function getPoidsIndexFromReponse(?string $reponse, AnalyseImpact $aipd): float
35    {
36        if (null === $reponse) {
37            return 0;
38        }
39        if (!array_key_exists($reponse, self::getReponses($aipd))) {
40            throw new NotFoundHttpException('Key ' . $reponse . ' not found in ReponseMesureProtectionDictionary');
41        }
42
43        if (self::SATISFAISANT === $reponse) {
44            return 1;
45        } elseif (self::BESOIN_AMELIORATION === $reponse) {
46            return 0.5;
47        }
48
49        return 0;
50    }
51}