Skip to content

Commit efca42e

Browse files
author
Matt Humphrey
committed
CS etc in Model dir. #61
1 parent 87c696a commit efca42e

23 files changed

+898
-135
lines changed

lib/Gitlab/Api/Projects.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,31 +205,31 @@ public function addHook($project_id, $url, $push_events = true, $issues_events =
205205
* @param int $project_id
206206
* @param int $hook_id
207207
* @param string $url
208-
* @param null $push_events
209-
* @param null $issues_events
210-
* @param null $merge_requests_events
211-
* @param null $tag_push_events
208+
* @param bool $push_events
209+
* @param bool $issues_events
210+
* @param bool $merge_requests_events
211+
* @param bool $tag_push_events
212212
* @return mixed
213213
*/
214-
public function updateHook($project_id, $hook_id, $url, $push_events = null, $issues_events = null, $merge_requests_events = null, $tag_push_events = null)
214+
public function updateHook($project_id, $hook_id, $url, $push_events = true, $issues_events = false, $merge_requests_events = false, $tag_push_events = false)
215215
{
216216
$params = array(
217217
'url' => $url
218218
);
219219

220-
if (null !== $push_events) {
220+
if ($push_events) {
221221
$params['push_events'] = $push_events;
222222
}
223223

224-
if (null !== $issues_events) {
224+
if ($issues_events) {
225225
$params['issues_events'] = $issues_events;
226226
}
227227

228-
if (null !== $merge_requests_events) {
228+
if ($merge_requests_events) {
229229
$params['merge_requests_events'] = $merge_requests_events;
230230
}
231231

232-
if (null !== $tag_push_events) {
232+
if ($tag_push_events) {
233233
$params['tag_push_events'] = $tag_push_events;
234234
}
235235

lib/Gitlab/Api/Snippets.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function update($project_id, $snippet_id, array $params)
5353
/**
5454
* @param int $project_id
5555
* @param int $snippet_id
56-
* @return mixed
56+
* @return string
5757
*/
5858
public function content($project_id, $snippet_id)
5959
{

lib/Gitlab/Model/AbstractModel.php

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,65 @@
1-
<?php
2-
3-
namespace Gitlab\Model;
1+
<?php namespace Gitlab\Model;
42

53
use Gitlab\Client;
64
use Gitlab\Exception\RuntimeException;
5+
use Gitlab\Api\AbstractApi;
76

87
abstract class AbstractModel
98
{
10-
protected static $_properties;
11-
12-
protected $_data = array();
13-
protected $_client = null;
14-
9+
/**
10+
* @var array
11+
*/
12+
protected static $properties;
13+
14+
/**
15+
* @var array
16+
*/
17+
protected $data = array();
18+
19+
/**
20+
* @var Client
21+
*/
22+
protected $client;
23+
24+
/**
25+
* @return Client
26+
*/
1527
public function getClient()
1628
{
17-
return $this->_client;
29+
return $this->client;
1830
}
1931

32+
/**
33+
* @param Client $client
34+
* @return $this
35+
*/
2036
public function setClient(Client $client = null)
2137
{
2238
if (null !== $client) {
23-
$this->_client = $client;
39+
$this->client = $client;
2440
}
2541

2642
return $this;
2743
}
2844

45+
/**
46+
* @param string $api
47+
* @return AbstractApi
48+
*/
2949
public function api($api)
3050
{
3151
return $this->getClient()->api($api);
3252
}
3353

54+
/**
55+
* @param array $data
56+
* @return $this
57+
*/
3458
public function hydrate(array $data = array())
3559
{
3660
if (!empty($data)) {
3761
foreach ($data as $k => $v) {
38-
if (in_array($k, static::$_properties)) {
62+
if (in_array($k, static::$properties)) {
3963
$this->$k = $v;
4064
}
4165
}
@@ -44,31 +68,38 @@ public function hydrate(array $data = array())
4468
return $this;
4569
}
4670

71+
/**
72+
* @param string $property
73+
* @param mixed $value
74+
*/
4775
public function __set($property, $value)
4876
{
49-
if (!in_array($property, static::$_properties)) {
77+
if (!in_array($property, static::$properties)) {
5078
throw new RuntimeException(sprintf(
5179
'Property "%s" does not exist for %s object', $property, get_called_class()
5280
));
5381
}
5482

55-
$this->_data[$property] = $value;
83+
$this->data[$property] = $value;
5684
}
5785

86+
/**
87+
* @param string $property
88+
* @return mixed
89+
*/
5890
public function __get($property)
5991
{
60-
if (!in_array($property, static::$_properties)) {
92+
if (!in_array($property, static::$properties)) {
6193
throw new RuntimeException(sprintf(
6294
'Property "%s" does not exist for %s object',
6395
$property, get_called_class()
6496
));
6597
}
6698

67-
if (isset($this->_data[$property])) {
68-
return $this->_data[$property];
99+
if (isset($this->data[$property])) {
100+
return $this->data[$property];
69101
}
70102

71103
return null;
72104
}
73-
74105
}

lib/Gitlab/Model/Branch.php

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
1-
<?php
2-
3-
namespace Gitlab\Model;
1+
<?php namespace Gitlab\Model;
42

53
use Gitlab\Client;
64
use Gitlab\Api\AbstractApi as Api;
75

86
class Branch extends AbstractModel
97
{
10-
protected static $_properties = array(
8+
/**
9+
* @var array
10+
*/
11+
protected static $properties = array(
1112
'name',
1213
'commit',
1314
'project',
1415
'protected'
1516
);
1617

18+
/**
19+
* @param Client $client
20+
* @param Project $project
21+
* @param array $data
22+
* @return Branch
23+
*/
1724
public static function fromArray(Client $client, Project $project, array $data)
1825
{
1926
$branch = new static($project, $data['name'], $client);
@@ -25,6 +32,11 @@ public static function fromArray(Client $client, Project $project, array $data)
2532
return $branch->hydrate($data);
2633
}
2734

35+
/**
36+
* @param Project $project
37+
* @param string $name
38+
* @param Client $client
39+
*/
2840
public function __construct(Project $project, $name = null, Client $client = null)
2941
{
3042
$this->setClient($client);
@@ -33,53 +45,87 @@ public function __construct(Project $project, $name = null, Client $client = nul
3345
$this->name = $name;
3446
}
3547

48+
/**
49+
* @return Branch
50+
*/
3651
public function show()
3752
{
3853
$data = $this->api('repositories')->branch($this->project->id, $this->name);
3954

40-
return Branch::fromArray($this->getClient(), $this->project, $data);
55+
return static::fromArray($this->getClient(), $this->project, $data);
4156
}
4257

58+
/**
59+
* @return Branch
60+
*/
4361
public function protect()
4462
{
4563
$data = $this->api('repositories')->protectBranch($this->project->id, $this->name);
4664

47-
return Branch::fromArray($this->getClient(), $this->project, $data);
65+
return static::fromArray($this->getClient(), $this->project, $data);
4866
}
4967

68+
/**
69+
* @return Branch
70+
*/
5071
public function unprotect()
5172
{
5273
$data = $this->api('repositories')->unprotectBranch($this->project->id, $this->name);
5374

54-
return Branch::fromArray($this->getClient(), $this->project, $data);
75+
return static::fromArray($this->getClient(), $this->project, $data);
5576
}
5677

78+
/**
79+
* @return bool
80+
*/
5781
public function delete()
5882
{
5983
$this->api('repositories')->deleteBranch($this->project->id, $this->name);
6084

6185
return true;
6286
}
6387

88+
/**
89+
* @param int $page
90+
* @param int $per_page
91+
* @return Commit[]
92+
*/
6493
public function commits($page = 1, $per_page = Api::PER_PAGE)
6594
{
6695
return $this->project->commits($page, $per_page, $this->name);
6796
}
6897

98+
/**
99+
* @param string $file_path
100+
* @param string $content
101+
* @param string $commit_message
102+
* @return File
103+
*/
69104
public function createFile($file_path, $content, $commit_message)
70105
{
71106
$data = $this->api('repositories')->createFile($this->project->id, $file_path, $content, $this->name, $commit_message);
72107

73108
return File::fromArray($this->getClient(), $this, $data);
74109
}
75110

111+
/**
112+
* @param string $file_path
113+
* @param string $content
114+
* @param string $commit_message
115+
* @return File
116+
*/
76117
public function updateFile($file_path, $content, $commit_message)
77118
{
78119
$data = $this->api('repositories')->updateFile($this->project->id, $file_path, $content, $this->name, $commit_message);
79120

80121
return File::fromArray($this->getClient(), $this, $data);
81122
}
82123

124+
/**
125+
* @param string $file_path
126+
* @param string $commit_message
127+
* @return bool
128+
*/
83129
public function deleteFile($file_path, $commit_message)
84130
{
85131
$this->api('repositories')->deleteFile($this->project->id, $file_path, $this->name, $commit_message);

lib/Gitlab/Model/Commit.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
<?php
2-
3-
namespace Gitlab\Model;
1+
<?php namespace Gitlab\Model;
42

53
use Gitlab\Client;
64

75
class Commit extends AbstractModel
86
{
9-
protected static $_properties = array(
7+
/**
8+
* @var array
9+
*/
10+
protected static $properties = array(
1011
'id',
1112
'short_id',
1213
'parents',
@@ -23,14 +24,20 @@ class Commit extends AbstractModel
2324
'project'
2425
);
2526

27+
/**
28+
* @param Client $client
29+
* @param Project $project
30+
* @param array $data
31+
* @return Commit
32+
*/
2633
public static function fromArray(Client $client, Project $project, array $data)
2734
{
2835
$commit = new static($project, $data['id'], $client);
2936

3037
if (isset($data['parents'])) {
3138
$parents = array();
3239
foreach ($data['parents'] as $parent) {
33-
$parents[] = Commit::fromArray($client, $project, $parent);
40+
$parents[] = static::fromArray($client, $project, $parent);
3441
}
3542

3643
$data['parents'] = $parents;
@@ -47,12 +54,16 @@ public static function fromArray(Client $client, Project $project, array $data)
4754
return $commit->hydrate($data);
4855
}
4956

57+
/**
58+
* @param Project $project
59+
* @param int $id
60+
* @param Client $client
61+
*/
5062
public function __construct(Project $project, $id = null, Client $client = null)
5163
{
5264
$this->setClient($client);
5365

5466
$this->project = $project;
5567
$this->id = $id;
5668
}
57-
5869
}

0 commit comments

Comments
 (0)