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

JsonString::handle()   A

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\EndpointAware;
6
use Cerbero\LazyJson\Concerns\JsonPointerAware;
7
use JsonMachine\JsonMachine;
8
use Traversable;
9
10
/**
11
 * The JSON string handler.
12
 *
13
 */
14
class JsonString implements Handler
15
{
16
    use EndpointAware;
17
    use JsonPointerAware;
18
19
    /**
20
     * Determine whether the handler can handle the given source
21
     *
22
     * @param mixed $source
23
     * @return bool
24
     */
25 7
    public function handles($source): bool
26
    {
27 7
        return is_string($source) && !is_file($source) && !$this->isEndpoint($source);
28
    }
29
30
    /**
31
     * Handle the given source
32
     *
33
     * @param mixed $source
34
     * @param string $path
35
     * @return Traversable
36
     */
37 2
    public function handle($source, string $path): Traversable
38
    {
39 2
        return JsonMachine::fromString($source, $this->toJsonPointer($path));
40
    }
41
}
42