Test Failed
Branch v5 (12d602)
by Alexey
04:51
created

Result   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
dl 0
loc 43
rs 10
c 2
b 1
f 1
ccs 0
cts 21
cp 0
wmc 9
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getArray() 0 16 4
A getObjects() 0 13 3
1
<?php
2
3
/**
4
 * Result class for mysql driver
5
 *
6
 * @author Alexey Krupskiy <[email protected]>
7
 * @link http://inji.ru/
8
 * @copyright 2015 Alexey Krupskiy
9
 * @license https://github.com/injitools/cms-Inji/blob/master/LICENSE
10
 */
11
12
namespace Inji\Db\Mysql;
13
14
use Inji\Db\DriverResult;
15
16
class Result implements DriverResult {
0 ignored issues
show
Bug introduced by
There is one abstract method fetchAll in this class; you could implement it, or declare this class as abstract.
Loading history...
17
18
    public $pdoResult = null;
19
20
    public function __construct($dbResult) {
21
        $this->pdoResult = $dbResult;
22
    }
23
24
    public function getArray($keyCol = '') {
25
        $key = \Inji\App::$cur->log->start('parse result');
26
        if (!$keyCol) {
27
            return $this->pdoResult->fetchAll(\PDO::FETCH_ASSOC);
28
        }
29
        $array = [];
30
        while ($row = $this->pdoResult->fetch(\PDO::FETCH_ASSOC)) {
31
            if (isset($row[$keyCol])) {
32
                $array[$row[$keyCol]] = $row;
33
            } else {
34
                $array[] = $row;
35
            }
36
        }
37
        \Inji\App::$cur->log->end($key);
38
        return $array;
39
    }
40
41
    public function getObjects($class, $keyCol = '') {
42
        $key = \Inji\App::$cur->log->start('parse result');
43
        $array = [];
44
        while ($object = $this->pdoResult->fetchObject($class)) {
45
            if ($keyCol) {
46
                $array[$object->$keyCol] = $object;
47
            } else {
48
                $array[] = $object;
49
            }
50
        }
51
        \Inji\App::$cur->log->end($key);
52
        return $array;
53
    }
54
55
    public function fetch($className = '') {
56
        if ($className) {
57
            return $this->pdoResult->fetchObject($className);
58
        } else {
59
            return $this->pdoResult->fetch(\PDO::FETCH_ASSOC);
60
        }
61
    }
62
}