StringCsvIterator::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
namespace itertools;
4
5
6
use ArrayIterator;
7
8
9
class StringCsvIterator extends AbstractCsvIterator
10
{
11
	protected $lines;
12
13
	public function __construct($input, array $options = array())
14
	{
15
		if(is_string($input)) {
16
			$input = new ArrayIterator(preg_split('/\r\n|\n|\r/', $input));
17
		}
18
		$this->lines = IterUtil::asIterator($input);
19
		$this->lines->rewind();
20
		parent::__construct($options);
21
	}
22
23
	public function retrieveNextCsvRow()
24
	{
25
		$nextLine = IterUtil::getCurrentAndAdvance($this->lines, array('default' => false));
26
		if($nextLine === false) {
27
			return false;
28
		}
29
		$rows = str_getcsv($nextLine, $this->options['delimiter'], $this->options['enclosure'], $this->options['escape']);
30
		return count($rows) == 0 ? false : $rows;
31
	}
32
}
33