Completed
Push — master ( 0c0ab1...4bb828 )
by Hong
02:29
created

Result::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
/**
3
 * Phossa Project
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  Library
8
 * @package   Phossa2\Db
9
 * @copyright Copyright (c) 2016 phossa.com
10
 * @license   http://mit-license.org/ MIT License
11
 * @link      http://www.phossa.com/
12
 */
13
/*# declare(strict_types=1); */
14
15
namespace Phossa2\Db\Driver\Pdo;
16
17
use Phossa2\Db\Driver\ResultAbstract;
18
19
/**
20
 * Result
21
 *
22
 * @package Phossa2\Db
23
 * @author  Hong Zhang <[email protected]>
24
 * @see     ResultAbstract
25
 * @version 2.0.0
26
 * @since   2.0.0 added
27
 */
28
class Result extends ResultAbstract
29
{
30
    /**
31
     * @var    \PDOStatement
32
     * @access protected
33
     */
34
    protected $statement;
35
36
    /**
37
     * Invoke to set statement
38
     *
39
     * @param  \PDOStatement $statement
40
     * @return $this
41
     * @access public
42
     */
43
    public function __invoke(\PDOStatement $statement)
44
    {
45
        $this->statement = $statement;
46
        return $this;
47
    }
48
49
    /**
50
     * {@inheritDoc}
51
     */
52
    public function fieldCount()/*# : int */
53
    {
54
        return $this->statement->columnCount();
55
    }
56
57
    /**
58
     * {@inheritDoc}
59
     */
60
    public function rowCount()/*# : int */
61
    {
62
        if ($this->statement) {
63
            return $this->statement->rowCount();
64
        }
65
        return 0;
66
    }
67
68
    /**
69
     * {@inheritDoc}
70
     */
71
    public function affectedRows()/*# : int */
72
    {
73
        return $this->statement->rowCount();
74
    }
75
76
    /**
77
     * {@inheritDoc}
78
     */
79
    protected function realFetchAll()/*# : array */
80
    {
81
        return $this->statement->fetchAll(\PDO::FETCH_ASSOC);
82
    }
83
84
    /**
85
     * {@inheritDoc}
86
     */
87
    protected function realFetchRow($rowCount)/*# : array */
88
    {
89
        $result = [];
90
        $count  = 0;
91
        while ($count++ < $rowCount) {
92
            $row = $this->statement->fetch(\PDO::FETCH_ASSOC);
93
            if (false === $row) {
94
                break;
95
            }
96
            $result[] = $row;
97
        }
98
        return $result;
99
    }
100
}
101