Passed
Push — master ( 222a88...547f19 )
by Andrea Marco
02:49 queued 12s
created

Macro::__invoke()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
nc 1
nop 2
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Cerbero\LazyJson;
4
5
use Cerbero\LazyJson\Exceptions\LazyJsonException;
6
use Illuminate\Support\LazyCollection;
7
use Throwable;
8
9
/**
10
 * The lazy collection macro.
11
 *
12
 */
13
class Macro
14
{
15
    /**
16
     * Load the given JSON source in a lazy collection
17
     *
18
     * @param mixed $source
19
     * @param string $path
20
     * @return LazyCollection
21
     */
22 9
    public function __invoke($source, string $path = ''): LazyCollection
23
    {
24 9
        return new LazyCollection(function () use ($source, $path) {
25
            try {
26 9
                yield from new Source($source, $path);
27 2
            } catch (Throwable $e) {
28 2
                throw new LazyJsonException($e->getMessage(), 0, $e);
29
            }
30 9
        });
31
    }
32
}
33