Remove invalid tokens from collection

@return $this
487179
protected function cleanCollection() : self {
      foreach ($this as $index => $token) {
        if ($token->isValid()) {
          continue;
        }
        unset($this->items[$index]);
      }

      return $this;
    }
538440
private function protect()
    {
        if (!in_array($this->type, self::allAsString(), true)) {
            throw new \InvalidArgumentException(sprintf('Invalid token type "%s"', $this->type));
        }
    }
1367179
private function cleanupGroupDelimiters(array &$tokens)
    {
        $indexes = $this->getUnmatchedGroupDelimiterIndexes($tokens);

        while (!empty($indexes)) {
            $lastIndex = array_pop($indexes);
            $token = $tokens[$lastIndex];
            unset($tokens[$lastIndex]);

            if ($token->type === Tokenizer::TOKEN_GROUP_BEGIN) {
                $this->addCorrection(
                    self::CORRECTION_UNMATCHED_GROUP_LEFT_DELIMITER_IGNORED,
                    $token
                );
            } else {
                $this->addCorrection(
                    self::CORRECTION_UNMATCHED_GROUP_RIGHT_DELIMITER_IGNORED,
                    $token
                );
            }
        }
    }
816507
private function pruneTokens()
    {
        $now = new \DateTime('now');
        // Delete access tokens that have no refresh token associated
        $qb = $this->entityManager->createQueryBuilder();
        $items = $qb->select('token')
            ->from(AccessToken::class, 'token')
            ->where($qb->expr()->lt('token.expiryDateTime', ':now'))
            ->getQuery()->execute([':now' => $now]);

        $this->pruneResults($items);

        // Delete all expired access tokens that have expired refresh tokens
        $qb = $this->entityManager->createQueryBuilder();
        $items = $qb->select('token')
            ->from(AccessToken::class, 'token')
            ->where($qb->expr()->lt('token.expiryDateTime', ':now'))
            ->getQuery()->execute([':now' => $now]);

        $this->pruneResults($items);

        // Delete all expired auth codes
        $qb = $this->entityManager->createQueryBuilder();
        $qb->delete(AuthCode::class, 'token')
            ->where($qb->expr()->lt('token.expiryDateTime', ':now'))
            ->getQuery()->execute([':now' => $now]);
    }
864964
public function deleteUserToken()
    {
        $this->removeExpiredTokens();

        if (empty($this->id)) {

            $msg = '%s: Can not delete auth tokens without a corresponding id. Use AuthToken::setId() to set an id before calling this method. Deletion of auth token aborted!';

            if (isset($this->logger)) {
                $this->logger->warning($msg, __METHOD__);
                return;
            }
            else {
                Throw new TokenException($msg);
            }
        }

        // Yep! Delete token and return false for failed autologin
        $this->db->qb([
            'table' => 'core_auth_tokens',
            'method' => 'DELETE',
            'filter' => 'expires < :expires OR id=:id',
            'params' => [
                ':expires' => date('Y-m-d H:i:s'),
                ':id' => $this->id
            ]
        ], true);
    }
1093243
public function clearErrors()
    {
        $this->_validationDone = false;

        if (count($this->_errors) != 0) {
            $this->_errors = array();
        }

        return $this;
    }
893980
protected function clearCachedAccessToken()
    {
        /** @var TokenStorageInterface $storage */
        $storage = $this->service->getStorage();
        $storage->clearToken($this->getServiceName());

        return $this;
    }
34354
public function deleteExpiredTokens()
    {
        $lifetime = config('autologin.lifetime');

        $expiry = Carbon::now()->subMinutes($lifetime);

        return $this->provider->deleteExpiredTokens($expiry);
    }
892230
public function unsetMinify()
    {
        $this->pug->removeKeyword('assets');
        $this->pug->removeKeyword('concat');
        $this->pug->removeKeyword('concat-to');
        $this->pug->removeKeyword('minify');
        $this->pug->removeKeyword('minify-to');
        $this->minify = null;

        return $this;
    }
1107359
def remove_invalid(self):
        
        valid = np.array([i.is_valid for i in self.entities],
                         dtype=np.bool)
        self.entities = self.entities[valid]
1326142
public function clear()
    {
        $count = $this->loadModel('Muffin/Tokenize.Tokens')->deleteAllExpiredOrUsed();
        $this->out(__n('One token deleted', '{0} tokens deleted', $count, $count));
    }
968367
public static function reset_token() {
        global $DB;
        if (!$hub = self::get_registration()) {
            return true;
        }
        $DB->delete_records('registration_hubs', array('id' => $hub->id));
        self::$registration = null;
    }
456854
public function removeRequired()
    {
        foreach ($this->getRules() as $key => $rules) {
            $newRules[$key] = preg_grep("/^required/", $rules, PREG_GREP_INVERT);
        }
        $this->rules = $newRules;
        return $this;
    }
984326
public function clearSessionTokens()
    {
        $this->session->remove(self::SESSION_TOKEN_KEY);
        $this->session->remove(self::SESSION_TOKEN_SECRET_KEY);
    }
849490
public function toLowerCase() {
    $token = $this->getConstantName()->lastToken();
    $token->setText(strtolower($token->getText()));
    return $this;
  }
476277
protected function filteredTokens()
    {
        foreach ($this->tokens as $token) {
            if ($token->reloadRequired() || $token->reloadRequiredIfError()) {
                yield $token;
            }
        }
    }
109346
public function revokeAllInvalid($datetime = null, $andFlush = true)
    {
        $invalidTokens = $this->repository->findInvalid($datetime);

        foreach ($invalidTokens as $invalidToken) {
            $this->objectManager->remove($invalidToken);
        }

        if ($andFlush) {
            $this->objectManager->flush();
        }

        return $invalidTokens;
    }