Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
29.03% covered (danger)
29.03%
9 / 31
33.33% covered (danger)
33.33%
2 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
VraisemblanceGraviteDictionary
29.03% covered (danger)
29.03%
9 / 31
33.33% covered (danger)
33.33%
2 / 6
148.03
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 getVraisemblanceGravite
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 getMasculineValues
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 offsetGet
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
6
 getPoidsFromImpact
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
42
 getImpact
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
56
1<?php
2
3declare(strict_types=1);
4
5namespace App\Domain\AIPD\Dictionary;
6
7use App\Application\Dictionary\SimpleDictionary;
8use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
9
10class VraisemblanceGraviteDictionary extends SimpleDictionary
11{
12    public const NEGLIGEABLE = 'negligeable';
13    public const LIMITEE     = 'limitee';
14    public const IMPORTANTE  = 'importante';
15    public const MAXIMALE    = 'maximale';
16
17    public function __construct(string $name = 'vraisemblance_gravite', array $values = [])
18    {
19        if (empty($values)) {
20            $values = self::getVraisemblanceGravite();
21        }
22        parent::__construct($name, $values);
23    }
24
25    public static function getVraisemblanceGravite(): array
26    {
27        return [
28            self::NEGLIGEABLE => 'Négligeable',
29            self::LIMITEE     => 'Limitée',
30            self::IMPORTANTE  => 'Importante',
31            self::MAXIMALE    => 'Maximale',
32        ];
33    }
34
35    public static function getMasculineValues()
36    {
37        return [
38            self::NEGLIGEABLE => 'Négligeable',
39            self::LIMITEE     => 'Limité',
40            self::IMPORTANTE  => 'Important',
41            self::MAXIMALE    => 'Maximal',
42        ];
43    }
44
45    public function offsetGet($offset): mixed
46    {
47        return isset(self::getVraisemblanceGravite()[$offset]) ? self::getVraisemblanceGravite()[$offset] : '';
48    }
49
50    public static function getPoidsFromImpact(string $key): int
51    {
52        if (array_key_exists($key, array_keys(self::getVraisemblanceGravite()))) {
53            throw new NotFoundHttpException('Key ' . $key . ' not found in VraisemblanceGraviteDictionary');
54        }
55
56        switch ($key) {
57            case self::NEGLIGEABLE:
58                return 1;
59            case self::LIMITEE:
60                return 2;
61            case self::IMPORTANTE:
62                return 3;
63            default:
64                return 4;
65        }
66    }
67
68    public static function getImpact(int $poids): string
69    {
70        if ($poids < 1 || $poids > 4) {
71            throw new NotFoundHttpException('No values for poids ' . $poids . ' has been found in VraisemblanceGraviteDictionary');
72        }
73        switch ($poids) {
74            case 1:
75                return self::NEGLIGEABLE;
76            case 2:
77                return self::LIMITEE;
78            case 3:
79                return self::IMPORTANTE;
80            default:
81                return self::MAXIMALE;
82        }
83    }
84}