diff --git a/src/Asana/Dispatcher/Dispatcher.php b/src/Asana/Dispatcher/Dispatcher.php index 2be00d7..33928df 100644 --- a/src/Asana/Dispatcher/Dispatcher.php +++ b/src/Asana/Dispatcher/Dispatcher.php @@ -11,13 +11,13 @@ public function __construct() { // All of Asana's IDs are int64. If the current build of PHP does not // support integers that large, we specify that integers that are too - // large should be represented as strings instead. Otherwise PHP would + // large should be represented as strings instead. Otherwise PHP would // convert them to floats. - // Note that Httpful's JsonHandler does not support that option which + // Note that Httpful's JsonHandler does not support that option which // is why we have to register our own JSON handler. if (PHP_INT_SIZE < 8) { \Httpful\Httpful::register( - \Httpful\Mime::JSON, + \Httpful\Mime::JSON, new \Asana\Dispatcher\Handlers\JsonHandler(array('parse_options' => JSON_BIGINT_AS_STRING)) ); } @@ -38,8 +38,8 @@ public function request($method, $uri, $requestOptions) ->expectsJson(); if (isset($requestOptions['curl'])) { - foreach($requestOptions['curl'] as $curlopt => $curlval){ - $request->addOnCurlOption($curlopt,$curlval); + foreach ($requestOptions['curl'] as $curlopt => $curlval) { + $request->addOnCurlOption($curlopt, $curlval); } } @@ -61,16 +61,14 @@ public function request($method, $uri, $requestOptions) // If the user's PHP version supports curl_file_create, use it. if (function_exists('curl_file_create')) { - if ( (isset($file[1]) && $file[1] != null) ) { + if ((isset($file[1]) && $file[1] != null)) { $mimetype = ''; - if ( (isset($file[2]) && $file[2] != null) ) { + if ((isset($file[2]) && $file[2] != null)) { $mimetype = $file[2]; } $body[$name] = curl_file_create($tmpFilePath, $mimetype, $file[1]); } - } - // Otherwise we can still use the '@' notation. - else { + } else { // Otherwise we can still use the '@' notation. $body[$name] = '@' . $tmpFilePath; if (isset($file[1]) && $file[1] != null) { $body[$name] .= ';filename=' . $file[1]; diff --git a/src/Asana/Dispatcher/Handlers/JsonHandler.php b/src/Asana/Dispatcher/Handlers/JsonHandler.php index d84a11f..bbaf4c0 100644 --- a/src/Asana/Dispatcher/Handlers/JsonHandler.php +++ b/src/Asana/Dispatcher/Handlers/JsonHandler.php @@ -30,11 +30,13 @@ public function init(array $args) public function parse($body) { $body = $this->stripBom($body); - if (empty($body)) + if (empty($body)) { return null; + } $parsed = json_decode($body, $this->decode_as_array, $this->depth, $this->parse_options); - if (is_null($parsed) && 'null' !== strtolower($body)) + if (is_null($parsed) && 'null' !== strtolower($body)) { throw new \Exception("Unable to parse response as JSON"); + } return $parsed; } @@ -46,4 +48,4 @@ public function serialize($payload) { return json_encode($payload); } -} \ No newline at end of file +} diff --git a/src/Asana/Dispatcher/OAuthDispatcher.php b/src/Asana/Dispatcher/OAuthDispatcher.php index 7664873..379f33a 100644 --- a/src/Asana/Dispatcher/OAuthDispatcher.php +++ b/src/Asana/Dispatcher/OAuthDispatcher.php @@ -89,4 +89,4 @@ protected function authenticate($request) } return $request->addHeader("Authorization", "Bearer " . $this->accessToken); } -} \ No newline at end of file +} diff --git a/tests/Asana/ClientTest.php b/tests/Asana/ClientTest.php index a8dbce6..63ab71e 100644 --- a/tests/Asana/ClientTest.php +++ b/tests/Asana/ClientTest.php @@ -213,7 +213,12 @@ public function testRateLimiting() array(429, array('Retry-After' => '0.1' ), '{}'), array(200, null, '{ "data": "me" }') ); - $this->dispatcher->registerResponse('/users/me', function () use (&$res) { return array_shift($res); }); + $this->dispatcher->registerResponse( + '/users/me', + function () use (&$res) { + return array_shift($res); + } + ); $result = $this->client->users->me(); $this->assertEquals($result, 'me'); @@ -229,7 +234,12 @@ public function testRateLimitedTwice() array(429, array('Retry-After' => '0.1' ), '{}'), array(200, null, '{ "data": "me" }') ); - $this->dispatcher->registerResponse('/users/me', function () use (&$res) { return array_shift($res); }); + $this->dispatcher->registerResponse( + '/users/me', + function () use (&$res) { + return array_shift($res); + } + ); $result = $this->client->users->me(); $this->assertEquals($result, 'me'); @@ -244,7 +254,12 @@ public function testServerErrorRetry() array(500, null, '{}'), array(200, null, '{ "data": "me" }') ); - $this->dispatcher->registerResponse('/users/me', function () use (&$res) { return array_shift($res); }); + $this->dispatcher->registerResponse( + '/users/me', + function () use (&$res) { + return array_shift($res); + } + ); $result = $this->client->users->me(null, array('max_retries' => 1)); $this->assertEquals(count($this->dispatcher->calls), 2); @@ -260,7 +275,12 @@ public function testServerErrorRetryBackoff() array(500, null, '{}'), array(200, null, '{ "data": "me" }') ); - $this->dispatcher->registerResponse('/users/me', function () use (&$res) { return array_shift($res); }); + $this->dispatcher->registerResponse( + '/users/me', + function () use (&$res) { + return array_shift($res); + } + ); $result = $this->client->users->me(); $this->assertEquals(count($this->dispatcher->calls), 4); @@ -269,7 +289,8 @@ public function testServerErrorRetryBackoff() public function testGetNamedParameters() { - $this->dispatcher->registerResponse('/tasks?limit=50&workspace=14916&assignee=me', 200, null, '{ "data": "foo" }'); + $res = '{ "data": "foo" }'; + $this->dispatcher->registerResponse('/tasks?limit=50&workspace=14916&assignee=me', 200, null, $res); $options = array('iterator_type' => false); $result = $this->client->tasks->findAll(array('workspace' => 14916, 'assignee' => 'me'), $options); diff --git a/tests/Asana/OAuthDispatcherTest.php b/tests/Asana/OAuthDispatcherTest.php index 115a917..dcbb710 100644 --- a/tests/Asana/OAuthDispatcherTest.php +++ b/tests/Asana/OAuthDispatcherTest.php @@ -8,18 +8,23 @@ use Asana\Dispatcher\OAuthDispatcher; // Extend dispatcher to expose protected methods for testing. -class FakeOauthDispatcher extends OAuthDispatcher { - public function authenticate($request) { - return parent::authenticate($request); - } -}; +class FakeOauthDispatcher extends OAuthDispatcher +{ + public function authenticate($request) + { + return parent::authenticate($request); + } +} class OAuthDispatcherTest extends \PHPUnit\Framework\TestCase { protected function setUp(): void { - $this->dispatcher = new FakeOAuthDispatcher(array( - 'client_id' => 'fake_client_id')); + $this->dispatcher = new FakeOAuthDispatcher( + array( + 'client_id' => 'fake_client_id' + ) + ); } public function testAuthenticateNoToken() @@ -37,6 +42,8 @@ public function testAuthenticateUsesToken() $request = new MockRequest($this->dispatcher); $this->dispatcher->authenticate($request); $this->assertEquals( - $request->headers, array('Authorization' => 'Bearer fake_token')); + $request->headers, + array('Authorization' => 'Bearer fake_token') + ); } } diff --git a/tests/Asana/Resources/AttachmentsTest.php b/tests/Asana/Resources/AttachmentsTest.php index f789fb5..1e41fe6 100644 --- a/tests/Asana/Resources/AttachmentsTest.php +++ b/tests/Asana/Resources/AttachmentsTest.php @@ -19,9 +19,9 @@ public function testAttachmentsCreateOnTask() // If the user's PHP version supports curl_file_create, use it. if (function_exists('curl_file_create')) { - $this->assertInstanceOf('CURLFile',$fileDescription); - $this->assertEquals('file name',$fileDescription->getPostFilename()); - $this->assertEquals('file content-type',$fileDescription->getMimeType()); + $this->assertInstanceOf('CURLFile', $fileDescription); + $this->assertEquals('file name', $fileDescription->getPostFilename()); + $this->assertEquals('file content-type', $fileDescription->getMimeType()); } else { $this->assertStringMatchesFormat('%Sfilename=file name%S', $fileDescription); $this->assertStringMatchesFormat('%Stype=file content-type%S', $fileDescription); diff --git a/tests/Asana/Resources/WebhooksTest.php b/tests/Asana/Resources/WebhooksTest.php index 92a9478..a7679ed 100644 --- a/tests/Asana/Resources/WebhooksTest.php +++ b/tests/Asana/Resources/WebhooksTest.php @@ -34,11 +34,12 @@ public function testWebhooksCreate() public function testWebhooksGetAll() { - $this->dispatcher->registerResponse('/webhooks?limit=50&workspace=1337', 200, null, '{ "data": [' . json_encode($this->data) . '] }'); + $res = '{ "data": [' . json_encode($this->data) . '] }'; + $this->dispatcher->registerResponse('/webhooks?limit=50&workspace=1337', 200, null, $res); $result = $this->client->webhooks->getAll(array("workspace" => 1337)); foreach ($result as $res) { - $this->verifyWebhookData($res); + $this->verifyWebhookData($res); } }