Skip to content

Commit 6049b35

Browse files
authored
Merge pull request #223 from kbsali/cs-fixes
Cs fixes
2 parents fa7d5fb + a16b452 commit 6049b35

File tree

10 files changed

+126
-105
lines changed

10 files changed

+126
-105
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ php:
66
- 5.6
77
- 7.0
88
- 7.1
9+
- 7.2
10+
- 7.3
911

1012
before_script:
1113
- composer install --dev --prefer-source

composer.json

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
"homepage": "https://github.com/kbsali/php-redmine-api",
66
"keywords": ["redmine", "api"],
77
"license": "MIT",
8-
"authors": [
9-
{
10-
"name": "Kevin Saliou",
11-
"email": "kevin@saliou.name",
12-
"homepage": "http://kevin.saliou.name"
13-
}
14-
],
8+
"authors": [{
9+
"name": "Kevin Saliou",
10+
"email": "kevin@saliou.name",
11+
"homepage": "http://kevin.saliou.name"
12+
}],
1513
"require": {
16-
"php": "^5.4 || ^7.0",
14+
"php": "^5.4 || ^7.2",
1715
"ext-curl": "*",
1816
"ext-simplexml": "*",
1917
"ext-json": "*"

lib/Redmine/Api/AbstractApi.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
abstract class AbstractApi
1313
{
1414
/**
15-
* The client.
16-
*
1715
* @var Client
1816
*/
1917
protected $client;

lib/Redmine/Api/Issue.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,24 +170,24 @@ public function update($id, array $params)
170170

171171
/**
172172
* @param int $id
173-
* @param string $watcher_user_id
173+
* @param string $watcherUserId
174174
*
175175
* @return false|string
176176
*/
177-
public function addWatcher($id, $watcher_user_id)
177+
public function addWatcher($id, $watcherUserId)
178178
{
179-
return $this->post('/issues/'.$id.'/watchers.xml', '<user_id>'.$watcher_user_id.'</user_id>');
179+
return $this->post('/issues/'.$id.'/watchers.xml', '<user_id>'.$watcherUserId.'</user_id>');
180180
}
181181

182182
/**
183183
* @param int $id
184-
* @param string $watcher_user_id
184+
* @param string $watcherUserId
185185
*
186186
* @return false|\SimpleXMLElement|string
187187
*/
188-
public function removeWatcher($id, $watcher_user_id)
188+
public function removeWatcher($id, $watcherUserId)
189189
{
190-
return $this->delete('/issues/'.$id.'/watchers/'.$watcher_user_id.'.xml');
190+
return $this->delete('/issues/'.$id.'/watchers/'.$watcherUserId.'.xml');
191191
}
192192

193193
/**

lib/Redmine/Api/Membership.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ public function remove($id)
102102
}
103103

104104
/**
105-
* Delete membership of project by user id
105+
* Delete membership of project by user id.
106106
*
107107
* @see http://www.redmine.org/projects/redmine/wiki/Rest_Memberships#DELETE
108108
*
109-
* @param int $projectId id of project
110-
* @param int $userId id of user
111-
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
109+
* @param int $projectId id of project
110+
* @param int $userId id of user
111+
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
112112
*
113113
* @return false|\SimpleXMLElement|string
114114
*/
@@ -124,6 +124,7 @@ public function removeMember($projectId, $userId, array $params = [])
124124
}
125125
}
126126
}
127+
127128
return $removed;
128129
}
129130

