Passed
Branch feature/first-release (668b10)
by Andrea Marco
02:52
created

Filename::shouldHandleSource()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 2
nc 2
nop 0
crap 6
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
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