Filename::handles()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 2
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 filename handler.
11
 *
12
 */
13
class Filename 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 9
    public function handles($source): bool
24
    {
25 9
        return is_string($source) && is_file($source);
26
    }
27
28
    /**
29
     * Handle the given source
30
     *
31
     * @param mixed $source
32
     * @param string $path
33
     * @return Traversable
34
     */
35 1
    public function handle($source, string $path): Traversable
36
    {
37 1
        return JsonMachine::fromFile($source, $this->toJsonPointer($path));
38
    }
39
}
40