Skip to content

Commit

Permalink
[Instrument] Allow fields to have value "0" (aces#6867)
Browse files Browse the repository at this point in the history
The instrument getFieldValue function was doing a "!empty" check
to see if the field is valid. This catches values such as "0"
incorrectly and converts them to false.

This changes it to array_key_exists to properly verify that the
field is valid. At the same time, it converts the "false" error
code return for an invalid field to an exception, since callers
shouldn't be requesting the value of fields that don't exist on
an instrument, and it indicates a programming error that is more
likely to be caught this way.
  • Loading branch information
driusan authored and AlexandraLivadas committed Jun 15, 2021
1 parent 92679a4 commit cef2091
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions php/libraries/NDB_BVL_Instrument.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1427,21 +1427,19 @@ abstract class NDB_BVL_Instrument extends NDB_Page

/**
* Get a the value of $field from the instrument table.
* Used specifically by electronic instruments to check if file
* is already uploaded.
*
* @param string $field The field to get from this instrument
*
* @return string|false The value of the field, or false if it's empty.
* @return string The value of the field, or false if it's empty.
*/
function getFieldValue(string $field)
{
$allValues = self::loadInstanceData($this);

if (!empty($allValues[$field])) {
return $allValues[$field];
if (!array_key_exists($field, $allValues)) {
throw new \OutOfBoundsException("Invalid field for instrument");
}
return false;
return $allValues[$field];
}


Expand Down

0 comments on commit cef2091

Please sign in to comment.