Skip to content

Commit 7e118c3

Browse files
committed
Reordered $client parameter
1 parent 766b2e7 commit 7e118c3

File tree

14 files changed

+79
-80
lines changed

14 files changed

+79
-80
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ General API Usage
2929
-----------------
3030

3131
```php
32-
$gitlab = new \Gitlab\Client('http://git.yourdomain.com/api/v3/'); // change here
33-
$gitlab->authenticate('your_gitlab_token_here', \Gitlab\Client::AUTH_URL_TOKEN); // change here
32+
$client = new \Gitlab\Client('http://git.yourdomain.com/api/v3/'); // change here
33+
$client->authenticate('your_gitlab_token_here', \Gitlab\Client::AUTH_URL_TOKEN); // change here
3434

35-
$project = $gitlab->api('projects')->create('My Project', array(
35+
$project = $client->api('projects')->create('My Project', array(
3636
'description' => 'This is a project'
3737
'issues_enabled' => false
3838
));
@@ -45,17 +45,17 @@ Model Usage
4545
You can also use the library in an object oriented manner. This is an experimental branch used for decided how to manage dependencies within model usage.
4646

4747
```php
48-
$gitlab = new \Gitlab\Client('http://git.yourdomain.com/api/v3/'); // change here
49-
$gitlab->authenticate('your_gitlab_token_here', \Gitlab\Client::AUTH_URL_TOKEN); // change here
48+
$client = new \Gitlab\Client('http://git.yourdomain.com/api/v3/'); // change here
49+
$client->authenticate('your_gitlab_token_here', \Gitlab\Client::AUTH_URL_TOKEN); // change here
5050
```
5151

5252
Creating a new project
5353

5454
```php
55-
$project = \Gitlab\Model\Project::create('My Project', array(
55+
$project = \Gitlab\Model\Project::create($client, 'My Project', array(
5656
'description' => 'This is my project',
5757
'issues_enabled' => false
58-
), $gitlab);
58+
));
5959

6060
$project->addHook('http://mydomain.com/hook/push/1');
6161

@@ -65,7 +65,7 @@ Creating a new issue
6565

