/** * @throws InvalidKey When a non-string key is encountered * @throws InvalidValue When a non-string value is encountered */ public static function fromFlatArray(array $flatArray) : self { $originalCount = count($flatArray); if ($originalCount > count(array_filter($flatArray, 'is_string', ARRAY_FILTER_USE_KEY))) { throw InvalidKey::fromArrayWithNonStringKeys($flatArray); } if ($originalCount > count(array_filter($flatArray, 'is_string'))) { throw InvalidValue::fromArrayWithNonStringValues($flatArray); } return new self($flatArray); }
public function testFromArrayWithNonStringKeys() { $this->assertSame('Non-string value in array found', InvalidValue::fromArrayWithNonStringValues([])->getMessage()); }