# fluent-cart/1.6.1/app/Http/Rules/MaxLengthRule.php

FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler, version 1.6.1. 42 lines.

- Page: https://pluginprobe.com/plugins/fluent-cart/1.6.1/code/app/Http/Rules/MaxLengthRule.php
- Raw: https://pluginprobe.com/plugins/fluent-cart/1.6.1/raw/app/Http/Rules/MaxLengthRule.php
- Modified: 2025-11-20T13:11:16+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/fluent-cart/1.6.1/code/app/Http/Rules/MaxLengthRule.php#L10-L20`.

```php
<?php

namespace FluentCart\App\Http\Rules;

use FluentCart\Framework\Support\Arr;

class MaxLengthRule
{
    public function __invoke($attr, $value, $rules, $data, ...$params)
    {


        $value = trim($value);
        if (is_numeric($value)) {
            $value = (string)$value;
        }

        if(!is_string($value)) {
            return sprintf(
                /* translators: 1: attribute name */
                __('The %s must be a valid text', 'fluent-cart'),
                $attr
            );
        }

        $maxLength = Arr::get($params, '0', 254);

        if(strlen($value) > $maxLength) {
            return sprintf(
                /* translators: 1: attribute name, 2: max length */
                __('The %1$s must not be greater than %2$s characters.', 'fluent-cart'),
                $attr,
                $maxLength
            );
        }

        return null;
    }


}

```
