Passed
Branch feature/first-release (f6e752)
by Andrea Marco
02:33
created

Macro   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

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
    public function __invoke($source, string $path = ''): LazyCollection
23
    {
24
        return new LazyCollection(function () use ($source, $path) {
25
            try {
26
                yield from new Source($source, $path);
27
            } catch (Throwable $e) {
28
                throw new LazyJsonException($e->getMessage(), 0, $e);
29
            }
30
        });
31
    }
32
}
33