Passed
Push — master ( 1ed9d2...698c63 )
by Sergio
01:13
created

JSONParser::__construct()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 1
nop 0
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: sergio.rodenas
5
 * Date: 14/5/18
6
 * Time: 11:02
7
 */
8
9
namespace Rodenastyle\StreamParser\Parsers;
10
11
12
use Rodenastyle\StreamParser\Services\JsonCollectionParser as Parser;
13
use Rodenastyle\StreamParser\StreamParserInterface;
14
use Tightenco\Collect\Support\Collection;
15
16
class JSONParser implements StreamParserInterface
17
{
18
	protected $reader, $source;
19
20 4
	public function from(String $source): StreamParserInterface
21
	{
22 4
		$this->source = $source;
23
24 4
		return $this;
25
	}
26
27 4
	public function each(callable $function)
28
	{
29 4
		$this->start();
30 4
		$this->reader->parse($this->source, function(array $item) use ($function){
31 4
			$function((new Collection($item))->recursive());
32 4
		});
33 4
	}
34
35 4
	private function start()
36
	{
37 4
		$this->reader = new Parser();
38
39 4
		return $this;
40
	}
41
}
42