Firstly, we can consider the following code snippet in IOTA\Util\ValidatorUtil class:
public static function isArrayOf(array $items, string $type): bool
{
foreach ($items as $item) {
if (false === ($item instanceof $type)) {
return false;
}
}
return true;
}
According to the old iota.lib.js, the related isArrayOf method has four methods. The methods are as follows:
isArrayOfAttachedTrytes
isArrayOfHashes
isArrayOfTrytes
isArrayOfTxObjects
I think it should be divided into different methods because the isArrayOf is not good enough to handle different arrays. It's not proper to use the instanceof approach to validate other non-class types.
Another approach is: enhancing the isArrayOf and let this method can support validating the different methods.
Firstly, we can consider the following code snippet in
IOTA\Util\ValidatorUtilclass:According to the old
iota.lib.js, the relatedisArrayOfmethod has four methods. The methods are as follows:isArrayOfAttachedTrytesisArrayOfHashesisArrayOfTrytesisArrayOfTxObjectsI think it should be divided into different methods because the
isArrayOfis not good enough to handle different arrays. It's not proper to use theinstanceofapproach to validate other non-class types.Another approach is: enhancing the
isArrayOfand let this method can support validating the different methods.