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/src/Asana/Resources/Gen/CustomFieldSettingsBase.php b/src/Asana/Resources/Gen/CustomFieldSettingsBase.php index 33a319a..ec23eff 100644 --- a/src/Asana/Resources/Gen/CustomFieldSettingsBase.php +++ b/src/Asana/Resources/Gen/CustomFieldSettingsBase.php @@ -20,7 +20,11 @@ public function __construct($client) } /** - * Returns a list of all of the custom fields settings on a project, in compact form. Note that, as in all queries to collections which return compact representation, `opt_fields` and `opt_expand` can be used to include more data than is returned in the compact representation. See the getting started guide on [input/output options](/developers/documentation/getting-started/input-output-options) for more information. + * Returns a list of all of the custom fields settings on a project, in compact form. + * Note that, as in all queries to collections which return compact representation, + * `opt_fields` and `opt_expand` can be used to include more data than is returned in the compact representation. + * See the getting started guide on + * [input/output options](/developers/documentation/getting-started/input-output-options) for more information. * * @param project The ID of the project for which to list custom field settings * @return response diff --git a/src/Asana/Resources/Gen/CustomFieldsBase.php b/src/Asana/Resources/Gen/CustomFieldsBase.php index c21458e..155beba 100644 --- a/src/Asana/Resources/Gen/CustomFieldsBase.php +++ b/src/Asana/Resources/Gen/CustomFieldsBase.php @@ -20,9 +20,12 @@ public function __construct($client) } /** - * Creates a new custom field in a workspace. Every custom field is required to be created in a specific workspace, and this workspace cannot be changed once set. + * Creates a new custom field in a workspace. Every custom field is required to be + * created in a specific workspace, and this workspace cannot be changed once set. * - * A custom field's `name` must be unique within a workspace and not conflict with names of existing task properties such as 'Due Date' or 'Assignee'. A custom field's `type` must be one of 'text', 'enum', or 'number'. + * A custom field's `name` must be unique within a workspace and not conflict + * with names of existing task properties such as 'Due Date' or 'Assignee'. + * A custom field's `type` must be one of 'text', 'enum', or 'number'. * * Returns the full record of the newly created custom field. * @@ -58,13 +61,18 @@ public function findByWorkspace($workspace, $params = array(), $options = array( } /** - * A specific, existing custom field can be updated by making a PUT request on the URL for that custom field. Only the fields provided in the `data` block will be updated; any unspecified fields will remain unchanged + * A specific, existing custom field can be updated by making a PUT request on the URL + * for that custom field. Only the fields provided in the `data` block will be updated; + * any unspecified fields will remain unchanged * - * When using this method, it is best to specify only those fields you wish to change, or else you may overwrite changes made by another user since you last retrieved the custom field. + * When using this method, it is best to specify only those fields you wish to change, + * or else you may overwrite changes made by another user since you last retrieved the + * custom field. * * A custom field's `type` cannot be updated. * - * An enum custom field's `enum_options` cannot be updated with this endpoint. Instead see "Work With Enum Options" for information on how to update `enum_options`. + * An enum custom field's `enum_options` cannot be updated with this endpoint. + * Instead see "Work With Enum Options" for information on how to update `enum_options`. * * Returns the complete updated custom field record. * @@ -92,7 +100,9 @@ public function delete($customField, $params = array(), $options = array()) } /** - * Creates an enum option and adds it to this custom field's list of enum options. A custom field can have at most 50 enum options (including disabled options). By default new enum options are inserted at the end of a custom field's list. + * Creates an enum option and adds it to this custom field's list of enum options. + * A custom field can have at most 50 enum options (including disabled options). + * By default new enum options are inserted at the end of a custom field's list. * * Returns the full record of the newly created enum option. * diff --git a/src/Asana/Resources/Gen/TasksBase.php b/src/Asana/Resources/Gen/TasksBase.php index e697ca5..ae52d8f 100644 --- a/src/Asana/Resources/Gen/TasksBase.php +++ b/src/Asana/Resources/Gen/TasksBase.php @@ -154,7 +154,9 @@ public function findAll($params = array(), $options = array()) } /** - * The search endpoint allows you to build complex queries to find and fetch exactly the data you need from Asana. For a more comprehensive description of all the query parameters and limitations of this endpoint, see our [long-form documentation](/developers/documentation/getting-started/search-api) for this feature. + * The search endpoint allows you to build complex queries to find and fetch exactly the data you need from Asana. + * For a more comprehensive description of all the query parameters and limitations of this endpoint, + * see our [long-form documentation](/developers/documentation/getting-started/search-api) for this feature. * * @param workspace The workspace or organization in which to search for tasks. * @return response diff --git a/tests/Asana/ClientTest.php b/tests/Asana/ClientTest.php index 89c55a4..bf23d05 100644 --- a/tests/Asana/ClientTest.php +++ b/tests/Asana/ClientTest.php @@ -31,7 +31,8 @@ public function testNotAuthorized() */ public function testInvalidRequest() { - $this->dispatcher->registerResponse('/tasks?limit=50', 400, null, '{ "errors": [{ "message": "Missing input" }] }'); + $res = '{ "errors": [{ "message": "Missing input" }] }'; + $this->dispatcher->registerResponse('/tasks?limit=50', 400, null, $res); $this->client->tasks->findAll(null, array('iterator_type' => false)); } @@ -215,7 +216,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'); @@ -231,7 +237,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'); @@ -246,7 +257,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); @@ -262,7 +278,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); @@ -271,7 +292,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 c354429..68a2841 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() { - $this->dispatcher = new FakeOAuthDispatcher(array( - 'client_id' => 'fake_client_id')); + $this->dispatcher = new FakeOAuthDispatcher( + array( + 'client_id' => 'fake_client_id' + ) + ); } /** @@ -38,6 +43,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); } }