Skip to content

Commit

Permalink
Fix coding standards (PSR-12)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Dargham committed Feb 4, 2022
1 parent 08c8c7a commit b5acb1a
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 17 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"php-http/mock-client": "^1.3",
"php-http/guzzle7-adapter": "^1.0.0",
"guzzlehttp/psr7": "^2.1.0",
"guzzlehttp/guzzle": "^7.4.1"
"guzzlehttp/guzzle": "^7.4.1",
"squizlabs/php_codesniffer": "^3.6"
},
"autoload": {
"psr-4": {
Expand Down
29 changes: 29 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0"?>
<ruleset name="globalis/chargebee-php-sdk">
<description>globalis/chargebee-php-sdk coding standards</description>

<!-- Scan all files in directory -->
<file>.</file>

<!-- Scan only PHP files -->
<arg name="extensions" value="php"/>

<!-- Ignore dependencies -->
<exclude-pattern>/vendor/</exclude-pattern>

<!-- Show colors in console -->
<arg value="-colors"/>

<!-- Show sniff codes in all reports -->
<arg value="ns"/>

<!-- Use PSR-12 as a base -->
<rule ref="PSR12"/>

<!-- Custom rule: disallow long `array()` syntax, use short `[]` syntax instead -->
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>

<rule ref="PSR1.Methods.CamelCapsMethodName">
<exclude-pattern>./tests/*</exclude-pattern>
</rule>
</ruleset>
4 changes: 2 additions & 2 deletions src/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ protected function post($path, array $parameters = [], $requestHeaders = [])
*/
protected function url(string $endpoint, ...$replacements): string
{
return $this->client->baseUrl.vsprintf($endpoint, $replacements);
return $this->client->baseUrl . vsprintf($endpoint, $replacements);
}

/**
Expand All @@ -137,7 +137,7 @@ protected function url(string $endpoint, ...$replacements): string
private function preparePath($path, array $parameters = []): string
{
if (count($parameters) > 0) {
$path .= '?'.QueryStringBuilder::build($parameters);
$path .= '?' . QueryStringBuilder::build($parameters);
}

return $path;
Expand Down
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function __construct(string $site = '', string $key = '', Builder $httpCl

public static function eventDispatcher()
{
if(is_null(self::$eventDispatcher)) {
if (is_null(self::$eventDispatcher)) {
self::$eventDispatcher = new EventDispatcher();
}

Expand Down
1 change: 0 additions & 1 deletion src/Events/EventChargebeeApiResponseError.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

class EventChargebeeApiResponseError extends EventChargebeeApiResponse
{

}
1 change: 0 additions & 1 deletion src/Events/EventChargebeeApiResponseSuccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

class EventChargebeeApiResponseSuccess extends EventChargebeeApiResponse
{

}
4 changes: 2 additions & 2 deletions src/HttpClient/Message/QueryStringBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ public static function build($query)
private static function encode($query, $prefix)
{
if (!is_array($query)) {
return static::rawurlencode($prefix).'='.static::rawurlencode($query);
return static::rawurlencode($prefix) . '=' . static::rawurlencode($query);
}

$isIndexedArray = static::isIndexedArray($query);

return implode('&', array_map(function ($value, $key) use ($prefix, $isIndexedArray) {
$prefix = $isIndexedArray ? $prefix.'[]' : $prefix.'['.$key.']';
$prefix = $isIndexedArray ? $prefix . '[]' : $prefix . '[' . $key . ']';

return static::encode($value, $prefix);
}, $query, array_keys($query)));
Expand Down
2 changes: 1 addition & 1 deletion src/Util/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static function removeQueryArgs($url): string
{
$url = parse_url($url);

if(empty($url)) {
if (empty($url)) {
return $url;
}

Expand Down
12 changes: 6 additions & 6 deletions tests/Unit/HttpClient/Message/QueryStringBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ public function queryStringProvider()
],
],
],
'search=a%20project'.
'&owned=true'.
'&iids%5B%5D=88&iids%5B%5D=86'.
'&assoc%5Ba%5D=b&assoc%5Bc%5D%5Bd%5D=e&assoc%5Bc%5D%5Bf%5D=g'.
'&nested%5Ba%5D%5B%5D%5Bb%5D=c&nested%5Ba%5D%5B%5D%5Bd%5D=e'.
'&nested%5Ba%5D%5B%5D%5Bf%5D%5Bg%5D=h&nested%5Ba%5D%5B%5D%5Bf%5D%5Bi%5D=j'.
'search=a%20project' .
'&owned=true' .
'&iids%5B%5D=88&iids%5B%5D=86' .
'&assoc%5Ba%5D=b&assoc%5Bc%5D%5Bd%5D=e&assoc%5Bc%5D%5Bf%5D=g' .
'&nested%5Ba%5D%5B%5D%5Bb%5D=c&nested%5Ba%5D%5B%5D%5Bd%5D=e' .
'&nested%5Ba%5D%5B%5D%5Bf%5D%5Bg%5D=h&nested%5Ba%5D%5B%5D%5Bf%5D%5Bi%5D=j' .
'&nested%5Ba%5D%5B%5D%5Bf%5D%5Bk%5D%5B%5D=87&nested%5Ba%5D%5B%5D%5Bf%5D%5Bk%5D%5B%5D=89',
];
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/HttpClient/Message/ResponseFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function should_get_content()
$body = ['foo' => 'bar'];
$response = new Response(
200,
['Content-Type'=> 'application/json'],
['Content-Type' => 'application/json'],
\GuzzleHttp\Psr7\Utils::streamFor(json_encode($body))
);

Expand Down Expand Up @@ -48,7 +48,7 @@ public function should_get_content_invalid_json()
$body = 'foobar';
$response = new Response(
200,
['Content-Type'=> 'application/json'],
['Content-Type' => 'application/json'],
\GuzzleHttp\Psr7\Utils::streamFor($body)
);

Expand Down

0 comments on commit b5acb1a

Please sign in to comment.