Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Count.php

function Count::getCountOf

Throws

Exception

3 calls to Count::getCountOf()
Count::failureDescription in vendor/phpunit/phpunit/src/Framework/Constraint/Cardinality/Count.php
Returns the description of the failure.
Count::matches in vendor/phpunit/phpunit/src/Framework/Constraint/Cardinality/Count.php
Evaluates the constraint for parameter $other. Returns true if the constraint is met, false otherwise.
SameSize::__construct in vendor/phpunit/phpunit/src/Framework/Constraint/Cardinality/SameSize.php
@psalm-param Countable|iterable $expected

File

vendor/phpunit/phpunit/src/Framework/Constraint/Cardinality/Count.php, line 58

Class

Count
@no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit

Namespace

PHPUnit\Framework\Constraint

Code

protected function getCountOf(mixed $other) : ?int {
    if (is_countable($other)) {
        return count($other);
    }
    if ($other instanceof EmptyIterator) {
        return 0;
    }
    if ($other instanceof Traversable) {
        while ($other instanceof IteratorAggregate) {
            try {
                $other = $other->getIterator();
            } catch (\Exception $e) {
                throw new Exception($e->getMessage(), $e->getCode(), $e);
            }
        }
        $iterator = $other;
        if ($iterator instanceof Generator) {
            throw new GeneratorNotSupportedException();
        }
        if (!$iterator instanceof Iterator) {
            return iterator_count($iterator);
        }
        $key = $iterator->key();
        $count = iterator_count($iterator);
        // Manually rewind $iterator to previous key, since iterator_count
        // moves pointer.
        if ($key !== null) {
            $iterator->rewind();
            while ($iterator->valid() && $key !== $iterator->key()) {
                $iterator->next();
            }
        }
        return $count;
    }
    return null;
}
RSS feed
Powered by Drupal