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

Breadcrumb

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

class Count

Same name in this branch
  1. 11.1.x vendor/phpunit/phpunit/src/Framework/Constraint/Cardinality/Count.php \PHPUnit\Framework\Constraint\Count

Validates a collection's element count.

@author Bernhard Schussek <bschussek@gmail.com>

Hierarchy

  • class \Symfony\Component\Validator\Constraint
    • class \Symfony\Component\Validator\Constraints\Count extends \Symfony\Component\Validator\Constraint

Expanded class hierarchy of Count

2 files declare their use of Count
CountConstraint.php in core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/CountConstraint.php
Recipe.php in core/lib/Drupal/Core/Recipe/Recipe.php
24 string references to 'Count'
AssertSameWithCountRule::processNode in vendor/phpstan/phpstan-phpunit/src/Rules/PHPUnit/AssertSameWithCountRule.php
AssertTypeSpecifyingExtensionHelper::getExpressionResolvers in vendor/phpstan/phpstan-phpunit/src/Type/PHPUnit/Assert/AssertTypeSpecifyingExtensionHelper.php
*
BumpCommand::doBump in vendor/composer/composer/src/Composer/Command/BumpCommand.php
Clover::process in vendor/phpunit/php-code-coverage/src/Report/Clover.php
CommentStorage::getDisplayOrdinal in core/modules/comment/src/CommentStorage.php
Gets the display ordinal or page number for a comment.

... See full list

File

vendor/symfony/validator/Constraints/Count.php, line 22

Namespace

Symfony\Component\Validator\Constraints
View source
class Count extends Constraint {
    public const TOO_FEW_ERROR = 'bef8e338-6ae5-4caf-b8e2-50e7b0579e69';
    public const TOO_MANY_ERROR = '756b1212-697c-468d-a9ad-50dd783bb169';
    public const NOT_EQUAL_COUNT_ERROR = '9fe5d43f-3784-4ece-a0e1-473fc02dadbc';
    public const NOT_DIVISIBLE_BY_ERROR = DivisibleBy::NOT_DIVISIBLE_BY;
    protected const ERROR_NAMES = [
        self::TOO_FEW_ERROR => 'TOO_FEW_ERROR',
        self::TOO_MANY_ERROR => 'TOO_MANY_ERROR',
        self::NOT_EQUAL_COUNT_ERROR => 'NOT_EQUAL_COUNT_ERROR',
        self::NOT_DIVISIBLE_BY_ERROR => 'NOT_DIVISIBLE_BY_ERROR',
    ];
    public string $minMessage = 'This collection should contain {{ limit }} element or more.|This collection should contain {{ limit }} elements or more.';
    public string $maxMessage = 'This collection should contain {{ limit }} element or less.|This collection should contain {{ limit }} elements or less.';
    public string $exactMessage = 'This collection should contain exactly {{ limit }} element.|This collection should contain exactly {{ limit }} elements.';
    public string $divisibleByMessage = 'The number of elements in this collection should be a multiple of {{ compared_value }}.';
    public ?int $min = null;
    public ?int $max = null;
    public ?int $divisibleBy = null;
    
    /**
     * @param int<0, max>|array<string,mixed>|null $exactly     The exact expected number of elements
     * @param int<0, max>|null                     $min         Minimum expected number of elements
     * @param positive-int|null                    $max         Maximum expected number of elements
     * @param positive-int|null                    $divisibleBy The number the collection count should be divisible by
     * @param string[]|null                        $groups
     * @param array<mixed,string>                  $options
     */
    public function __construct(int|array|null $exactly = null, ?int $min = null, ?int $max = null, ?int $divisibleBy = null, ?string $exactMessage = null, ?string $minMessage = null, ?string $maxMessage = null, ?string $divisibleByMessage = null, ?array $groups = null, mixed $payload = null, array $options = []) {
        if (\is_array($exactly)) {
            $options = array_merge($exactly, $options);
            $exactly = $options['value'] ?? null;
        }
        $min ??= $options['min'] ?? null;
        $max ??= $options['max'] ?? null;
        unset($options['value'], $options['min'], $options['max']);
        if (null !== $exactly && null === $min && null === $max) {
            $min = $max = $exactly;
        }
        parent::__construct($options, $groups, $payload);
        $this->min = $min;
        $this->max = $max;
        $this->divisibleBy = $divisibleBy ?? $this->divisibleBy;
        $this->exactMessage = $exactMessage ?? $this->exactMessage;
        $this->minMessage = $minMessage ?? $this->minMessage;
        $this->maxMessage = $maxMessage ?? $this->maxMessage;
        $this->divisibleByMessage = $divisibleByMessage ?? $this->divisibleByMessage;
        if (null === $this->min && null === $this->max && null === $this->divisibleBy) {
            throw new MissingOptionsException(\sprintf('Either option "min", "max" or "divisibleBy" must be given for constraint "%s".', __CLASS__), [
                'min',
                'max',
                'divisibleBy',
            ]);
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
Constraint::$groups public property The groups that the constraint belongs to.
Constraint::$payload public property Domain-specific data attached to a constraint.
Constraint::addImplicitGroupName public function Adds the given group if this constraint is in the Default group. 2
Constraint::CLASS_CONSTRAINT public constant Marks a constraint that can be put onto classes.
Constraint::DEFAULT_GROUP public constant The name of the group given to all constraints with no explicit group.
Constraint::getDefaultOption public function Returns the name of the default option. 28
Constraint::getErrorName public static function Returns the name of the given error code.
Constraint::getRequiredOptions public function Returns the name of the required options. 22
Constraint::getTargets public function Returns whether the constraint can be put onto classes, properties or
both.
8
Constraint::normalizeOptions protected function
Constraint::PROPERTY_CONSTRAINT public constant Marks a constraint that can be put onto properties.
Constraint::validatedBy public function Returns the name of the class that validates this constraint. 9
Constraint::__get public function Returns the value of a lazily initialized option. 2
Constraint::__isset public function 1
Constraint::__set public function Sets the value of a lazily initialized option. 1
Constraint::__sleep public function Optimizes the serialized value to minimize storage space.
Count::$divisibleBy public property
Count::$divisibleByMessage public property
Count::$exactMessage public property
Count::$max public property
Count::$maxMessage public property
Count::$min public property
Count::$minMessage public property
Count::ERROR_NAMES protected constant Maps error codes to the names of their constants. Overrides Constraint::ERROR_NAMES
Count::NOT_DIVISIBLE_BY_ERROR public constant
Count::NOT_EQUAL_COUNT_ERROR public constant
Count::TOO_FEW_ERROR public constant
Count::TOO_MANY_ERROR public constant
Count::__construct public function Overrides Constraint::__construct 1

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal