public function toSerializableArray()
    {
        $arr = [
            'message' => $this->getMessage(),
        ];

        $locations = Utils::map(
            $this->getLocations(),
            static function (SourceLocation $loc) {
                return $loc->toSerializableArray();
            }
        );

        if (! empty($locations)) {
            $arr['locations'] = $locations;
        }
        if (! empty($this->path)) {
            $arr['path'] = $this->path;
        }
        if (! empty($this->extensions)) {
            $arr['extensions'] = $this->extensions;
        }

        return $arr;
    }