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

JSONParser   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 24
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A each() 0 5 1
A from() 0 5 1
A start() 0 5 1
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