Macro   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 16
ccs 5
cts 5
cp 1
rs 10
c 1
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 7 2
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