JSONParser::each()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
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