for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Palmtree\Csv\Normalizer;
/**
* StringNormalizer formats a CSV cell as a string.
* It will trim the string by default.
*/
class StringNormalizer extends AbstractNormalizer
{
private bool $trim = true;
private array $trimChars = [' ', "\t", "\n", "\r", "\0", "\x0B"];
* Sets whether the string should be trimmed. Defaults to true.
public function trim(bool $trim): self
$this->trim = $trim;
return $this;
}
* Sets the character mask passed to trim(). Defaults to the mask used by trim itself.
public function trimChars(array $trimChars): self
$this->trimChars = $trimChars;
public function addTrimChar(string $char): self
$this->trimChars[] = $char;
protected function getNormalizedValue(string $value): string
if ($this->trim) {
$value = trim($value, implode('', $this->trimChars));
return $value;