for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Aweapi\Openapi;
use JsonSerializable;
use stdClass;
final class JsonObject implements JsonSerializable
{
private $data = [];
public function jsonSerialize()
return $this->data ?: self::emptyObject();
}
/**
* @param mixed $value
*/
public function setOptionalProperty(string $name, $value): void
if (!self::isEmpty($value)) {
$this->setRequiredProperty($name, $value);
public function setRequiredNestedProperty(string $name, $value): void
$this->setRequiredProperty(
$name,
self::isEmpty($value)
? self::emptyObject()
: $value
);
public function setRequiredProperty(string $name, $value): void
$this->data[$name] = $value;
* Use this instead of empty maps for required properties to force JSON-object.
private static function emptyObject(): stdClass
return new stdClass();
private static function isEmpty($value): bool
if ($value instanceof JsonSerializable) {
JsonSerializable
return self::isEmpty($value->jsonSerialize());
return empty($value);