Completed
Push — master ( 40aac0...525ff6 )
by Rougin
02:26
created

ResultTrait::getQueryResult()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Rougin\Wildfire\Traits;
4
5
/**
6
 * Result Trait
7
 * 
8
 * @package Wildfire
9
 * @author  Rougin Royce Gutib <[email protected]>
10
 *
11
 * @property \CI_DB_null $query
12
 */
13
trait ResultTrait
14
{
15
    /**
16
     * @var string
17
     */
18
    protected $table = '';
19
20
    /**
21
     * Creates an object from the specified table and row.
22
     *
23
     * @param  string $table
24
     * @param  object $row
25
     * @return array
26
     */
27
    abstract protected function createObject($table, $row);
28
29
    /**
30
     * Returns all rows from the specified table.
31
     * 
32
     * @param  string $table
33
     * @return self
34
     */
35
    abstract public function get($table = '');
36
37
    /**
38
     * Returns the result.
39
     * 
40
     * @return object
41
     */
42 12
    public function result()
43
    {
44 12
        $query = $this->query;
45 12
        $result = [];
46
47 12
        if (method_exists($this->query, 'result')) {
48 12
            $query = $this->query->result();
49 12
        }
50
51 12
        if (empty($this->table)) {
52 6
            $this->get();
53 6
        }
54
55 12
        foreach ($query as $row) {
56 12
            array_push($result, $this->createObject($this->table, $row));
57 12
        }
58
59 12
        return $result;
60
    }
61
}
62