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

Resource   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handles() 0 3 1
A handle() 0 3 1
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