<?php

class LegacyLaravelDbResult
{
    protected $rows;
    protected $position = 0;

    public function __construct(array $rows)
    {
        $this->rows = array_map([$this, 'normalizeRow'], $rows);
    }

    private function normalizeRow($row): array
    {
        return array_change_key_case((array)$row, CASE_LOWER);
    }

    public function fetchRow()
    {
        if (!isset($this->rows[$this->position])) {
            return null;
        }

        return $this->rows[$this->position++];
    }

    public function numRows()
    {
        return count($this->rows);
    }

    public function free()
    {
        $this->rows = [];
        return true;
    }
}