| @@ 238-255 (lines=18) @@ | ||
| 235 | * @return JsonWritable |
|
| 236 | * @throws \LogicException |
|
| 237 | */ |
|
| 238 | public function writeNull(): JsonWritable |
|
| 239 | { |
|
| 240 | if ($this->stackSize > 0 && $this->stackStates[$this->stackSize - 1] === self::STATE_OBJECT_NAME) { |
|
| 241 | throw new LogicException('Cannot call writeNull() before name() during object serialization'); |
|
| 242 | } |
|
| 243 | ||
| 244 | if ($this->serializeNull) { |
|
| 245 | return $this->push(new JsonNull()); |
|
| 246 | } |
|
| 247 | ||
| 248 | // if we're not serializing nulls |
|
| 249 | if (null !== $this->pendingName) { |
|
| 250 | $this->stackStates[$this->stackSize - 1] = self::STATE_OBJECT_NAME; |
|
| 251 | $this->pendingName = null; |
|
| 252 | } |
|
| 253 | ||
| 254 | return $this; |
|
| 255 | } |
|
| 256 | ||
| 257 | /** |
|
| 258 | * Sets whether nulls are serialized |
|
| @@ 233-251 (lines=19) @@ | ||
| 230 | * @return JsonWritable |
|
| 231 | * @throws \LogicException |
|
| 232 | */ |
|
| 233 | public function writeNull(): JsonWritable |
|
| 234 | { |
|
| 235 | if ($this->stackSize > 0 && $this->stackStates[$this->stackSize - 1] === self::STATE_OBJECT_NAME) { |
|
| 236 | throw new LogicException('Cannot call writeNull() before name() during object serialization'); |
|
| 237 | } |
|
| 238 | ||
| 239 | if ($this->serializeNull) { |
|
| 240 | $null = null; |
|
| 241 | return $this->push($null); |
|
| 242 | } |
|
| 243 | ||
| 244 | // if we're not serializing nulls |
|
| 245 | if (null !== $this->pendingName) { |
|
| 246 | $this->stackStates[$this->stackSize - 1] = self::STATE_OBJECT_NAME; |
|
| 247 | $this->pendingName = null; |
|
| 248 | } |
|
| 249 | ||
| 250 | return $this; |
|
| 251 | } |
|
| 252 | ||
| 253 | /** |
|
| 254 | * Sets whether nulls are serialized |
|