This commit is contained in:
Andrea Bontempi 2021-12-23 12:35:55 +01:00
parent c46d884740
commit ff12d97129
4 changed files with 10 additions and 10 deletions

View file

@ -49,19 +49,19 @@ class CsvLine extends ArrayObject {
}
/**
* @param string $name
* @param string|int $name
* @return bool
*/
private function existsField(string $name): bool {
private function existsField(string|int $name): bool {
return array_key_exists($name, $this->headerList) && !is_null($this->headerList[$name]->getIndex());
}
/**
* @param string $name
* @param string|int $name
* @return mixed
* @throws ParserException
*/
private function getField(string $name): mixed {
private function getField(string|int $name): mixed {
if(!$this->existsField($name)) {
throw new ParserException("Field '{$name}' not found", $this->currentRow);
}

View file

@ -24,10 +24,10 @@ class BoolParser implements TypeParserInterface {
/**
* @param string $data
* @return bool
* @return bool|null
* @throws ParserException
*/
public function parse(string $data): bool {
public function parse(string $data): ?bool {
$return = filter_var($data, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
if(is_null($return) && $this->is_strict) throw new ParserException("Cannot parse '{$data}' as bool.");
return $return;

View file

@ -24,10 +24,10 @@ class FloatParser implements TypeParserInterface {
/**
* @param string $data
* @return float
* @return float|null
* @throws ParserException
*/
public function parse(string $data): float {
public function parse(string $data): ?float {
$return = filter_var($data, FILTER_VALIDATE_FLOAT, FILTER_NULL_ON_FAILURE);
if(is_null($return) && $this->is_strict) throw new ParserException("Cannot parse '{$data}' as float.");
return $return;

View file

@ -24,10 +24,10 @@ class IntParser implements TypeParserInterface {
/**
* @param string $data
* @return int
* @return int|null
* @throws ParserException
*/
public function parse(string $data): int {
public function parse(string $data): ?int {
$return = filter_var($data, FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE);
if(is_null($return) && $this->is_strict) throw new ParserException("Cannot parse '{$data}' as int.");
return $return;