HEX
Server: Apache
System: Linux srv13.cpanelhost.cl 3.10.0-962.3.2.lve1.5.38.el7.x86_64 #1 SMP Thu Jun 18 05:28:41 EDT 2020 x86_64
User: cca63905 (4205)
PHP: 7.3.20
Disabled: NONE
Upload Files
File: /home4/cca63905/www/nueva/vendor/prestashop/circuit-breaker/src/Util/ErrorFormatter.php
<?php

namespace PrestaShop\CircuitBreaker\Util;

/**
 * Helper to provide complete and easy to read
 * error messages.
 * Mostly used to build Exception messages.
 */
final class ErrorFormatter
{
    /**
     * Format error message.
     *
     * @param string $parameter the parameter to evaluate
     * @param mixed $value the value to format
     * @param string $function the validation function
     * @param string $expectedType the expected type
     *
     * @return string
     */
    public static function format($parameter, $value, $function, $expectedType)
    {
        $errorMessage = '';
        $isValid = Assert::$function($value);
        $type = gettype($value);
        $hasStringValue = in_array($type, ['integer', 'float', 'string'], true);

        if (!$isValid) {
            $errorMessage = sprintf(
                'Excepted %s to be %s, got %s',
                $parameter,
                $expectedType,
                $type
            );

            if ($hasStringValue) {
                $errorMessage .= sprintf(' (%s)', (string) $value);
            }

            $errorMessage .= PHP_EOL;
        }

        return $errorMessage;
    }
}