Skip to content

Commit 5767e46

Browse files
authored
Merge pull request #1 from DiegoRelyveld/patch-1
Laravel 9.x compatibility
2 parents f6a9cd3 + 9b7975d commit 5767e46

File tree

6 files changed

+25
-25
lines changed

6 files changed

+25
-25
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
}
1515
},
1616
"require": {
17-
"php": "^7.4|^8.0",
17+
"php": "^7.4.15 || ^8.0.2",
1818
"ext-json": "*",
1919
"guzzlehttp/guzzle": "^7.0.1",
2020
"http-interop/http-factory-guzzle": "^1.0",
21-
"illuminate/support": "^7.0|^8.0",
22-
"m4tthumphrey/php-gitlab-api": "^9.0",
21+
"illuminate/support": "^7.0|^8.0|^9.0",
22+
"m4tthumphrey/php-gitlab-api": "^11.7.0",
2323
"php-http/guzzle7-adapter": "^1.0.0"
2424
}
2525
}

src/Contracts/GitPlatformInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function addRepository(array $properties, ?GitOwnerInterface $owner = nul
2727
* @param bool $onlyActive
2828
* @return GitUserInterface[]
2929
*/
30-
public function getUserList($onlyActive = true): array;
30+
public function getUserList(bool $onlyActive = true): array;
3131

3232
public function getUser(string $idOrName): GitUserInterface;
3333

src/Models/GitLab/GitLabClient.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,13 @@ private function makeModelForType(string $type, array $properties, $parent = nul
5757

5858
public function getModelInstance($type, $id, $parent)
5959
{
60-
return $this->makeModelForType($type, $this->api($type)->show($id), $parent);
60+
return $this->makeModelForType($type, $this->{$type}()->show($id), $parent);
6161
}
6262

63-
public function getAllData($api, $method = 'all', $methodParameters = [])
63+
public function getAllData($api, $method = 'all', $methodParameters = []): array
6464
{
6565
try {
66-
$pager = new ResultPager($this);
67-
return $pager->fetchAll($this->api($api), $method, $methodParameters);
66+
return (new ResultPager($this))->fetchAll($this->{$api}(), $method, $methodParameters);
6867
} catch (ExceptionInterface $e) {
6968
throw new GitException(
7069
"Unable to fetch all data for {$api}->{$method}: {$e->getMessage()}", $e->getCode(), $e
@@ -88,7 +87,7 @@ public function getAllModelInstances(
8887

8988
public function addModelInstance($type, $requiredProperties, $extraProperties = null, $parent = null)
9089
{
91-
$api = $this->api($type);
90+
$api = $this->{$type}();
9291
$params = $requiredProperties;
9392
if ($extraProperties) {
9493
$params[] = $extraProperties;

src/Models/GitLab/GitLabPlatform.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ class GitLabPlatform extends GitPlatform
2222

2323
public function __construct(array $config)
2424
{
25-
$this->client = (new GitLabClient())
26-
->setUrl($config['url'])
27-
->authenticate($config['auth'], GitLabClient::AUTH_HTTP_TOKEN);
25+
$this->client = new GitLabClient();
26+
27+
$this->client->setUrl($config['url']);
28+
$this->client->authenticate($config['auth'], GitLabClient::AUTH_HTTP_TOKEN);
2829

2930
parent::__construct($config);
3031
}
@@ -118,7 +119,7 @@ public function addRepository(array $properties, ?GitOwnerInterface $owner = nul
118119
}
119120
}
120121

121-
public function getUserList($onlyActive = true): array
122+
public function getUserList(bool $onlyActive = true): array
122123
{
123124
$filter = [];
124125
if ($onlyActive) {
@@ -176,21 +177,21 @@ public function getTeamList(string $namespace = null): array
176177

177178
return array_filter(
178179
$this->client->getAllModelInstances(GitLabClient::TYPE_GROUPS, $this),
179-
function ($team) use ($namespace) {
180+
static function ($team) use ($namespace) {
180181
return $team->namespace === $namespace;
181182
}
182183
);
183184
}
184185

185-
public function getTeam(string $teamId, string $namespace = null): GitTeamInterface
186+
public function getTeam(string $idOrName, string $namespace = null): GitTeamInterface
186187
{
187188
$namespace = $namespace ?? $this->defaultTeamNamespace;
188-
if (!is_numeric($teamId) && $namespace !== '') {
189-
$teamId = "{$namespace}/{$teamId}";
189+
if (!is_numeric($idOrName) && $namespace !== '') {
190+
$idOrName = "{$namespace}/{$idOrName}";
190191
}
191192

192193
try {
193-
return $this->client->getModelInstance(GitLabClient::TYPE_GROUPS, $teamId, $this);
194+
return $this->client->getModelInstance(GitLabClient::TYPE_GROUPS, $idOrName, $this);
194195
} catch (ExceptionInterface $e) {
195196
throw new GitException("Unable to get team: {$e->getMessage()}", $e->getCode(), $e);
196197
}

src/Models/GitLab/GitLabRepository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,9 @@ public function getOwner(): GitOwnerInterface
309309
{
310310
if ($this->ownerType === 'user') {
311311
return $this->platform->getUser($this->ownerId);
312-
} else {
313-
return $this->platform->getTeam($this->ownerId);
314312
}
313+
314+
return $this->platform->getTeam($this->ownerId);
315315
}
316316

317317
public function transferTo(GitOwnerInterface $owner): void

src/Models/Gitea/GiteaPlatform.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function addRepository(array $properties, ?GitOwnerInterface $owner = nul
5454
return $this->client->post(GiteaRepository::class, "/org/{$namespace}/repos", $this, $properties);
5555
}
5656

57-
public function getUserList($onlyActive = true): array
57+
public function getUserList(bool $onlyActive = true): array
5858
{
5959
$namespace = $this->defaultTeamNamespace;
6060
return $this->client->getAll(GiteaUser::class, "/orgs/{$namespace}/members", $this);
@@ -64,18 +64,18 @@ public function getUser(string $idOrName): GitUserInterface
6464
{
6565
if (is_numeric($idOrName)) {
6666
return $this->client->getFirst(GiteaUser::class, "/users/search?uid={$idOrName}", $this);
67-
} else {
68-
return $this->client->get(GiteaUser::class, "/users/{$idOrName}", $this);
6967
}
68+
69+
return $this->client->get(GiteaUser::class, "/users/{$idOrName}", $this);
7070
}
7171

7272
public function getUserAsAdmin(string $idOrName): GitUserInterface
7373
{
7474
if (is_numeric($idOrName)) {
7575
return $this->client->getFirst(GiteaUser::class, "/users/search?uid={$idOrName}", $this);
76-
} else {
77-
return $this->client->get(GiteaUser::class, "/users/{$idOrName}", $this);
7876
}
77+
78+
return $this->client->get(GiteaUser::class, "/users/{$idOrName}", $this);
7979
}
8080

8181
public function addUser(array $properties): GitUserInterface

0 commit comments

Comments
 (0)