Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isArrayOf should be divided into different isArrayOf methods #64

Open
peter279k opened this issue Aug 25, 2018 · 1 comment
Open

isArrayOf should be divided into different isArrayOf methods #64

peter279k opened this issue Aug 25, 2018 · 1 comment
Assignees

Comments

@peter279k
Copy link
Contributor

peter279k commented Aug 25, 2018

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.

@Techworker
Copy link
Member

You can keep the one we have now and add the others if applicable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants