Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated formatting to pass cs lint #56

Merged
merged 2 commits into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions src/Asana/Dispatcher/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
);
}
Expand All @@ -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);
}
}

Expand All @@ -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];
Expand Down
8 changes: 5 additions & 3 deletions src/Asana/Dispatcher/Handlers/JsonHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -46,4 +48,4 @@ public function serialize($payload)
{
return json_encode($payload);
}
}
}
2 changes: 1 addition & 1 deletion src/Asana/Dispatcher/OAuthDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ protected function authenticate($request)
}
return $request->addHeader("Authorization", "Bearer " . $this->accessToken);
}
}
}
6 changes: 5 additions & 1 deletion src/Asana/Resources/Gen/CustomFieldSettingsBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 16 additions & 6 deletions src/Asana/Resources/Gen/CustomFieldsBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down
4 changes: 3 additions & 1 deletion src/Asana/Resources/Gen/TasksBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 28 additions & 6 deletions tests/Asana/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
23 changes: 15 additions & 8 deletions tests/Asana/OAuthDispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
);
}

/**
Expand All @@ -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')
);
}
}
6 changes: 3 additions & 3 deletions tests/Asana/Resources/AttachmentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions tests/Asana/Resources/WebhooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down