Convert pg types to php types

@param array $row

@return array
971873
private function convertColumns(array $row)
    {
        $result = [];

        foreach ($row as $fieldName => $value) {
            if (is_null($value)) {
                $result[$fieldName] = null;
                continue;
            }
            switch($this->columnTypes[$fieldName]) {
                case self::BOOL:
                    $value = is_null($value) ? null : $value == 't';
                    break;
                case self::INTEGER:
                case self::SMALLINT:
                case self::BIGINT:
                    $value = (int) $value;
                    break;
                case self::NUMERIC:
                    $value = (float) $value;
                    break;
                case self::JSON:
                    $value = json_decode($value, true);
                    break;
                case self::HSTORE:
                    $value = self::fromHStore($value);
                    break;
                case self::DATE:
                case self::TIMESTAMP:
                case self::TIMESTAMPTZ:
                    $value = self::fromTimestamp($value);
                    break;
                case self::SMALLINT_ARRAY:
                case self::INTEGER_ARRAY:
                    $value = self::fromArray($value);
                    if (!is_null($value)) {
                        $value = array_map(function($a) {
                            return $a === 'NULL' ? null : intval($a);
                        }, $value);
                    }
                    break;
                case self::BIGINT_ARRAY:
                case self::NUMERIC_ARRAY:
                    $value = self::fromArray($value);
                    if (!is_null($value)) {
                        $value = array_map(function($a) {
                            return $a === 'NULL' ? null : doubleval($a);
                        }, $value);
                    }
                    break;
                case self::TEXT_ARRAY:
                case self::VARCHAR_ARRAY:
                case self::CHAR_ARRAY:
                    $value = self::fromArray($value);
                    break;
                case self::HSTORE_ARRAY:
                    $array = self::fromArray($value);
                    $value = [];
                    foreach ($array as $val) {
                        $value[] = self::fromHStore($val);
                    }
                    break;
                case self::JSON_ARRAY:
                    $array = self::fromArray($value);
                    $value = [];
                    foreach ($array as $val) {
                        $value[] = json_decode($val, true);
                    }
                    break;
                case self::INTERVAL:
                    $value = self::fromInterval($value);
                    break;
            }

            $result[$fieldName] = $value;
        }
        return $result;
    }
495070
public function getValue(array $row, array $rows = [])
    {
        if (isset($row[$this->getName()])) {
            $rawValue = $row[$this->getName()];
        } else {
            $rawValue = null;
        }
        // if a callback is set
        $callback = $this->getDisplayCallback();
        if (!is_null($callback)) {
            if (!is_callable($callback)) {
                throw new \Exception('displayCallback is not callable');
            }

            return $callback($rawValue, $row, $rows);
        } else {
            switch ($this->getDisplayFormat()) {
                case static::FORMAT_DATE:
                    $formatParams = $this->getDisplayFormatParams();
                    if (is_null($formatParams)) {
                        $formatParams = 'Y-m-d H:i:s';
                    }
                    if (!is_null($rawValue) && is_object($rawValue) && get_class($rawValue) == 'DateTime') {
                        return $rawValue->format($formatParams);
                    } else {
                        return '';
                    }
                    break;
                case static::FORMAT_TEXT:
                default:
                    if (is_array($rawValue)) {
                        return implode(',', $rawValue);
                    } else {
                        return $rawValue;
                    }
                    break;
            }
        }
    }
563138
public function map($row){
        $class = $this->modelClass;
        $model = new $class($this->db, $row, false);
        $model->setAttribute('table', $this->table)->setAttribute('pk', $this->pk);
        return $model;
    }
301649
public function encode(array $row): string
    {
        $stream = fopen('php://memory', 'r+');
        fputcsv($stream, $row, "\t");
        rewind($stream);
        $line = fgets($stream);
        fclose($stream);
        return $line;
    }
741545
public function marshal($row)
    {
        foreach ($this->_props as $key=>$prop) {
            if (isset($row[$key])) {
                $row[$key] = $prop->type->marshal($row[$key]);
            }
        }

        return $row;
    }
391537
private function formatRows(array $rows) {
        foreach ($rows as $rowIndex => $row) {
            $type = $row['type'];
            $indent = $this->indent;
            $gutter = str_repeat(' ', $this->gutter);
            $verticalSeparator = $this->verticalSeparator;

            if ($type === '@section') {
                $indent = $this->sectionIndent;
            }

            foreach ($row['cols'] as $colIndex => $col) {
                if ($colIndex === 0) {
                    $col = str_repeat(' ', $indent) . $col;
                } else {
                    $col = $gutter . $verticalSeparator . $gutter . $col;
                }

                array_set($row['cols'], $colIndex, $col);
            }

            array_set($rows, $rowIndex, $row);
        }

        return $rows;
    }
