Total Complexity | 6 |
Total Lines | 79 |
Duplicated Lines | 0 % |
Coverage | 0% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
11 | abstract class AbstractHandler |
||
12 | { |
||
13 | /** |
||
14 | * The JSON source. |
||
15 | * |
||
16 | * @var mixed |
||
17 | */ |
||
18 | protected $source; |
||
19 | |||
20 | /** |
||
21 | * The dot-noted path. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $path; |
||
26 | |||
27 | /** |
||
28 | * Instantiate the class. |
||
29 | * |
||
30 | * @param mixed $source |
||
31 | * @param string $path |
||
32 | */ |
||
33 | public function __construct(&$source, string $path) |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * Determine whether the handler should handle the source |
||
41 | * |
||
42 | * @return bool |
||
43 | */ |
||
44 | abstract protected function shouldHandleSource(): bool; |
||
45 | |||
46 | /** |
||
47 | * Handle the source |
||
48 | * |
||
49 | * @return Traversable|null |
||
50 | */ |
||
51 | abstract protected function handleSource(): ?Traversable; |
||
52 | |||
53 | /** |
||
54 | * Instantiate the class |
||
55 | * |
||
56 | * @param mixed $source |
||
57 | * @param string $path |
||
58 | * @return self |
||
59 | */ |
||
60 | public static function of(&$source, string $path): self |
||
61 | { |
||
62 | return new static($source, $path); |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Attempts to retrieve a traversable JSON from the source |
||
67 | * |
||
68 | * @return Traversable|null |
||
69 | */ |
||
70 | public function handle(): ?Traversable |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * Retrieve the JSON pointer of the dot-noted path |
||
77 | * |
||
78 | * @param string $path |
||
79 | * @return string |
||
80 | */ |
||
81 | protected function pointer(): string |
||
92 |