| Conditions | 8 |
| Paths | 12 |
| Total Lines | 29 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 18 |
| CRAP Score | 8 |
| Changes | 0 | ||
| 1 | <?php |
||
| 29 | 2 | public function process($data) |
|
| 30 | { |
||
| 31 | 2 | if (!is_array($data) && !is_object($data)) { |
|
| 32 | 2 | return $data === $this->search ? $this->replace : $data; |
|
| 33 | } |
||
| 34 | |||
| 35 | 2 | $originalKeys = $data instanceof \stdClass ? get_object_vars($data) : $data; |
|
| 36 | |||
| 37 | 2 | $diff = new JsonDiff($data, $this->search, JsonDiff::STOP_ON_DIFF); |
|
| 38 | 2 | if ($diff->getDiffCnt() === 0) { |
|
| 39 | 1 | return $this->replace; |
|
| 40 | } |
||
| 41 | |||
| 42 | 2 | $result = array(); |
|
| 43 | |||
| 44 | 2 | foreach ($originalKeys as $key => $originalValue) { |
|
| 45 | 2 | $path = $this->path; |
|
| 46 | 2 | $pathItems = $this->pathItems; |
|
| 47 | 2 | $actualKey = $key; |
|
| 48 | 2 | $this->path .= '/' . JsonPointer::escapeSegment($actualKey); |
|
| 49 | 2 | $this->pathItems[] = $actualKey; |
|
| 50 | |||
| 51 | 2 | $result[$key] = $this->process($originalValue); |
|
| 52 | |||
| 53 | 2 | $this->path = $path; |
|
| 54 | 2 | $this->pathItems = $pathItems; |
|
| 55 | } |
||
| 56 | |||
| 57 | 2 | return $data instanceof \stdClass ? (object)$result : $result; |
|
| 58 | } |
||
| 59 | } |