mirror of
https://github.com/sitelease/sugar-cube-client.git
synced 2025-10-29 19:12:30 +01:00
PushEvents - Fixed two errors
+ Fixed "array_map() expects parameter 1 to be a valid callback" error + Fixed "Argument 1 passed to Gitea\PushEvent::setCommits() must be of the type array, null given"
This commit is contained in:
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
namespace Gitea;
|
namespace Gitea;
|
||||||
|
|
||||||
use Gitea\Models\{PayloadCommit, Repository, User};
|
use Gitea\Model\PayloadCommit;
|
||||||
|
use Gitea\Model\Repository;
|
||||||
|
use Gitea\Model\User;
|
||||||
use GuzzleHttp\Exception\ClientException;
|
use GuzzleHttp\Exception\ClientException;
|
||||||
use GuzzleHttp\Psr7\Uri;
|
use GuzzleHttp\Psr7\Uri;
|
||||||
use Psr\Http\Message\UriInterface;
|
use Psr\Http\Message\UriInterface;
|
||||||
@ -101,19 +103,28 @@ class PushEvent extends AbstractApiModel {
|
|||||||
* @return static The instance corresponding to the specified JSON map.
|
* @return static The instance corresponding to the specified JSON map.
|
||||||
*/
|
*/
|
||||||
static function fromJson(object &$client, ?object $caller, object $map): self {
|
static function fromJson(object &$client, ?object $caller, object $map): self {
|
||||||
return (new static(
|
$newEvent = new static(
|
||||||
$client,
|
$client,
|
||||||
$caller
|
$caller
|
||||||
))
|
);
|
||||||
->setAfter(isset($map->after) && is_string($map->after) ? $map->after : '')
|
$newEvent->setAfter(isset($map->after) && is_string($map->after) ? $map->after : '')
|
||||||
->setBefore(isset($map->before) && is_string($map->before) ? $map->before : '')
|
->setBefore(isset($map->before) && is_string($map->before) ? $map->before : '')
|
||||||
->setCompareUrl(isset($map->compare_url) && is_string($map->compare_url) ? new Uri($map->compare_url) : null)
|
->setCompareUrl(isset($map->compare_url) && is_string($map->compare_url) ? new Uri($map->compare_url) : null)
|
||||||
->setCommits(isset($map->commits) && is_array($map->commits) ? array_map([PayloadCommit::class, 'fromJson'], $map->commits) : [])
|
->setPusher(isset($map->pusher) && is_object($map->pusher) ? User::fromJson($client, null, $map->pusher) : null)
|
||||||
->setPusher(isset($map->pusher) && is_object($map->pusher) ? User::fromJson($client, $caller, $map->pusher) : null)
|
->setRef(isset($map->ref) && is_string($map->ref) ? $map->ref : '')
|
||||||
->setRef(isset($map->ref) && is_string($map->ref) ? $map->ref : '')
|
->setRepository(isset($map->repository) && is_object($map->repository) ? Repository::fromJson($client, null, $map->repository) : null)
|
||||||
->setRepository(isset($map->repository) && is_object($map->repository) ? Repository::fromJson($client, $caller, $map->repository) : null)
|
->setSecret(isset($map->secret) && is_string($map->secret) ? $map->secret : '')
|
||||||
->setSecret(isset($map->secret) && is_string($map->secret) ? $map->secret : '')
|
->setSender(isset($map->sender) && is_object($map->sender) ? User::fromJson($client, null, $map->sender) : null);
|
||||||
->setSender(isset($map->sender) && is_object($map->sender) ? User::fromJson($client, $caller, $map->sender) : null);
|
|
||||||
|
if(isset($map->commits) && is_array($map->commits)) {
|
||||||
|
$commitsArray = [];
|
||||||
|
foreach ($commits as $commit) {
|
||||||
|
$commitsArray[] = PayloadCommit::fromJson($client, null, $commit);
|
||||||
|
}
|
||||||
|
$newEvent->setCommits($commitsArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $newEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user