Ejemplo n.º 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);
 }
Ejemplo n.º 2
0
 public function testFromArrayWithNonStringKeys()
 {
     $this->assertSame('Non-string value in array found', InvalidValue::fromArrayWithNonStringValues([])->getMessage());
 }