481905
protected function messageTitleFromRow(array $row)
    {
        $ret = array();

        if (!empty($row['title'])) {
            $ret[] = '"' . htmlspecialchars($row['title']) . '"';
        }

        if (!empty($row['uid'])) {
            $ret[] = '[UID #' . htmlspecialchars($row['uid']) . ']';
        }

        return implode(' ', $ret);
    }
1166387
private function mapDocument(array $row)
    {
        $message = Message::create(
            $row['subject'],
            $row['body'],
            $row['priority'],
            $row['type'],
            $row['channel'],
            $row['role'],
            $row['user'],
            \DateTime::createFromFormat('U', $row['createdAt'])
        );

        return $message;
    }
1121297
protected function getItemRowCast($row)
    {
        return array(
            (string)(int)$row[self::INTERNAL_ITEM_SKU],
            (string)(int)$row[self::INTERNAL_ITEM_NAME],
            (string)(int)$row[self::INTERNAL_ITEM_CATEGORY],
            (string)(int)$row[self::INTERNAL_ITEM_CATEGORY2],
            (string)(int)$row[self::INTERNAL_ITEM_CATEGORY3],
            (string)(int)$row[self::INTERNAL_ITEM_CATEGORY4],
            (string)(int)$row[self::INTERNAL_ITEM_CATEGORY5],
            (string)$row[self::INTERNAL_ITEM_PRICE],
            (string)$row[self::INTERNAL_ITEM_QUANTITY],
        );
    }
1364683
private function calculateColumnWidths(array $rows) {
        $widths = [];

        foreach ($rows as $row) {
            if ($row['type'] !== '@row') {
                continue;
            }

            foreach ($row['cols'] as $colIndex => $col) {
                $currentWidth = array_get($widths, $colIndex, 0);
                $col = $this->output->format($col, OutputFormat::PLAIN);
                $width = strlen($col);

                if ($width > $currentWidth) {
                    $widths[$colIndex] = $width;
                }
            }
        }

        return $widths;
    }
165871
public function format($row)
    {
        $data = $this->getArray($row);
        $data = $this->process($data);

        return json_encode($data, $this->encodeOptions);
    }
152590
public function getColumnValue(Row $row)
	{
		$value = parent::getColumnValue($row);

		if (!is_numeric($value)) {
			return $value;
		}

		return number_format(
			(float) $value,
			(int) $this->number_format[0],
			(string) $this->number_format[1],
			(string) $this->number_format[2]
		);
	}
759877
public function castRow($row)
    {
        $outRow = [];
        $validationErrors = [];
        foreach ($this->fields() as $fieldName => $field) {
            $value = array_key_exists($fieldName, $row) ? $row[$fieldName] : null;
            if (in_array($value, $this->missingValues())) {
                $value = null;
            }
            try {
                $outRow[$fieldName] = $field->castValue($value);
            } catch (Exceptions\FieldValidationException $e) {
                $validationErrors = array_merge($validationErrors, $e->validationErrors);
            }
        }
        if (count($validationErrors) > 0) {
            throw new Exceptions\FieldValidationException($validationErrors);
        }

        return $outRow;
    }
878917
public function format($row)
    {
        $data = $this->getArray($row);
        $prefix = $this->getHeaderPrefix($data);
        $data = $this->process($data);

        foreach ($data as &$element) {
            if (is_null($element)) {
                $element = $this->csvFormat->getNullValue();
            } else {
                $element = $this->csvFormat->getQuote() . $this->escape($element) . $this->csvFormat->getQuote();
            }
        }

        return $prefix . $this->encode(implode($this->csvFormat->getDelimiter(), $data));
    }
409822
public function generate(array $rows): array
    {
        $generatedRows = [];
        foreach ($rows as $identifier => $row) {
            $generatedRows = $this->generateRowsIfNeeded($identifier, $row, $generatedRows);
        }
        return $generatedRows;
    }
218161
protected function getArray($row)
    {
        if (!$row instanceof Traversable && !is_array($row)) {
            throw new InvalidArgumentException("The input is not an array or traversable");
        }
        return ($row instanceof Traversable) ? iterator_to_array($row, true) : $row;
    }
962714
public function parseResults($rows)
    {
        $results = array();

        //convert the resulting set into arrays
        foreach ($rows as $item) {
            //iterate over the included and related columns
            $arr = array();

            $this->parseOnTableColumns($item, $arr);

            //then grab the computed, unsortable columns
            $this->parseComputedColumns($item, $arr);

            $results[] = $arr;
        }

        return $results;
    }