webmozarts / assert

Assertions to validate method input/output with nice error messages.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Assert an array of values is a non-empty, non-associative list of a specific type

PHLAK opened this issue · comments

I find myself repeating the following assertions often to ensure an array of values is a non-associative list, not empty and all values are of a particular type.

Assert::isNonEmptyList($someValues);
Assert::allIsInstanceOf($someValues, SomeClass::class);

Would there be interest in adding methods to unify this use case to a single method? For example.

Assert::listIsInstanceOf($someValues, SomeClass::class);

// and

Assert::nonEmptyListIsInstanceOf($someValues, SomeClass::class);

If so, I'd gladly work on a PR for this.