Skip to content

Commit

Permalink
Fix CS with php-cs-fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
Art4 committed Mar 1, 2022
1 parent ad5c0b9 commit 14720c8
Show file tree
Hide file tree
Showing 22 changed files with 35 additions and 61 deletions.
13 changes: 5 additions & 8 deletions src/Redmine/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Redmine\Api;

use JsonException;
use Redmine\Api;
use Redmine\Client\Client;
use Redmine\Exception\SerializerException;
Expand Down Expand Up @@ -165,7 +164,7 @@ protected function sanitizeParams(array $defaults, array $params)
* Retrieves all the elements of a given endpoint (even if the
* total number of elements is greater than 100).
*
* @deprecated the `retrieveAll()` method is deprecated, use `retrieveData()` instead.
* @deprecated the `retrieveAll()` method is deprecated, use `retrieveData()` instead
*
* @param string $endpoint API end point
* @param array $params optional parameters to be passed to the api (offset, limit, ...)
Expand Down Expand Up @@ -297,7 +296,7 @@ protected function attachCustomFieldXML(SimpleXMLElement $xml, array $fields)
}

/**
* returns the last response body as array
* returns the last response body as array.
*
* @throws SerializerException if response body could not be converted into array
*/
Expand All @@ -310,14 +309,12 @@ private function getLastResponseBodyAsArray(): array
// parse XML
if (0 === strpos($contentType, 'application/xml')) {
$returnData = XmlSerializer::createFromString($body)->getNormalized();
} else if (0 === strpos($contentType, 'application/json')) {
} elseif (0 === strpos($contentType, 'application/json')) {
$returnData = JsonSerializer::createFromString($body)->getNormalized();
}

if (! is_array($returnData)) {
throw new SerializerException(
'Could not convert response body into array: ' . $body
);
if (!is_array($returnData)) {
throw new SerializerException('Could not convert response body into array: '.$body);
}

return $returnData;
Expand Down
2 changes: 1 addition & 1 deletion src/Redmine/Api/Issue.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function update($id, array $params)
$sanitizedParams = $this->sanitizeParams($defaults, $params);

// Allow assigned_to_id to be `` (empty string) to unassign a user from an issue
if (array_key_exists('assigned_to_id', $params) && $params['assigned_to_id'] === '') {
if (array_key_exists('assigned_to_id', $params) && '' === $params['assigned_to_id']) {
$sanitizedParams['assigned_to_id'] = '';
}

Expand Down
2 changes: 1 addition & 1 deletion src/Redmine/Api/Wiki.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function show($project, $page, $version = null)
'include' => 'attachments',
];

if ($version === null) {
if (null === $version) {
$path = '/projects/'.$project.'/wiki/'.$page.'.json';
} else {
$path = '/projects/'.$project.'/wiki/'.$page.'/'.$version.'.json';
Expand Down
2 changes: 1 addition & 1 deletion src/Redmine/Exception/SerializerException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Redmine\Exception;

use RuntimeException;
use Redmine\Exception as RedmineException;
use RuntimeException;

class SerializerException extends RuntimeException implements RedmineException
{
Expand Down
10 changes: 3 additions & 7 deletions src/Redmine/Serializer/JsonSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Redmine\Exception\SerializerException;

/**
* JsonSerializer
* JsonSerializer.
*
* @internal
*/
Expand All @@ -25,7 +25,7 @@ public static function createFromString(string $data): self

private string $encoded;

/** @var mixed $normalized */
/** @var mixed */
private $normalized;

private function __construct()
Expand Down Expand Up @@ -53,11 +53,7 @@ private function decode(string $encoded): void
\JSON_THROW_ON_ERROR
);
} catch (JsonException $e) {
throw new SerializerException(
'Catched error "' . $e->getMessage() . '" while decoding JSON: ' . $encoded,
$e->getCode(),
$e
);
throw new SerializerException('Catched error "'.$e->getMessage().'" while decoding JSON: '.$encoded, $e->getCode(), $e);
}
}
}
8 changes: 4 additions & 4 deletions src/Redmine/Serializer/PathSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Redmine\Serializer;