lib/Redmine/Api/Project.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public function all(array $params = [])
3232
/**
3333
* Returns an array of projects with name/id pairs (or id/name if $reserse is false).
3434
*
35-
* @param bool $forceUpdate to force the update of the projects var
36-
* @param bool $reverse to return an array indexed by name rather than id
37-
* @param array $params to allow offset/limit (and more) to be passed
35+
* @param bool $forceUpdate to force the update of the projects var
36+
* @param bool $reverse to return an array indexed by name rather than id
37+
* @param array $params to allow offset/limit (and more) to be passed
3838
*
3939
* @return array list of projects (id => project name)
4040
*/
@@ -55,7 +55,7 @@ public function listing($forceUpdate = false, $reverse = true, array $params = [
5555
* Get a project id given its name.
5656
*
5757
* @param string $name
58-
* @param array $params to allow offset/limit (and more) to be passed
58+
* @param array $params to allow offset/limit (and more) to be passed
5959
*
6060
* @return int|bool
6161
*/
@@ -74,9 +74,9 @@ public function getIdByName($name, array $params = [])
7474
*
7575
* @see http://www.redmine.org/projects/redmine/wiki/Rest_Projects#Showing-a-project
7676
*
77-
* @param string $id the project id
78-
* @param array $params available parameters:
79-
* include: fetch associated data (optional). Possible values: trackers, issue_categories, enabled_modules (since 2.6.0)
77+
* @param string $id the project id
78+
* @param array $params available parameters:
79+
* include: fetch associated data (optional). Possible values: trackers, issue_categories, enabled_modules (since 2.6.0)
8080
*
8181
* @return array information about the project
8282
*/

lib/Redmine/Api/Search.php

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,29 @@
1-
<?php
2-
3-
namespace Redmine\Api;
4-
5-
/**
6-
* Searching
7-
*
8-
* @see http://www.redmine.org/projects/redmine/wiki/Rest_Search
9-
*
10-
*/
11-
class Search extends AbstractApi
12-
{
13-
private $results = [];
14-
15-
/**
16-
* Search.
17-
*
18-
* @see http://www.redmine.org/projects/redmine/wiki/Rest_Search
19-
*
20-
* @param string $query string to search
21-
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
22-
*
23-
* @return array list of results (projects, issues)
24-
*/
25-
public function search($query, array $params = [])
26-
{
27-
$params['q'] = $query;
28-
$this->results = $this->retrieveAll('/search.json', $params);
29-
30-
return $this->results;
31-
}
32-
}
1+
<?php
2+
3+
namespace Redmine\Api;
4+
5+
/**
6+
* @see http://www.redmine.org/projects/redmine/wiki/Rest_Search
7+
*/
8+
class Search extends AbstractApi
9+
{
10+
private $results = [];
11+
12+
/**
13+
* Search.
14+
*
15+
* @see http://www.redmine.org/projects/redmine/wiki/Rest_Search
16+
*
17+
* @param string $query string to search
18+
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
19+
*
20+
* @return array list of results (projects, issues)
21+
*/
22+
public function search($query, array $params = [])
23+
{
24+
$params['q'] = $query;
25+
$this->results = $this->retrieveAll('/search.json', $params);
26+
27+
return $this->results;
28+
}
29+
}

lib/Redmine/Client.php

Lines changed: 56 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@
88
* @author Kevin Saliou <kevin at saliou dot name>
99
* Website: http://github.com/kbsali/php-redmine-api
1010
*
11-
* @property Api\Attachment $attachment
12-
* @property Api\Group $group
13-
* @property Api\CustomField $custom_fields
14-
* @property Api\Issue $issue
15-
* @property Api\IssueCategory $issue_category
16-
* @property Api\IssuePriority $issue_priority
17-
* @property Api\IssueRelation $issue_relation
18-
* @property Api\IssueStatus $issue_status
19-
* @property Api\Membership $membership
20-
* @property Api\News $news
21-
* @property Api\Project $project
22-
* @property Api\Query $query
23-
* @property Api\Role $role
24-
* @property Api\TimeEntry $time_entry
11+
* @property Api\Attachment $attachment
12+
* @property Api\Group $group
13+
* @property Api\CustomField $custom_fields
14+
* @property Api\Issue $issue
15+
* @property Api\IssueCategory $issue_category
16+
* @property Api\IssuePriority $issue_priority
17+
* @property Api\IssueRelation $issue_relation
18+
* @property Api\IssueStatus $issue_status
19+
* @property Api\Membership $membership
20+
* @property Api\News $news
21+
* @property Api\Project $project
22+
* @property Api\Query $query
23+
* @property Api\Role $role
24+
* @property Api\TimeEntry $time_entry
2525
* @property Api\TimeEntryActivity $time_entry_activity
26-
* @property Api\Tracker $tracker
27-
* @property Api\User $user
28-
* @property Api\Version $version
29-
* @property Api\Wiki $wiki
26+
* @property Api\Tracker $tracker
27+
* @property Api\User $user
28+
* @property Api\Version $version
29+
* @property Api\Wiki $wiki
3030
*/
3131
class Client
3232
{
@@ -501,19 +501,19 @@ public function setCurlOption($option, $value)
501501
return $this;
502502
}
503503

504-
/**
505-
* Unset a cURL option.
506-
*
507-
* @param int $option The CURLOPT_XXX option to unset
508-
*
509-
* @return Client
510-
*/
511-
public function unsetCurlOption($option)
512-
{
513-
unset($this->curlOptions[$option]);
504+
/**
505+
* Unset a cURL option.
506+
*
507+
* @param int $option The CURLOPT_XXX option to unset
508+
*
509+
* @return Client
510+
*/
511+
public function unsetCurlOption($option)
512+
{
513+
unset($this->curlOptions[$option]);
514514

515-
return $this;
516-
}
515+
return $this;
516+
}
517517

518518
/**
519519
* Get all set cURL options.
@@ -573,17 +573,9 @@ public function prepareRequest($path, $method = 'GET', $data = '')
573573
switch ($method) {
574574
case 'POST':
575575
$this->setCurlOption(CURLOPT_POST, 1);
576-
577-
if ('/uploads.json' === $path || '/uploads.xml' === $path && isset($data) && is_file($data)) {
578-
$file = fopen($data, 'r');
579-
$size = filesize($data);
580-
$filedata = fread($file, $size);
581-
582-
$this->setCurlOption(CURLOPT_POSTFIELDS, $filedata);
583-
$this->setCurlOption(CURLOPT_INFILE, $file);
584-
$this->setCurlOption(CURLOPT_INFILESIZE, $size);
585-
}
586-
elseif (isset($data)) {
576+
if ($this->isUploadCall($path, $data)) {
577+
$this->prepareUploadRequest($data);
578+
} elseif (isset($data)) {
587579
$this->setCurlOption(CURLOPT_POSTFIELDS, $data);
588580
}
589581
break;
@@ -599,13 +591,33 @@ public function prepareRequest($path, $method = 'GET', $data = '')
599591
default: // GET
600592
break;
601593
}
602-
603594
// Set all cURL options to the current cURL resource
604595
curl_setopt_array($curl, $this->getCurlOptions());
605596

606597
return $curl;
607598
}
608599

600+
private function isUploadCall($path, $data)
601+
{
602+
return
603+
'/uploads.json' === $path ||
604+
'/uploads.xml' === $path &&
605+
isset($data) &&
606+
is_file($data)
607+
;
608+
}
609+
610+
private function prepareUploadRequest($data)
611+
{
612+
$file = fopen($data, 'r');
613+
$size = filesize($data);
614+
$filedata = fread($file, $size);
615+
616+
$this->setCurlOption(CURLOPT_POSTFIELDS, $filedata);
617+
$this->setCurlOption(CURLOPT_INFILE, $file);
618+
$this->setCurlOption(CURLOPT_INFILESIZE, $size);
619+
}
620+
609621
private function setHttpHeader($path)
610622
{
611623
// Additional request headers
@@ -623,12 +635,12 @@ private function setHttpHeader($path)
623635
$httpHeader[] = 'Content-Type: text/xml';
624636
}
625637

626-
if ($this->customHost !== null) {
638+
if (null !== $this->customHost) {
627639
$httpHeader[] = 'Host: '.$this->customHost;
628640
}
629641

630642
// Redmine specific headers
631-
if ($this->impersonateUser !== null) {
643+
if (null !== $this->impersonateUser) {
632644
$httpHeader[] = 'X-Redmine-Switch-User: '.$this->impersonateUser;
633645
}
634646
if (null === $this->pass) {

lib/autoload.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
if (file_exists($composerPath)) {
77
include $composerPath;
8+
89
return;
910
}
1011

@@ -17,14 +18,14 @@
1718
spl_autoload_register(function ($class) {
1819
// project-specific namespace prefix and base directory with trailing /
1920
$namespaceMap = [
20-
'Redmine\\' => __DIR__.'/Redmine/',
21+
'Redmine\\' => __DIR__.'/Redmine/',
2122
'Redmine\\Tests\\' => __DIR__.'/../tests/',
2223
];
2324

2425
foreach ($namespaceMap as $prefix => $baseDir) {
2526
// does the class use the namespace prefix?
2627
$len = strlen($prefix);
27-
if (strncmp($prefix, $class, $len) !== 0) {
28+
if (0 !== strncmp($prefix, $class, $len)) {
2829
// no, move to the next registered autoloader
2930
continue;
3031
}

0 commit comments

Comments
 (0)