$item) { if ($index !== $observationIndex && $item !== $before['cases'][$caseIndex]['fixed_passage_lines'][$lineIndex]['observations'][$index]) { throw new RuntimeException('Another phase changed.'); } } if (! is_file($backup)) { file_put_contents($backup, $original); } $encoded = json_encode($data, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_THROW_ON_ERROR); $encoded = preg_replace_callback('/^ +/m', fn ($match) => str_repeat(' ', intdiv(strlen($match[0]), 2)), $encoded); file_put_contents($path, $encoded."\n"); echo json_encode(['line'=>1, 'QA21'=>'passou', 'phase_2'=>'não observado', 'other_lines_and_aggregate_states_unchanged'=>true], JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR).PHP_EOL;