/**
* PathSerializer
* PathSerializer.
*
* @internal
*/
Expand Down Expand Up @@ -31,13 +31,13 @@ public function getPath(): string
{
$queryString = '';

if (! empty($this->queryParams)) {
$queryString = '?' . \http_build_query($this->queryParams);
if (!empty($this->queryParams)) {
$queryString = '?'.\http_build_query($this->queryParams);

// @see #154: replace every encoded array (`foo[0]=`, `foo[1]=`, etc with `foo[]=`)
$queryString = preg_replace('/%5B[0-9]+%5D/simU', '%5B%5D', $queryString);
}

return $this->path . $queryString;
return $this->path.$queryString;
}
}
16 changes: 4 additions & 12 deletions src/Redmine/Serializer/XmlSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use SimpleXMLElement;

/**
* XmlSerializer
* XmlSerializer.
*
* @internal
*/
Expand All @@ -26,7 +26,7 @@ public static function createFromString(string $data): self

private string $encoded;

/** @var mixed $normalized */
/** @var mixed */
private $normalized;

private SimpleXMLElement $deserialized;
Expand All @@ -51,11 +51,7 @@ private function deserialize(string $encoded): void
try {
$this->deserialized = new SimpleXMLElement($encoded);
} catch (Exception $e) {
throw new SerializerException(
'Catched error "' . $e->getMessage() . '" while decoding XML: ' . $encoded,
$e->getCode(),
$e
);
throw new SerializerException('Catched error "'.$e->getMessage().'" while decoding XML: '.$encoded, $e->getCode(), $e);
}

$this->normalize($this->deserialized);
Expand All @@ -66,11 +62,7 @@ private function normalize(SimpleXMLElement $deserialized): void
try {
$serialized = json_encode($deserialized, \JSON_THROW_ON_ERROR);
} catch (JsonException $e) {
throw new SerializerException(
'Catched error "' . $e->getMessage() . '" while encoding SimpleXMLElement',
$e->getCode(),
$e
);
throw new SerializerException('Catched error "'.$e->getMessage().'" while encoding SimpleXMLElement', $e->getCode(), $e);
}

$this->normalized = JsonSerializer::createFromString($serialized)->getNormalized();
Expand Down
1 change: 0 additions & 1 deletion tests/Integration/IssueCategoryXmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Redmine\Tests\Integration;

use DOMDocument;
use Exception;
use PHPUnit\Framework\TestCase;
use Redmine\Exception\MissingParameterException;
use Redmine\Tests\Fixtures\MockClient;
Expand Down
1 change: 0 additions & 1 deletion tests/Integration/MembershipXmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Redmine\Tests\Integration;

use DOMDocument;
use Exception;
use PHPUnit\Framework\TestCase;
use Redmine\Exception\MissingParameterException;
use Redmine\Tests\Fixtures\MockClient;
Expand Down
1 change: 0 additions & 1 deletion tests/Integration/ProjectXmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Redmine\Tests\Integration;

use DOMDocument;
use Exception;
use PHPUnit\Framework\TestCase;
use Redmine\Exception\MissingParameterException;
use Redmine\Tests\Fixtures\MockClient;
Expand Down
14 changes: 7 additions & 7 deletions tests/Integration/UrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,13 @@ public function testTimeEntry()

// Test for #154: fix http_build_query encoding array values with numeric keys
$res = $api->all([
"f" => ["spent_on"],
"op" => ["spent_on" => "><"],
"v" => [
"spent_on" => [
"2016-01-18",
"2016-01-22"
]
'f' => ['spent_on'],
'op' => ['spent_on' => '><'],
'v' => [
'spent_on' => [
'2016-01-18',
'2016-01-22',
],
],
]);
$this->assertEquals('/time_entries.json?limit=25&offset=0&f%5B%5D=spent_on&op%5Bspent_on%5D=%3E%3C&v%5Bspent_on%5D%5B%5D=2016-01-18&v%5Bspent_on%5D%5B%5D=2016-01-22', $res['path']);
Expand Down
1 change: 0 additions & 1 deletion tests/Integration/UserXmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Redmine\Tests\Integration;

use DOMDocument;
use Exception;
use PHPUnit\Framework\TestCase;
use Redmine\Exception\MissingParameterException;
use Redmine\Tests\Fixtures\MockClient;
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Api/AbstractApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function getIsNotNullReturnsCorrectBooleanData()
[true, [0]],
[true, ['0']],
[true, ['']],
[true, new \stdClass],
[true, new \stdClass()],
];
}

