replace a MenuEntry by another one

@param MenuEntry $new
@param MenuEntry $toReplace
@return Menu
481337
public function replaceEntry(MenuEntry $new, MenuEntry $toReplace) {

		foreach($this->entries as $k => $e) {
			if($e === $toReplace) {
				$this->insertEntry($new, $k);
				$this->removeEntry($toReplace);
				break;
			}
		}
		
		return $this;

	}
371565
public function addSeparator($push=false)
    {
        $entry = MenuEntry::separator();
        return $this->add($entry, $push);
    }
745570
public function changeParent(
        \Mirasvit\Blog\Model\Category $category,
        \Mirasvit\Blog\Model\Category $newParent,
        $afterCategoryId = null
    ) {
        $childrenCount = $this->getChildrenCount($category->getId()) + 1;
        $table = $this->getEntityTable();
        $connection = $this->getConnection();
        $levelFiled = $connection->quoteIdentifier('level');
        $pathField = $connection->quoteIdentifier('path');

        /**
         * Decrease children count for all old category parent categories
         */
        $connection->update(
            $table,
            ['children_count' => new \Zend_Db_Expr('children_count - ' . $childrenCount)],
            ['entity_id IN(?)' => $category->getParentIds()]
        );

        /**
         * Increase children count for new category parents
         */
        $connection->update(
            $table,
            ['children_count' => new \Zend_Db_Expr('children_count + ' . $childrenCount)],
            ['entity_id IN(?)' => $newParent->getPathIds()]
        );

        $position = $this->processPositions($category, $newParent, $afterCategoryId);

        $newPath = sprintf('%s/%s', $newParent->getPath(), $category->getId());
        $newLevel = $newParent->getLevel() + 1;
        $levelDisposition = $newLevel - $category->getLevel();

        /**
         * Update children nodes path
         */
        $connection->update(
            $table,
            [
                'path'  => new \Zend_Db_Expr(
                    'REPLACE(' . $pathField . ',' . $connection->quote(
                        $category->getPath() . '/'
                    ) . ', ' . $connection->quote(
                        $newPath . '/'
                    ) . ')'
                ),
                'level' => new \Zend_Db_Expr($levelFiled . ' + ' . $levelDisposition)
            ],
            [$pathField . ' LIKE ?' => $category->getPath() . '/%']
        );

        /**
         * Update moved category data
         */
        $data = [
            'path'      => $newPath,
            'level'     => $newLevel,
            'position'  => $position,
            'parent_id' => $newParent->getId(),
        ];
        $connection->update($table, $data, ['entity_id = ?' => $category->getId()]);

        // Update category object to new data
        $category->addData($data);
        $category->unsetData('path_ids');

        return $this;
    }
529642
public function replaceInFile($old, $new, $append = 0)
    {
        $contents = $this->previous;
        $replaceWith = preg_replace("~$old\n?~", "$new\n", $contents);

        file_put_contents($this->getPath(), $replaceWith, $append);

        return $this;
    }
954503
public function addMenu(array $menu, string $namespace = null, int $position = null): void
	{
		foreach ($menu as $name => $row) {
			if (!isset($row['link'])) {
				throw new InvalidArgumentException('First level of Menu must have set link');
			} else {
				$link = new Link($name, $row['link'], isset($row['arguments']) ? $row['arguments'] : []);
				$link->setNamespace($namespace);
				if (!empty($row['toBlank'])) {
					$link->toBlank();
				}
				$this->addItem($link, $position);
				$this->attachLink($link);

				unset($row['link'], $row['arguments'], $row['toBlank']);
				$this->addMenuItems($link, $row);
			}
		}
	}
423162
public function replaceProjectNamespace(string $replacement, string $filePath): self
    {
        $this->findReplace(
            AbstractGenerator::FIND_PROJECT_NAMESPACE,
            $this->namespaceHelper->tidy($replacement),
            $filePath
        );

        return $this;
    }
325931
public function newInstance(
        string $createdByUserId,
        string $createdReason = Tracking::UNKNOWN_REASON
    ) {
        /** @var PluginWrapper $new */
        $new = parent::newInstance(
            $createdByUserId,
            $createdReason
        );

        // if no id, then it has not been save and can be returned
        if (empty($new->pluginWrapperId)) {
            return $new;
        }

        $new->pluginWrapperId = null;

        // @deprecated <deprecated-site-wide-plugin>
        //if (!$new->instance->isSiteWide()) {
            $pluginInstance = $new->instance->newInstance(
                $createdByUserId,
                $createdReason
            );
            $new->instance = $pluginInstance;
        //}

        return $new;
    }
1340272
public static function update($itemid, $newvalue) {
        require_capability('moodle/tag:manage', context_system::instance());
        $tag = core_tag_tag::get($itemid, '*', MUST_EXIST);
        $newvalue = (int)clean_param($newvalue, PARAM_BOOL);
        $tag->update(array('isstandard' => $newvalue));
        return new self($tag);
    }
