/** * Sets a collection of constants * * @param array|PhpConstant[] $constants * @return $this */ public function setConstants(array $constants) { $normalizedConstants = []; foreach ($constants as $name => $value) { if ($value instanceof PhpConstant) { $name = $value->getName(); } else { $constValue = $value; $value = new PhpConstant($name); $value->setValue($constValue); } $normalizedConstants[$name] = $value; } $this->constants->setAll($normalizedConstants); return $this; }
public function testAddGetRemove() { $key1 = 'key1'; $key2 = 'key2'; $key3 = 'key3'; $item1 = 'item 1'; $item2 = 'item 2'; $item3 = 'item 3'; $items = [$key1 => $item1, $key2 => $item2]; $keys = new Set([$key1, $key2]); $values = new ArrayList([$item1, $item2]); $map = new Map(); $map->set($key1, $item1); $this->assertEquals(1, $map->size()); $this->assertEquals($item1, $map->get($key1)); $this->assertEquals($key1, $map->getKey($item1)); $this->assertNull($map->getKey($item2)); $this->assertTrue($map->has($key1)); $this->assertFalse($map->has($key2)); $map->remove($key1); $this->assertEquals(0, $map->size()); $map->setAll($items); $this->assertEquals(2, $map->size()); $this->assertEquals($keys, $map->keys()); $this->assertEquals($values, $map->values()); $map->set($key3, $item3); $this->assertEquals(3, $map->size()); $map->clear(); $this->assertEquals(0, $map->size()); $dupKeyItems = [$key1 => $item1, $key2 => $item2]; $map->setAll($dupKeyItems); $map->set($key2, $item3); $this->assertEquals(2, $map->size()); $this->assertEquals($item3, $map->get($key2)); $this->assertEmpty($map->get('non_existing_key')); $this->assertEmpty($map->remove('non_existing_key')); $this->assertEquals([], $map->get('non_existing_key', [])); }
/** * @return Skill[] */ public function getDescendents() { $descendents = new Map(); $add = function (Skill $skill) use($descendents) { if ($skill->isMultiple() || $skill->isTransition()) { return; } $descendents->set($skill->getId(), $skill); $descendents->setAll($skill->getDescendents()); }; foreach ($this->getVariations() as $variation) { $add($variation); } foreach ($this->getChildren() as $child) { $add($child); } return $descendents->toArray(); }