/**
  * @param string $type
  * @param string $name
  * @param mixed $value
  * @param bool $optionnal
  *
  * @throws ResponseCode
  * @throws \Exception
  *
  * @return array|bool|float|string
  */
 private function getFinalValue(string $type, string $name, $value, bool $optionnal)
 {
     if ($optionnal && ($value === null || $value === '')) {
         return null;
     }
     if (strpos($type, '[]') !== false) {
         $return = [];
         foreach (is_array($value) ? $value : [$value] as $sKey => $currentValue) {
             $return[$sKey] = $this->getFinalValue(str_replace('[]', '', $type), $name, $currentValue, $optionnal);
         }
         return $return;
     }
     switch ($type) {
         case 'int':
             $value = filter_var($value, FILTER_VALIDATE_INT, ['flags' => FILTER_NULL_ON_FAILURE]);
             if (is_null($value)) {
                 throw new ResponseCode("Invalid integer parameters '{$name}' with value '{$value}'", 422);
             }
             break;
         case 'float':
             $value = filter_var($value, FILTER_VALIDATE_FLOAT, ['flags' => FILTER_NULL_ON_FAILURE]);
             if (is_null($value)) {
                 throw new ResponseCode("Invalid float parameters '{$name}' with value '{$value}'", 422);
             }
             break;
         case 'string':
             if (!is_string($value) || !$value) {
                 throw new ResponseCode("Invalid string parameters '{$name}' with value '{$value}'", 422);
             }
             break;
         case 'bool':
             if ($value !== '1' && $value !== 1 && $value !== '0' && $value !== 0 && $value !== 'true' && $value !== 'false') {
                 throw new ResponseCode("Invalid bool parameters '{$name}' with value '{$value}'", 422);
             }
             if ($value == '1') {
                 $value = true;
             } elseif ($value === 'true') {
                 $value = true;
             } elseif ($value == '0') {
                 $value = false;
             } elseif ($value === 'false') {
                 $value = false;
             }
             if (!is_bool($value)) {
                 throw new ResponseCode("Invalid bool parameters '{$name}' with value '{$value}'", 422);
             }
             break;
         case '\\Cawa\\SwaggerServer\\DateTime':
             $value = DateTime::createFromInput($value);
             break;
         case 'array':
             if (!is_array($value)) {
                 $jsonValue = @json_decode($value, true);
                 if ($jsonValue === false || !is_array($jsonValue)) {
                     throw new ResponseCode("Invalid array parameters '{$name}' with value '{$value}'", 422);
                 }
                 $value = $jsonValue;
             }
             break;
         case 'mixed':
             if (is_numeric($value)) {
                 $value = 0 + $value;
             }
             break;
         default:
             throw new \Exception('Invalid ' . $type . " parameters '{$name}' with value '{$value}'");
             break;
     }
     return $value;
 }