Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
28 / 28
Result
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
9 / 9
17
100.00% covered (success)
100.00%
28 / 28
 asArray
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
5 / 5
 get
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
3 / 3
 getField
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
8 / 8
 getFields
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
8 / 8
 getItemField
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
4 / 4
 current
100.00% covered (success)
100.00%
1 / 1
1  
 
 next
100.00% covered (success)
100.00%
1 / 1
1  
 
 valid
100.00% covered (success)
100.00%
1 / 1
1  
 
 rewind
100.00% covered (success)
100.00%
1 / 1
1  
 
<?php
namespace PHPixie\Database;
abstract class Result implements \Iterator
{
    public function asArray()
    {
        $this->rewind();
        $array = array();
        foreach ($this as $item)
            $array[] = $item;
        return $array;
    }
    public function get($field)
    {
        if (!$this->valid())
            return null;
        return $this->getItemField($this->current(), $field);
    }
    public function getField($field, $skipNulls = false)
    {
        $this->rewind();
        $values = array();
        foreach ($this as $item) {
            $value = $this->getItemField($item, $field);
            if ($value !== null || !$skipNulls)
                $values[] = $value;
        }
        return $values;
    }
    public function getFields($fields)
    {
        $data = array();
        foreach($this as $item){
            $values = array();
            foreach($fields as $field)
                $values[$field] = $this->getItemField($item, $field);
            $data[]=$values;
        }
        
        return $data;
    }
    
    public function getItemField($item, $field)
    {
        $current = $item;
        if(!property_exists($current, $field))
            return null;
        return $current->$field;
    }
    abstract public function current();
    abstract public function next();
    abstract public function valid();
    abstract public function rewind();
}