Completed
Pull Request — master (#178)
by ignace nyamagana
02:30
created

Reader::getRow()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 7
Bugs 1 Features 0
Metric Value
c 7
b 1
f 0
dl 0
loc 18
ccs 0
cts 0
cp 0
rs 9.2
cc 4
eloc 11
nc 3
nop 1
crap 20
1
<?php
2
/**
3
* This file is part of the League.csv library
4
*
5
* @license http://opensource.org/licenses/MIT
6
* @link https://github.com/thephpleague/csv/
7
* @version 9.0.0
8
* @package League.csv
9
*
10
* For the full copyright and license information, please view the LICENSE
11
* file that was distributed with this source code.
12
*/
13
namespace League\Csv;
14
15
use BadMethodCallException;
16
use Countable;
17
use JsonSerializable;
18
19
/**
20
 * A class to interact with a CSV document without overriding it
21
 *
22
 * @package League.csv
23
 * @since  3.0.0
24
 *
25
 * @method array fetchAll()
26
 * @method array fetchOne(int $offset = 0)
27
 * @method array fetchColumn(string|int $column_index = 0)
28
 * @method array fetchPairs(string|int $offset_index = 0, string|int $value_index = 1)
29
 * @method string toHTML(string $class_attr = 'table-csv-data')
30
 * @method DOMDocument toXML(string $root_name = 'csv', string $row_name = 'row', string $cell_name = 'cell')
31
 * @method array jsonSerialize()
32
 * @method int count()
33
 */
34
class Reader extends AbstractCsv implements JsonSerializable, Countable
35
{
36
    protected static $record_set_methods = [
37
        'fetchPairs' => 1,
38
        'fetchColumn' => 1,
39
        'fetchAll' => 1,
40
        'fetchOne' => 1,
41
        'toHTML' => 1,
42
        'toXML' => 1,
43 159
        'jsonSerialize' => 1,
44
        'count' => 1,
45 159
    ];
46
47
    /**
48
     * @inheritdoc
49
     */
50
    protected $stream_filter_mode = STREAM_FILTER_READ;
51
52
    /**
53
     * Returns the Record object
54
     *
55
     * @param Statement|null $stmt
56 159
     *
57
     * @return RecordSet
58 159
     */
59 75
    public function select(Statement $stmt = null)
60
    {
61
        $stmt = $stmt ?: new Statement();
62 144
63
        return $stmt->process($this);
64
    }
65
66
    /**
67
     * @inheritdoc
68
     */
69
    public function __call($method, array $args)
70
    {
71
        static $stmt;
72
        if (null === $stmt) {
73
            $stmt = new Statement();
74 63
        }
75
76 63
        if (isset(self::$record_set_methods[$method])) {
77
            $records = $stmt->process($this);
78
79
            return call_user_func_array([$records, $method], $args);
80
        }
81
82
        throw new BadMethodCallException(sprintf('Unknown method %s::%s', get_class($this), $method));
83
    }
84
85
    /**
86
     * @inheritdoc
87
     */
88
    public function count()
89 9
    {
90
        return $this->__call('count', []);
91 9
    }
92 9
93 9
    /**
94 9
     * @inheritdoc
95 6
     */
96 9
    public function jsonSerialize()
97 9
    {
98
        return $this->__call('jsonSerialize', []);
99 6
    }
100
}
101