PhpBench\Formatter\Format\TruncateFormat::format PHP Метод

format() публичный Метод

public format ( $value, array $options )
$options array
    public function format($value, array $options)
    {
        if (strlen($value) <= $options['length']) {
            return $value;
        }
        $truncateLength = $options['length'] - strlen($options['pad']);
        switch ($options['position']) {
            case 'left':
                $string = $options['pad'] . substr($value, -$truncateLength);
                break;
            case 'right':
                $string = substr($value, 0, $truncateLength) . $options['pad'];
                break;
            case 'middle':
                $offset = floor($truncateLength / 2);
                $left = substr($value, 0, $offset);
                $string = $left . $options['pad'];
                $string = $string . substr($value, -($options['length'] - strlen($string)));
                break;
            default:
                throw new \Exception(sprintf('Truncation position must be one of "%s", got "%s"', implode('", "', ['left', 'right']), $options['position']));
        }
        return $string;
    }