*/ class StringMapper implements Mapper { /** * Constructor * * @param string $fieldName The name of the field to be retrieved as a string */ public function __construct(public string $fieldName) { } /** * @inheritDoc */ public function map(array $result): ?string { return match (false) { key_exists($this->fieldName, $result) => null, is_string($result[$this->fieldName]) => "{$result[$this->fieldName]}", default => $result[$this->fieldName] }; } }