Expand Down
1 change: 0 additions & 1 deletion tests/Unit/Api/GroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Redmine\Tests\Unit\Api;

use Exception;
use PHPUnit\Framework\TestCase;
use Redmine\Api\Group;
use Redmine\Client\Client;
Expand Down
1 change: 0 additions & 1 deletion tests/Unit/Api/IssueCategoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Redmine\Tests\Unit\Api;

use Exception;
use PHPUnit\Framework\TestCase;
use Redmine\Api\IssueCategory;
use Redmine\Client\Client;
Expand Down
9 changes: 4 additions & 5 deletions tests/Unit/Api/IssueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function getPriorityConstantsData()
[5, Issue::PRIO_IMMEDIATE],
];
}

/**
* Test the constants.
*
Expand Down Expand Up @@ -917,7 +918,7 @@ public function testBuildXmlWithWatcherAndUploadAndCustomFieldAndStandard()
}

/**
* Test assign an user to an issue
* Test assign an user to an issue.
*
* @test
*/
Expand All @@ -938,7 +939,6 @@ public function testAssignUserToAnIssue()
$this->stringStartsWith('<?xml version="1.0"?>'."\n".'<issue>'),
$this->stringContains('<assigned_to_id>5</assigned_to_id>'),
$this->stringEndsWith('</issue>'."\n"),

)
);

Expand All @@ -950,15 +950,15 @@ public function testAssignUserToAnIssue()
}

/**
* Test unassign an user from an issue
* Test unassign an user from an issue.
*
* @test
*/
public function testUnassignUserFromAnIssue()
{
// Test values
$parameters = [
'assigned_to_id' => "",
'assigned_to_id' => '',
];

// Create the used mock objects
Expand All @@ -971,7 +971,6 @@ public function testUnassignUserFromAnIssue()
$this->stringStartsWith('<?xml version="1.0"?>'."\n".'<issue>'),
$this->stringContains('<assigned_to_id></assigned_to_id>'),
$this->stringEndsWith('</issue>'."\n"),

)
);

Expand Down
1 change: 0 additions & 1 deletion tests/Unit/Api/ProjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Redmine\Tests\Unit\Api;

use Exception;
use PHPUnit\Framework\TestCase;
use Redmine\Api\Project;
use Redmine\Client\Client;
Expand Down
1 change: 0 additions & 1 deletion tests/Unit/Api/TimeEntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Redmine\Tests\Unit\Api;

use Exception;
use PHPUnit\Framework\TestCase;
use Redmine\Api\TimeEntry;
use Redmine\Client\Client;
Expand Down
1 change: 0 additions & 1 deletion tests/Unit/Api/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Redmine\Tests\Unit\Api;

use Exception;
use PHPUnit\Framework\TestCase;
use Redmine\Api\User;
use Redmine\Client\Client;
Expand Down
1 change: 0 additions & 1 deletion tests/Unit/Api/VersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Redmine\Tests\Unit\Api;

use Exception;
use PHPUnit\Framework\TestCase;
use Redmine\Api\Version;
use Redmine\Client\Client;
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Serializer/JsonSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function getNormalizedAndEncodedData()
],
[
'["foo","bar"]',
['foo','bar'],
['foo', 'bar'],
],
[
'{"foo":"bar"}',
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Serializer/PathSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public function getPathData()
[
'/time_entries.json',
[
'f' => ['spent_on'],
'f' => ['spent_on'],
'op' => ['spent_on' => '><'],
'v' => [
'v' => [
'spent_on' => [
'2016-01-18',
'2016-01-22'
'2016-01-22',
],
],
],
Expand Down

0 comments on commit 14720c8

Please sign in to comment.