801412
public function override($new)
    {
        $old = iterator_to_array($this->collection);
        $new = $new instanceof Traversable ? iterator_to_array($this->collection) : $new;

        if (!is_array($new)) {
            throw new Exception("Argument must be an array or instance of Traversable");
        }

        // Create restore point
        $this->overrides[] = $old;

        // Override collection with new data
        $merged = $this->merge($old, $new);
        $this->apply($merged, $purge = false);

        return $this;
    }
648402
public function replace($newNode, $clone = true)
    {
        if ($this->node->parentNode === null) {
            throw new LogicException('Can not replace element without parent node');
        }

        if ($newNode instanceof Element) {
            $newNode = $newNode->getNode();
        }

        if (!$newNode instanceof DOMNode) {
            throw new InvalidArgumentException(sprintf('Argument 1 passed to %s must be an instance of %s or DOMNode, %s given', __METHOD__, __CLASS__, (is_object($newNode) ? get_class($newNode) : gettype($newNode))));
        }

        if ($clone) {
            $newNode = $newNode->cloneNode(true);
        }

        if ($newNode->ownerDocument === null || !$this->getDocument()->is($newNode->ownerDocument)) {
            $newNode = $this->node->ownerDocument->importNode($newNode, true);
        }

        $node = $this->node->parentNode->replaceChild($newNode, $this->node);

        return new Element($node);
    }
845158
public function replace($stepNameToReplace, Step $replacingStep)
    {
        $this->assertStepExists($stepNameToReplace);

        // remove event bindings for step being replaced
        $stepToReplace = $this->steps[$stepNameToReplace];
        foreach ($stepToReplace->getTriggeringEvents() as $eventName) {
            unset($this->eventBindings[$eventName]);
        }

        // insert after the step we want to replace
        $this->insert($stepNameToReplace, $replacingStep, true);

        // remove step
        unset($this->steps[$stepNameToReplace]);

        // reindex steps array
        $temporaryStepNames = array_keys($this->steps);
        $temporarySteps = array_values($this->steps);

        $this->steps = array_combine($temporaryStepNames, $temporarySteps);
    }
770899
public function replaceHost($newUrl, $opt = self::SCHEME | self::HOST | self::PORT | self::CREDENTIALS)
	{
		if ($newUrl instanceof Url) {
			$url = $newUrl;
		} else if (is_string($newUrl)) {
			$url = new Url($newUrl);
		} else {
			throw new InvalidUrlException();
		}
		$scheme = ($opt & self::SCHEME) === self::SCHEME;
		$host = ($opt & self::HOST) === self::HOST;
		$port = ($opt & self::PORT) === self::PORT;
		$creds = ($opt & self::CREDENTIALS) === self::CREDENTIALS;
		if ($scheme) {
			$this->scheme->set($url->scheme->get());
		}
		if ($host) {
			$this->host->set($url->host->get());
		}
		if ($port) {
			$this->port->set($url->port->get());
		}
		if ($creds) {
			$this->credentials->username = $url->credentials->username;
			$this->credentials->password = $url->credentials->password;
		}
		return $this;
	}
1352255
public function placeAt(Sortable $movedNode, Sortable $newParent, $position)
    {
        // 1. movedNode.parentId = newDescendant.parentId, movedNode.position = MAX(newDescendant.position,1)
        // 2. removeFromSort(movedNode) like delete without delete
        // 2. UPDATE SET position = position+1 WHERE parentId = newAncestor.parentId
        //    AND position >= movedNode.position
        // 3. movedNode.save()

        $targetParentId = $newParent->getId();
        $targetPosition = $position;
        $oldParentId = $movedNode->getParentId();
        $oldPosition = $movedNode->getPosition();

        // Nothing to do
        if ($targetParentId == $oldParentId &&
            $targetPosition == $oldPosition &&
            $movedNode->exists) {
            return $this;
        }

        $movedNode[$this->getParentIdName()] = $targetParentId;
        $movedNode[$this->getPositionName()] = $targetPosition;

        // Remove node from old parent
        $this->decrementOrderAfter($oldParentId, $oldPosition);

        // Create space for new position
        $this->incrementOrderAfter($targetParentId, $targetPosition-1);

        $movedNode->save();

        return $this;

    }
275569
public function appendTo( $sourceNode, $newParentNode )
    {
        $mapper = $this->getMapper();

        return $mapper->moveNode( $sourceNode,
                                  $mapper::MOVE_APPEND,
                                  $newParentNode );
    }
1111408
public function replaceEntityNamespace(string $replacement, string $filePath): self
    {
        if (false === \ts\stringContains($replacement, '\\Entity')) {
            throw new \RuntimeException('$replacement ' . $replacement . ' does not contain \\Entity\\');
        }
        $this->findReplace(
            AbstractGenerator::FIND_ENTITY_NAMESPACE,
            $this->namespaceHelper->tidy($replacement),
            $filePath
        );

        return $this;
    }
961557
private function replaceCurrentVersionbyNewVersion()
    {
        $this->fs->copy($this->newInstallerFile, $this->currentInstallerFile, true);

        return $this;
    }
938251
@Override
    public MenuState<String> newMenuState(String value, boolean changed, boolean active) {
        return new StringMenuState(changed, active, value);
    }