Skip to content

Commit a73719b

Browse files
authored
Merge pull request #225 from fbourigault/static-analysis
Static analysis
2 parents ba62c92 + 745fee2 commit a73719b

17 files changed

+266
-150
lines changed

.travis.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@ sudo: false
55
php:
66
- 5.6
77
- 7.0
8-
- 7.1
8+
9+
matrix:
10+
include:
11+
- php: 7.1
12+
env: STATIC_ANALYSIS=yes
913

1014
before_script:
1115
- travis_retry composer self-update
1216
- travis_retry composer install --no-interaction --prefer-source
17+
- if [ "$STATIC_ANALYSIS" != "" ]; then curl -L https://github.com/phpstan/phpstan/releases/download/0.8/phpstan.phar -o phpstan.phar; fi;
1318

1419
script:
1520
- vendor/bin/phpunit --verbose --coverage-text
21+
- if [ "$STATIC_ANALYSIS" != "" ]; then php phpstan.phar analyse --level=4 lib; fi;

lib/Gitlab/Api/IssueBoards.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@ public function createList($project_id, $board_id, $label_id)
6363
/**
6464
* @param int $project_id
6565
* @param int $board_id
66-
* @param int $label_id
66+
* @param int $list_id
6767
* @param int $position
6868
* @return mixed
6969
*/
70-
public function updateList($project_id, $board_id, $label_id, $position)
70+
public function updateList($project_id, $board_id, $list_id, $position)
7171
{
7272
$params = array(
7373
'id' => $project_id,
7474
'board_id' => $board_id,
75-
'label_id' => $label_id,
75+
'list_id' => $list_id,
7676
'position' => $position
7777
);
7878

@@ -82,10 +82,10 @@ public function updateList($project_id, $board_id, $label_id, $position)
8282
/**
8383
* @param int $project_id
8484
* @param int $board_id
85-
* @param int $label_id
85+
* @param int $list_id
8686
* @return mixed
8787
*/
88-
public function deleteList($project_id, $board_id, $label_id)
88+
public function deleteList($project_id, $board_id, $list_id)
8989
{
9090
return $this->delete($this->getProjectPath($project_id, 'boards/'.$this->encodePath($board_id).'/lists/'.$this->encodePath($list_id)));
9191
}

lib/Gitlab/Api/Users.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ public function show($id)
5454
return $this->get('users/'.$this->encodePath($id));
5555
}
5656

57+
/**
58+
* @return mixed
59+
*/
60+
public function user()
61+
{
62+
return $this->get('user');
63+
}
64+
5765
/**
5866
* @param string $email
5967
* @param string $password

lib/Gitlab/Client.php

Lines changed: 135 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,126 @@ public static function createWithHttpClient(HttpClient $httpClient)
117117
return new self($builder);
118118
}
119119

120+
/**
121+
* @return Api\DeployKeys
122+
*/
123+
public function deployKeys()
124+
{
125+
return new Api\DeployKeys($this);
126+
}
127+
128+
/**
129+
* @return Api\Groups
130+
*/
131+
public function groups()
132+
{
133+
return new Api\Groups($this);
134+
}
135+
136+
/**
137+
* @return Api\Issues
138+
*/
139+
public function issues()
140+
{
141+
return new Api\Issues($this);
142+
}
143+
144+
/**
145+
* @return Api\IssueBoards
146+
*/
147+
public function issueBoards()
148+
{
149+
return new Api\IssueBoards($this);
150+
}
151+
152+
/**
153+
* @return Api\Jobs
154+
*/
155+
public function jobs()
156+
{
157+
return new Api\Jobs($this);
158+
}
159+
160+
/**
161+
* @return Api\MergeRequests
162+
*/
163+
public function mergeRequests()
164+
{
165+
return new Api\MergeRequests($this);
166+
}
167+
168+
/**
169+
* @return Api\Milestones
170+
*/
171+
public function milestones()
172+
{
173+
return new Api\Milestones($this);
174+
}
175+
176+
/**
177+
* @return Api\ProjectNamespaces
178+
*/
179+
public function namespaces()
180+
{
181+
return new Api\ProjectNamespaces($this);
182+
}
183+
184+
/**
185+
* @return Api\Projects
186+
*/
187+
public function projects()
188+
{
189+
return new Api\Projects($this);
190+
}
191+
192+
/**
193+
* @return Api\Repositories
194+
*/
195+
public function repositories()
196+
{
197+
return new Api\Repositories($this);
198+
}
199+
200+
/**
201+
* @return Api\Snippets
202+
*/
203+
public function snippets()
204+
{
205+
return new Api\Snippets($this);
206+
}
207+
208+
/**
209+
* @return Api\SystemHooks
210+
*/
211+
public function systemHooks()
212+
{
213+
return new Api\SystemHooks($this);
214+
}
215+
216+
/**
217+
* @return Api\Users
218+
*/
219+
public function users()
220+
{
221+
return new Api\Users($this);
222+
}
223+
224+
/**
225+
* @return Api\Keys
226+
*/
227+
public function keys()
228+
{
229+
return new Api\Keys($this);
230+
}
231+
232+
/**
233+
* @return Api\Tags
234+
*/
235+
public function tags()
236+
{
237+
return new Api\Tags($this);
238+
}
239+
120240
/**
121241
* @param string $name
122242
*
@@ -128,75 +248,58 @@ public function api($name)
128248
switch ($name) {
129249

130250
case 'deploy_keys':
131-
$api = new Api\DeployKeys($this);
132-
break;
251+
return $this->deployKeys();
133252

134253
case 'groups':
135-
$api = new Api\Groups($this);
136-
break;
254+
return $this->groups();
137255

138256
case 'issues':
139-
$api = new Api\Issues($this);
140-
break;
257+
return $this->issues();
141258

142259
case 'board':
143260
case 'issue_boards':
144-
$api = new Api\IssueBoards($this);
261+
return $this->issueBoards();
145262
case 'jobs':
146-
$api = new Api\Jobs($this);
147-
break;
263+
return $this->jobs();
148264

149265
case 'mr':
150266
case 'merge_requests':
151-
$api = new Api\MergeRequests($this);
152-
break;
267+
return $this->mergeRequests();
153268

154269
case 'milestones':
155270
case 'ms':
156-
$api = new Api\Milestones($this);
157-
break;
271+
return $this->milestones();
158272

159273
case 'namespaces':
160274
case 'ns':
161-
$api = new Api\ProjectNamespaces($this);
162-
break;
275+
return $this->namespaces();
163276

164277
case 'projects':
165-
$api = new Api\Projects($this);
166-
break;
278+
return $this->projects();
167279

168280
case 'repo':
169281
case 'repositories':
170-
$api = new Api\Repositories($this);
171-
break;
282+
return $this->repositories();
172283

173284
case 'snippets':
174-
$api = new Api\Snippets($this);
175-
break;
285+
return $this->snippets();
176286

177287
case 'hooks':
178288
case 'system_hooks':
179-
$api = new Api\SystemHooks($this);
180-
break;
289+
return $this->systemHooks();
181290

182291
case 'users':
183-
$api = new Api\Users($this);
184-
break;
292+
return $this->users();
185293

186294
case 'keys':
187-
$api = new Api\Keys($this);
188-
break;
295+
return $this->keys();
189296

190297
case 'tags':
191-
$api = new Api\Tags($this);
192-
break;
298+
return $this->tags();
193299

194300
default:
195301
throw new InvalidArgumentException('Invalid endpoint: "'.$name.'"');
196-
197302
}
198-
199-
return $api;
200303
}
201304

202305
/**

lib/Gitlab/HttpClient/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Builder
3131
/**
3232
* A HTTP client with all our plugins.
3333
*
34-
* @var PluginClient
34+
* @var HttpMethodsClient
3535
*/
3636
private $pluginClient;
3737

