php-array-table icon indicating copy to clipboard operation
php-array-table copied to clipboard

formatter order matters

Open 8ctopus opened this issue 2 years ago • 0 comments

I really like the way you implemented formatters, thank you.

Small issue:

use dekor\ArrayToTextTable;
use dekor\formatters\AlignFormatter;
use dekor\formatters\SprintfFormatter;

require __DIR__ . '/vendor/autoload.php';

$data = [
    ['test' => 1],
    ['test' => 10.1],
];

$builder = new ArrayToTextTable($data);
$builder->applyFormatter(new SprintfFormatter(['test' => '%.2f']));
$builder->applyFormatter(new AlignFormatter(['test' => 'right']));

echo $builder->render() . PHP_EOL;
+------+
| test |
+------+
|    1 |
| 10.1 |
+------+

Now invert formatter one and two and you get a different result.

$builder->applyFormatter(new AlignFormatter(['test' => 'right']));
$builder->applyFormatter(new SprintfFormatter(['test' => '%.2f']));
+-------+
| test  |
+-------+
|  1.00 |
| 10.10 |
+-------+

8ctopus avatar Mar 21 '23 12:03 8ctopus