Iterates over the collection to remove an entity if found

@param EntityInterface|null $entity
@return EntityInterface
558707
protected function findAndRemove(EntityInterface $entity = null)
    {
        if (null == $entity) {
            return $entity;
        }

        /** @var EntityInterface $existent */
        foreach ($this->data as $key => $existent) {
            if ($existent->getId() == $entity->getId()) {
                parent::remove($key);
                $this->getEmitter()
                    ->emit(
                        new EntityRemoved(
                            $entity,
                            ['collection' => $this]
                        )
                    );
                break;
            }
        }
        
        return $entity;
    }
1289693
public function delete($entity)
    {
        if (!$this->isRepositoryDeletable()) {
            throw $this->createNotDeletableException();
        }

        return $this->trigger(__FUNCTION__, [
            'entity' => $entity,
        ]);
    }
969369
public function destroy(Entity $entity)
    {
        if ($entity->isExists()) {

            // enable logical delete ?
            if ($entity->hasAttribute('active')) {
                $attributes = [];
                $attributes['active'] = 0;
                if ($entity->hasAttribute('deleted_at')) $attributes['deleted_at'] = time();
                $this->update($attributes, $entity->getPrimaryValue());
            } else {
                $this->delete($entity->getPrimaryValue());
            }
        }
    }
1244964
public function remove(object $entity): self
    {
        $identity = $this->extractIdentity($entity);

        try {
            $state = $this->container->stateFor($identity);

            switch ($state) {
                case State::new():
                    $this->container->push(
                        $identity,
                        $entity,
                        State::removed()
                    );
                    break;

                case State::managed():
                    $this->container->push(
                        $identity,
                        $entity,
                        State::toBeRemoved()
                    );
                    break;
            }
        } catch (IdentityNotManaged $e) {
            //pass
        }

        return $this;
    }
306712
protected function removeEntity(EntityInterface $entity)
    {
        Orm::getRepository($this->getEntityClassName())
            ->getIdentityMap()
            ->remove($entity);
    }
791874
public function delete($entity)
    {
        $identifier   = $this->getIdentifier($entity);
        $affectedRows = $this->connection->delete($this->tableName, $identifier);

        if ($affectedRows == 0) {
            throw new OrmException("Entity not found.");
        }
    }
1315474
public function remove(AbstractEntity $entity)
    {
        for ($i = count($this->registries) - 1; $i >= 0; $i--) {
            /** @var RegistryInterface $registry */
            $registry = $this->registries[ $i ];
            $registry->remove($entity->getId());
        }
    }
202655
public function remove(EntityRemoved $event)
    {
        $entity = $event->getEntity();
        $collection = $event->getCollection();
        $this->deleteRelation($entity, $collection);
    }
594135
public function validate(EntityInterface $entity)
    {
        if (!$entity instanceof Application) {
            throw new Exception(
                sprintf('The Entity to validate must be an instance of %s', Application::class)
            );
        }

        $this->validateName($entity->getName());
        $this->validateUrl($entity->getUrl());
        $this->validateStatus($entity->getStatus());
        $this->validateLogoUrl($entity->getLogoUrl());
        $this->validateAllowProfileAssociation($entity->getAllowProfileAssociation());
        $errors = $this->getErrors();

        return empty($errors);
    }
1047850
public function removeEntity($entity)
    {
        $registries = $this->findRegistriesEntityById(get_class($entity), $entity->getObjectIdentifier());

        foreach ($registries as $registry) {
            $this->remove($registry);
        }
    }
803647
public function forceDelete(Entity $entity = null, Repository $repository = null)
    {
        $entity = $this->getEntityIfEmpty($entity);
        $repository = $entity->getRepositoryIfEmpty($repository);

        $this->trigger(['saving', 'deleting']);

        $delete = $repository->delete($this, $entity);

        $this->trigger(['deleted', 'saved']);

        return $delete;
    }
232292
public function delete(Entity $entity)
    {
        $this->delete = new Delete('history');
        $this->delete->where(array(
             'history.history_id = ?' => $entity->getHistoryId()
        ));
                 
        return $this->deleteRow();
    }
875259
public function removeEntity(Entity $entity)
    {
        foreach ($this->entities as $key => $entityElement) {
            if ($entityElement === $entity) {
                unset($this->entities[$key]);
                break;
            }
        }

        return $this;
    }
1163775
public function remove($entity)
    {
        $key = get_class($entity).'::'.$entity->getId();
        $this->getCache()->erase($key);
        return $this;
    }
1359596
public function remove($entity)
    {
        $objectManager = $this->getObjectManager();
        $objectManager->remove($entity);
        $objectManager->flush();
    }
861360
public function removeAllImageVersions(EntityInterface $entity, array $options = []) {
		return $this->removeImageVersions(
			$entity,
			$this->getAllVersionsKeysForModel($entity->model),
			$options
		);
	}
1101175
public function free(EntityNodeInterface $entity)
	{
		$this->repository->free($entity);
		$this->repository = null;
	}