Why this matters
External APIs change. Structural checks prevent downstream errors and data corruption.
After decoding, assert required keys and types before use; reject unexpected shapes.
External APIs change. Structural checks prevent downstream errors and data corruption.
Side-by-side examples engineers can pattern-match during review.
$status = $data['status']; $id = $data['id'];if (!isset($data['status'], $data['id']) || !is_string($data['status'])) {
throw new UnexpectedValueException('Invalid response structure');
}$v = $data['x'];if(!isset($data['x'])) throw new UnexpectedValueException()From the same buckets as this rule.