Skip to content

Commit 4c914be

Browse files
committed
Replace all calls of http_build_query with PathSerializer
1 parent 68a515e commit 4c914be

File tree

7 files changed

+40
-16
lines changed

7 files changed

+40
-16
lines changed

src/Redmine/Api/Attachment.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Redmine\Api;
44

5+
use Redmine\Serializer\PathSerializer;
6+
57
/**
68
* Attachment details.
79
*
@@ -51,7 +53,10 @@ public function download($id)
5153
*/
5254
public function upload($attachment, $params = [])
5355
{
54-
return $this->post('/uploads.json?'.http_build_query($params), $attachment);
56+
return $this->post(
57+
PathSerializer::create('/uploads.json', $params)->getPath(),
58+
$attachment
59+
);
5560
}
5661

5762
/**

src/Redmine/Api/Group.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Exception;
66
use Redmine\Exception\MissingParameterException;
7+
use Redmine\Serializer\PathSerializer;
78

89
/**
910
* Handling of groups.
@@ -110,7 +111,9 @@ public function update($id, array $params = [])
110111
*/
111112
public function show($id, array $params = [])
112113
{
113-
return $this->get('/groups/'.urlencode($id).'.json?'.http_build_query($params));
114+
return $this->get(
115+
PathSerializer::create('/groups/'.urlencode($id).'.json', $params)->getPath()
116+
);
114117
}
115118

116119
/**

src/Redmine/Api/Issue.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Redmine\Api;
44

5+
use Redmine\Serializer\PathSerializer;
6+
57
/**
68
* Listing issues, searching, editing and closing your projects issues.
79
*
@@ -59,7 +61,9 @@ public function show($id, array $params = [])
5961
$params['include'] = implode(',', $params['include']);
6062
}
6163

62-
return $this->get('/issues/'.urlencode($id).'.json?'.http_build_query($params));
64+
return $this->get(
65+
PathSerializer::create('/issues/'.urlencode($id).'.json', $params)->getPath()
66+
);
6367
}
6468

6569
/**

src/Redmine/Api/Project.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Redmine\Api;
44

55
use Redmine\Exception\MissingParameterException;
6+
use Redmine\Serializer\PathSerializer;
67

78
/**
89
* Listing projects, creating, editing.
@@ -90,7 +91,9 @@ public function show($id, array $params = [])
9091
$params['include'] = 'trackers,issue_categories,attachments,relations';
9192
}
9293

93-
return $this->get('/projects/'.urlencode($id).'.json?'.http_build_query($params));
94+
return $this->get(
95+
PathSerializer::create('/projects/'.urlencode($id).'.json', $params)->getPath()
96+
);
9497
}
9598

9699
/**

src/Redmine/Api/User.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Redmine\Api;
44

55
use Redmine\Exception\MissingParameterException;
6+
use Redmine\Serializer\PathSerializer;
67

78
/**
89
* Listing users, creating, editing.
@@ -117,11 +118,9 @@ public function show($id, array $params = [])
117118
);
118119
$params['include'] = implode(',', $params['include']);
119120

120-
return $this->get(sprintf(
121-
'/users/%s.json?%s',
122-
urlencode($id),
123-
http_build_query($params)
124-
));
121+
return $this->get(
122+
PathSerializer::create('/users/'.urlencode($id).'.json', $params)->getPath()
123+
);
125124
}
126125

127126
/**

src/Redmine/Api/Wiki.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Redmine\Api;
44

5+
use Redmine\Serializer\PathSerializer;
6+
57
/**
68
* Listing Wiki pages.
79
*
@@ -44,11 +46,19 @@ public function all($project, array $params = [])
4446
*/
4547
public function show($project, $page, $version = null)
4648
{
47-
$path = null === $version
48-
? '/projects/'.$project.'/wiki/'.$page.'.json?include=attachments'
49-
: '/projects/'.$project.'/wiki/'.$page.'/'.$version.'.json?include=attachments';
49+
$params = [
50+
'include' => 'attachments',
51+
];
52+
53+
if ($version === null) {
54+
$path = '/projects/'.$project.'/wiki/'.$page.'.json';
55+
} else {
56+
$path = '/projects/'.$project.'/wiki/'.$page.'/'.$version.'.json';
57+
}
5058

51-
return $this->get($path);
59+
return $this->get(
60+
PathSerializer::create($path, $params)->getPath()
61+
);
5262
}
5363

5464
/**

tests/Integration/UrlTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function testAttachment()
2828
$res = $api->upload('asdf');
2929
$res = json_decode($res, true);
3030

31-
$this->assertEquals('/uploads.json?', $res['path']);
31+
$this->assertEquals('/uploads.json', $res['path']);
3232
$this->assertEquals('POST', $res['method']);
3333
}
3434

@@ -59,7 +59,7 @@ public function testGroup()
5959

6060
$res = $api->show(1);
6161

62-
$this->assertEquals('/groups/1.json?', $res['path']);
62+
$this->assertEquals('/groups/1.json', $res['path']);
6363
$this->assertEquals('GET', $res['method']);
6464

6565
$res = $api->remove(1);
@@ -112,7 +112,7 @@ public function testIssue()
112112

113113
$res = $api->show(1);
114114

115-
$this->assertEquals('/issues/1.json?', $res['path']);
115+
$this->assertEquals('/issues/1.json', $res['path']);
116116
$this->assertEquals('GET', $res['method']);
117117

118118
$res = $api->remove(1);

0 commit comments

Comments
 (0)