Result::rowCount()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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
        return $this->statement->rowCount();
63
    }
64
65
    /**
66
     * {@inheritDoc}
67
     */
68
    public function affectedRows()/*# : int */
69
    {
70
        return $this->rowCount();
71
    }
72
73
    /**
74
     * {@inheritDoc}
75
     */
76
    public function close()
77
    {
78
        if ($this->statement) {
79
            $this->statement->closeCursor();
80
        }
81
    }
82
83
    /**
84
     * {@inheritDoc}
85
     */
86
    protected function realFetchAll()/*# : array */
87
    {
88
        return $this->statement->fetchAll(\PDO::FETCH_ASSOC);
89
    }
90
91
    /**
92
     * {@inheritDoc}
93
     */
94
    protected function realFetchRow($rowCount)/*# : array */
95
    {
96
        $result = [];
97
        $count  = 0;
98
        while ($count++ < $rowCount) {
99
            $row = $this->statement->fetch(\PDO::FETCH_ASSOC);
100
            if (false === $row) {
101
                break;
102
            }
103
            $result[] = $row;
104
        }
105
        return $result;
106
    }
107
}
108