Resource::handle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Cerbero\LazyJson\Handlers;
4
5
use Cerbero\LazyJson\Concerns\JsonPointerAware;
6
use JsonMachine\JsonMachine;
7
use Traversable;
8
9
/**
10
 * The resource handler.
11
 *
12
 */
13
class Resource implements Handler
14
{
15
    use JsonPointerAware;
16
17
    /**
18
     * Determine whether the handler can handle the given source
19
     *
20
     * @param mixed $source
21
     * @return bool
22
     */
23 2
    public function handles($source): bool
24
    {
25 2
        return is_resource($source);
26
    }
27
28
    /**
29
     * Handle the given source
30
     *
31
     * @param mixed $source
32
     * @param string $path
33
     * @return Traversable
34
     */
35 6
    public function handle($source, string $path): Traversable
36
    {
37 6
        return JsonMachine::fromStream($source, $this->toJsonPointer($path));
38
    }
39
}
40