Validte that lookup arrays are actually arrays
This commit is contained in:
parent
4c1d953897
commit
4881e2ae9e
|
|
@ -32,9 +32,10 @@ class HLookup extends LookupBase
|
|||
}
|
||||
|
||||
$notExactMatch = (bool) ($notExactMatch ?? true);
|
||||
$lookupArray = self::convertLiteralArray($lookupArray);
|
||||
|
||||
try {
|
||||
self::validateLookupArray($lookupArray);
|
||||
$lookupArray = self::convertLiteralArray($lookupArray);
|
||||
$indexNumber = self::validateIndexLookup($lookupArray, $indexNumber);
|
||||
} catch (Exception $e) {
|
||||
return $e->getMessage();
|
||||
|
|
|
|||
|
|
@ -7,6 +7,16 @@ use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
|||
|
||||
abstract class LookupBase
|
||||
{
|
||||
/**
|
||||
* @param mixed $lookup_array
|
||||
*/
|
||||
protected static function validateLookupArray($lookup_array): void
|
||||
{
|
||||
if (!is_array($lookup_array)) {
|
||||
throw new Exception(ExcelError::REF());
|
||||
}
|
||||
}
|
||||
|
||||
protected static function validateIndexLookup(array $lookup_array, $index_number): int
|
||||
{
|
||||
// index_number must be a number greater than or equal to 1
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ class VLookup extends LookupBase
|
|||
$notExactMatch = (bool) ($notExactMatch ?? true);
|
||||
|
||||
try {
|
||||
self::validateLookupArray($lookupArray);
|
||||
$indexNumber = self::validateIndexLookup($lookupArray, $indexNumber);
|
||||
} catch (Exception $e) {
|
||||
return $e->getMessage();
|
||||
|
|
|
|||
|
|
@ -24,6 +24,13 @@ return [
|
|||
2,
|
||||
false,
|
||||
],
|
||||
[
|
||||
'#REF!',
|
||||
1,
|
||||
'HELLO WORLD',
|
||||
2,
|
||||
false,
|
||||
],
|
||||
[
|
||||
100,
|
||||
1,
|
||||
|
|
|
|||
Loading…
Reference in New Issue