lib/Gitlab/Model/Branch.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function __construct(Project $project, $name = null, Client $client = nul
5757
*/
5858
public function show()
5959
{
60-
$data = $this->api('repositories')->branch($this->project->id, $this->name);
60+
$data = $this->client->repositories()->branch($this->project->id, $this->name);
6161

6262
return static::fromArray($this->getClient(), $this->project, $data);
6363
}
@@ -69,7 +69,7 @@ public function show()
6969
*/
7070
public function protect($devPush = false, $devMerge = false)
7171
{
72-
$data = $this->api('repositories')->protectBranch($this->project->id, $this->name, $devPush, $devMerge);
72+
$data = $this->client->repositories()->protectBranch($this->project->id, $this->name, $devPush, $devMerge);
7373

7474
return static::fromArray($this->getClient(), $this->project, $data);
7575
}
@@ -79,7 +79,7 @@ public function protect($devPush = false, $devMerge = false)
7979
*/
8080
public function unprotect()
8181
{
82-
$data = $this->api('repositories')->unprotectBranch($this->project->id, $this->name);
82+
$data = $this->client->repositories()->unprotectBranch($this->project->id, $this->name);
8383

8484
return static::fromArray($this->getClient(), $this->project, $data);
8585
}
@@ -89,7 +89,7 @@ public function unprotect()
8989
*/
9090
public function delete()
9191
{
92-
$this->api('repositories')->deleteBranch($this->project->id, $this->name);
92+
$this->client->repositories()->deleteBranch($this->project->id, $this->name);
9393

9494
return true;
9595
}
@@ -112,7 +112,7 @@ public function commits($page = 1, $per_page = Api::PER_PAGE)
112112
*/
113113
public function createFile($file_path, $content, $commit_message)
114114
{
115-
$data = $this->api('repositories')->createFile($this->project->id, $file_path, $content, $this->name, $commit_message);
115+
$data = $this->client->repositories()->createFile($this->project->id, $file_path, $content, $this->name, $commit_message);
116116

117117
return File::fromArray($this->getClient(), $this->project, $data);
118118
}
@@ -125,7 +125,7 @@ public function createFile($file_path, $content, $commit_message)
125125
*/
126126
public function updateFile($file_path, $content, $commit_message)
127127
{
128-
$data = $this->api('repositories')->updateFile($this->project->id, $file_path, $content, $this->name, $commit_message);
128+
$data = $this->client->repositories()->updateFile($this->project->id, $file_path, $content, $this->name, $commit_message);
129129

130130
return File::fromArray($this->getClient(), $this->project, $data);
131131
}
@@ -137,7 +137,7 @@ public function updateFile($file_path, $content, $commit_message)
137137
*/
138138
public function deleteFile($file_path, $commit_message)
139139
{
140-
$this->api('repositories')->deleteFile($this->project->id, $file_path, $this->name, $commit_message);
140+
$this->client->repositories()->deleteFile($this->project->id, $file_path, $this->name, $commit_message);
141141

142142
return true;
143143
}

0 commit comments

Comments
 (0)