/**
  * @param AbstractQuery $query
  *
  * @throws \LogicException
  * @return int
  *
  */
 public function cleanByQuery(AbstractQuery $query)
 {
     $numCleaned = 0;
     /** @var SourceInterface $source */
     foreach ($query->iterate() as list($source)) {
         if (!$source instanceof SourceInterface) {
             throw new \LogicException(sprintf('Invalid iterator given, encountered %s instead of SourceInterface', is_object($source) ? get_class($source) : gettype($source)));
         }
         $this->eventDispatcher->dispatch(IoEvents::PRE_CLEAN_SOURCE, new SourceEvent($source));
         $this->sourceManager->remove($source);
         $this->eventDispatcher->dispatch(IoEvents::POST_CLEAN_SOURCE, new SourceEvent($source));
         ++$numCleaned;
         if ($numCleaned % 50 === 0) {
             $this->sourceManager->flush();
             $this->sourceManager->clear();
         }
     }
     if ($numCleaned > 0) {
         $this->sourceManager->flush();
         $this->sourceManager->clear();
     }
     return $numCleaned;
 }
 /**
  * @param SourceInterface $source
  */
 protected function removeSource(SourceInterface $source)
 {
     $this->sourceManager->remove($source);
     $this->sourceManager->flush($source);
 }
 /**
  * @inheritdoc
  */
 public function remove(SourceInterface $source)
 {
     $this->sourceManager->remove($source);
 }