6666
```php
6767
$project = new \Gitlab\Model\Project(1);
68-
$project->setClient($gitlab);
68+
$project->setClient($client);
6969
$issue = $project->createIssue('This does not work..', array(
7070
'description' => 'This doesnt work properly. Please fix',
7171
'assignee_id' => 2

lib/Gitlab/Model/Branch.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ class Branch extends AbstractModel
1313
'protected'
1414
);
1515

16-
public static function fromArray(Project $project, array $data, Client $client)
16+
public static function fromArray(Client $client, Project $project, array $data)
1717
{
1818
$branch = new Branch($project, $data['name']);
1919
$branch->setClient($client);
2020

2121
if (isset($data['commit'])) {
22-
$data['commit'] = Commit::fromArray($project, $data['commit'], $client);
22+
$data['commit'] = Commit::fromArray($client, $project, $data['commit']);
2323
}
2424

2525
return $branch->hydrate($data);
@@ -35,21 +35,20 @@ public function show()
3535
{
3636
$data = $this->api('repositories')->branch($this->project->id, $this->name);
3737

38-
return Branch::fromArray($this->project, $data, $this->getClient());
38+
return Branch::fromArray($this->getClient(), $this->project, $data);
3939
}
4040

4141
public function protect()
4242
{
4343
$data = $this->api('repositories')->protectBranch($this->project->id, $this->name);
4444

45-
return Branch::fromArray($this->project, $data, $this->getClient());
45+
return Branch::fromArray($this->getClient(), $this->project, $data);
4646
}
4747

4848
public function unprotect()
4949
{
5050
$data = $this->api('repositories')->unprotectBranch($this->project->id, $this->name);
5151

52-
return Branch::fromArray($this->project, $data, $this->getClient());
52+
return Branch::fromArray($this->getClient(), $this->project, $data);
5353
}
54-
5554
}

lib/Gitlab/Model/Commit.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,26 @@ class Commit extends AbstractModel
2323
'project'
2424
);
2525

26-
public static function fromArray(Project $project, array $data, Client $client)
26+
public static function fromArray(Client $client, Project $project, array $data)
2727
{
2828
$commit = new Commit($project, $data['id']);
2929
$commit->setClient($client);
3030

3131
if (isset($data['parents'])) {
3232
$parents = array();
3333
foreach ($data['parents'] as $parent) {
34-
$parents[] = Commit::fromArray($project, $parent, $client);
34+
$parents[] = Commit::fromArray($client, $project, $parent);
3535
}
3636

3737
$data['parents'] = $parents;
3838
}
3939

4040
if (isset($data['author'])) {
41-
$data['author'] = User::fromArray($data['author'], $client);
41+
$data['author'] = User::fromArray($client, $data['author']);
4242
}
4343

4444
if (isset($data['committer'])) {
45-
$data['committer'] = User::fromArray($data['committer'], $client);
45+
$data['committer'] = User::fromArray($client, $data['committer']);
4646
}
4747

4848
return $commit->hydrate($data);

lib/Gitlab/Model/Group.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,27 @@ class Group extends AbstractModel
1414
'projects'
1515
);
1616

17-
public static function fromArray(array $data, Client $client)
17+
public static function fromArray(Client $client, array $data)
1818
{
1919
$group = new Group($data['id']);
2020
$group->setClient($client);
2121

2222
if (isset($data['projects'])) {
2323
$projects = array();
2424
foreach ($data['projects'] as $project) {
25-
$projects[] = Project::fromArray($project, $client);
25+
$projects[] = Project::fromArray($client, $project);
2626
}
2727
$data['projects'] = $projects;
2828
}
2929

3030
return $group->hydrate($data);
3131
}
3232

33-
public static function create($name, $path, Client $client)
33+
public static function create(Client $client, $name, $path)
3434
{
3535
$data = $client->api('groups')->create($name, $path);
3636

37-
return Group::fromArray($data, $client);
37+
return Group::fromArray($client, $data);
3838
}
3939

4040
public function __construct($id)
@@ -46,6 +46,6 @@ public function show()
4646
{
4747
$data = $this->api('groups')->show($this->id);
4848

49-
return Group::fromArray($data, $this->getClient());
49+
return Group::fromArray($this->getClient(), $data);
5050
}
5151
}

lib/Gitlab/Model/Hook.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ class Hook extends AbstractModel
1212
'created_at'
1313
);
1414

15-
public static function fromArray(array $data, Client $client)
15+
public static function fromArray(Client $client, array $data)
1616
{
1717
$hook = new Hook($data['id']);
1818
$hook->setClient($client);
1919

2020
return $hook->hydrate($data);
2121
}
2222

23-
public static function create($url, Client $client)
23+
public static function create(Client $client, $url)
2424
{
2525
$data = $client->api('system_hooks')->create($url);
2626

27-
return Hook::fromArray($data, $client);
27+
return Hook::fromArray($client, $data);
2828
}
2929

3030
public function __construct($id)

lib/Gitlab/Model/Issue.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@ class Issue extends AbstractModel
2222
'state'
2323
);
2424

25-
public static function fromArray(Project $project, array $data, Client $client)
25+
public static function fromArray(Client $client, Project $project, array $data)
2626
{
2727
$issue = new Issue($project, $data['id']);
2828
$issue->setClient($client);
2929

3030
if (isset($data['author'])) {
31-
$data['author'] = User::fromArray($data['author'], $client);
31+
$data['author'] = User::fromArray($client, $data['author']);
3232
}
3333

3434
if (isset($data['assignee'])) {
35-
$data['assignee'] = User::fromArray($data['assignee'], $client);
35+
$data['assignee'] = User::fromArray($client, $data['assignee']);
3636
}
3737

3838
return $issue->hydrate($data);
3939
}
4040

41-
public function __construct(Project $project, $id = null, Client $client)
41+
public function __construct(Project $project, $id = null)
4242
{
4343
$this->project = $project;
4444
$this->id = $id;
@@ -48,14 +48,14 @@ public function show()
4848
{
4949
$data = $this->api('issues')->show($this->project->id, $this->id);
5050

51-
return Issue::fromArray($this->project, $data, $this->getClient());
51+
return Issue::fromArray($this->getClient(), $this->project, $data);
5252
}
5353

5454
public function update(array $params)
5555
{
5656
$data = $this->api('issues')->update($this->project->id, $this->id, $params);
5757

58-
return Issue::fromArray($this->project, $data, $this->getClient());
58+
return Issue::fromArray($this->getClient(), $this->project, $data);
5959
}
6060

6161
public function close($comment = null)
@@ -82,7 +82,7 @@ public function addComment($body)
8282
'body' => $body
8383
));
8484

85-
return Note::fromArray($this, $data);
85+
return Note::fromArray($this->getClient(), $this, $data);
8686
}
8787

8888
}

lib/Gitlab/Model/Key.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Key extends AbstractModel
1313
'created_at'
1414
);
1515

16-
public static function fromArray(array $data, Client $client)
16+
public static function fromArray(Client $client, array $data)
1717
{
1818
$key = new Key();
1919
$key->setClient($client);

lib/Gitlab/Model/MergeRequest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ class MergeRequest extends AbstractModel
1919
'project'
2020
);
2121

22-
public static function fromArray(Project $project, array $data, Client $client)
22+
public static function fromArray(Client $client, Project $project, array $data)
2323
{
2424
$mr = new MergeRequest($project, $data['id']);
2525
$mr->setClient($client);
2626

2727
if (isset($data['author'])) {
28-
$data['author'] = User::fromArray($data['author'], $client);
28+
$data['author'] = User::fromArray($client, $data['author']);
2929
}
3030

3131
if (isset($data['assignee'])) {
32-
$data['assignee'] = User::fromArray($data['assignee'], $client);
32+
$data['assignee'] = User::fromArray($client, $data['assignee']);
3333
}
3434

3535
return $mr->hydrate($data);
@@ -45,14 +45,14 @@ public function show()
4545
{
4646
$data = $this->api('mr')->show($this->project->id, $this->id);
4747

48-
return MergeRequest::fromArray($this->project, $data, $this->getClient());
48+
return MergeRequest::fromArray($this->getClient(), $this->project, $data);
4949
}
5050

5151
public function update(array $params)
5252
{
5353
$data = $this->api('mr')->update($this->project->id, $this->id, $params);
5454

55-
return MergeRequest::fromArray($this->project, $data, $this->getClient());
55+
return MergeRequest::fromArray($this->getClient(), $this->project, $data);
5656
}
5757

5858
public function close()
@@ -69,7 +69,7 @@ public function addComment($note)
6969
{
7070
$data = $this->api('mr')->addComment($this->project->id, $this->id, $note);
7171

72-
return Note::fromArray($this, $data, $this->getClient());
72+
return Note::fromArray($this->getClient(), $this, $data);
7373
}
7474

7575
}

lib/Gitlab/Model/Milestone.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Milestone extends AbstractModel
1919
'created_at'
2020
);
2121

22-
public static function fromArray(Project $project, array $data, Client $client)
22+
public static function fromArray(Client $client, Project $project, array $data)
2323
{
2424
$milestone = new Milestone($project, $data['id']);
2525
$milestone->setClient($client);
@@ -37,14 +37,14 @@ public function show()
3737
{
3838
$data = $this->api('milestones')->show($this->project->id, $this->id);
3939

40-
return Milestone::fromArray($this->project, $data, $this->getClient());
40+
return Milestone::fromArray($this->getClient(), $this->project, $data);
4141
}
4242

4343
public function update(array $params)
4444
{
4545
$data = $this->api('milestones')->update($this->project->id, $this->id, $params);
4646

47-
return Milestone::fromArray($this->project, $data, $this->getClient());
47+
return Milestone::fromArray($this->getClient(), $this->project, $data);
4848
}
4949

5050
public function complete()

lib/Gitlab/Model/Note.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ class Note extends AbstractModel
1717
'attachment'
1818
);
1919

20-
public static function fromArray($type, array $data, Client $client)
20+
public static function fromArray(Client $client, $type, array $data)
2121
{
2222
$comment = new Note($type);
2323
$comment->setClient($client);
2424

2525
if (isset($data['author'])) {
26-
$data['author'] = User::fromArray($data['author'], $client);
26+
$data['author'] = User::fromArray($client, $data['author']);
2727
}
2828

2929
return $comment->hydrate($data);

0 commit comments

Comments
 (0)