JsonString   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

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