Skip to content

Commit f1c3bb6

Browse files
committed
use OptionsResolver in Milestones api
1 parent 14f294c commit f1c3bb6

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

UPGRADE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ See [documentation](doc/customize.md) to know how to customize the client timeou
4343
* The `all` method now take a single argument which is an associative array of query string parameters.
4444
* The `getNotes` method now take only two arguments, the project id and the merge request iid.
4545

46+
## `Gitlab\Api\Milestones` changes
47+
48+
* The `all` method second and subsequent arguments have been replaced by a single associative array of query string parameters.
49+
4650
## `Gitlab\Api\Projects` changes
4751

4852
* The `keys`, `key`, `addKey`, `removeKey`, `disableKey` and `enableKey` methods have been removed.

lib/Gitlab/Api/Milestones.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,30 @@ class Milestones extends AbstractApi
44
{
55
/**
66
* @param int $project_id
7-
* @param int $page
8-
* @param int $per_page
7+
* @param array $parameters (
8+
*
9+
* @var int[] $iids Return only the milestones having the given iids.
10+
* @var string $state Return only active or closed milestones.
11+
* @var string $search Return only milestones with a title or description matching the provided string.
12+
* )
13+
*
914
* @return mixed
1015
*/
11-
public function all($project_id, $page = 1, $per_page = self::PER_PAGE)
16+
public function all($project_id, array $parameters = [])
1217
{
13-
return $this->get($this->getProjectPath($project_id, 'milestones'), array(
14-
'page' => $page,
15-
'per_page' => $per_page
16-
));
18+
$resolver = $this->createOptionsResolver();
19+
$resolver->setDefined('iids')
20+
->setAllowedTypes('iids', 'array')
21+
->setAllowedValues('iids', function (array $value) {
22+
return count($value) == count(array_filter($value, 'is_int'));
23+
})
24+
;
25+
$resolver->setDefined('state')
26+
->setAllowedValues('state', ['active', 'closed'])
27+
;
28+
$resolver->setDefined('search');
29+
30+
return $this->get($this->getProjectPath($project_id, 'milestones'), $resolver->resolve($parameters));
1731
}
1832

1933
/**

0 commit comments

Comments
 (0)