Example #1
0
 /**
  * @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);
 }
Example #2
0
 public function testFromArrayWithNonStringKeys()
 {
     $this->assertSame('Non-string key in array found', InvalidKey::fromArrayWithNonStringKeys([])->getMessage());
 }