StringCsvIterator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 24
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A retrieveNextCsvRow() 0 9 3
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