# metricool/2.1.1/app/Support/Validation/Rules/MatchesRule.php

Metricool – Social media and site statistics, version 2.1.1. 29 lines.

- Page: https://pluginprobe.com/plugins/metricool/2.1.1/code/app/Support/Validation/Rules/MatchesRule.php
- Raw: https://pluginprobe.com/plugins/metricool/2.1.1/raw/app/Support/Validation/Rules/MatchesRule.php
- Modified: 2026-08-20T14:08:30+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/metricool/2.1.1/code/app/Support/Validation/Rules/MatchesRule.php#L10-L20`.

```php
<?php

declare(strict_types=1);

namespace Metricool\Support\Validation\Rules;

class MatchesRule extends AbstractRule
{
    /**
     * Checks if the field matches the value of another field, e.g.
     * "passwordConfirmation" => "matches:password". When no field is given it
     * falls back to "{field}_confirmation".
     * @inheritDoc
     */
    public function validate(string $field, $value, array $data): void
    {
        $otherField = $this->parameters[0] ?? $field . '_confirmation';

        if (!array_key_exists($otherField, $data) || $data[$otherField] !== $value) {
            $this->fail(sprintf(
                /* translators: %1$s and %2$s are field names */
                __('%1$s must match %2$s.', 'metricool'),
                $field,
                $otherField
            ));
        }
    }
}

```
