commits = new \ArrayObject; } /** * Creates a new event from the specified JSON map. * @param object $map A JSON map representing an event. * @return static The instance corresponding to the specified JSON map. */ static function fromJson(object $map): self { return new static([ 'after' => isset($map->after) && is_string($map->after) ? $map->after : '', 'before' => isset($map->before) && is_string($map->before) ? $map->before : '', 'compareUrl' => isset($map->compare_url) && is_string($map->compare_url) ? new Uri($map->compare_url) : null, 'commits' => isset($map->commits) && is_array($map->commits) ? array_map([PayloadCommit::class, 'fromJson'], $map->commits) : [], 'pusher' => isset($map->pusher) && is_object($map->pusher) ? User::fromJson($map->pusher) : null, 'ref' => isset($map->ref) && is_string($map->ref) ? $map->ref : '', 'repository' => isset($map->repository) && is_object($map->repository) ? Repository::fromJson($map->repository) : null, 'secret' => isset($map->secret) && is_string($map->secret) ? $map->secret : '', 'sender' => isset($map->sender) && is_object($map->sender) ? User::fromJson($map->sender) : null ]); } /** * Returns the list of fields that should be returned by default. * @return array The list of field names or field definitions. */ function fields(): array { return [ 'after', 'before', 'compare_url' => function(self $model) { return ($url = $model->getCompareUrl()) ? (string) $url : null; }, 'commits', 'pusher', 'ref', 'repository', 'sender' ]; } /** * Gets the revision commits. * @return \ArrayObject The revision commits. */ function getCommits(): \ArrayObject { return $this->commits; } /** * Gets the URL for comparing the revisions. * @return UriInterface|null The URL for comparing the revisions. */ function getCompareUrl(): ?UriInterface { return $this->compareUrl; } /** * Sets the revision commits. * @param PayloadCommit[] $values The revision commits. * @return $this This instance. */ function setCommits(array $values): self { $this->getCommits()->exchangeArray($values); return $this; } /** * Sets the URL for comparing the revisions. * @param UriInterface|string|null $value The URL for comparing the revisions. * @return $this This instance. */ function setCompareUrl($value): self { $this->compareUrl = is_string($value) ? new Uri($value) : $value; return $this; } }