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

Simplify returns #849

Merged
merged 1 commit into from
Jan 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 2 additions & 10 deletions dev/src/DocGenerator/Parser/CodeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,11 +610,7 @@ private function hasNestedParams($description)
return false;
}

if ($description[0] === '{') {
return true;
}

return false;
return $description[0] === '{';
}

private function buildExceptions($exceptions)
Expand Down Expand Up @@ -727,11 +723,7 @@ private function hasExternalType($type)
return (strpos($type, $external['name']) !== false);
});

if (count($types) === 0) {
return false;
}

return true;
return count($types) !== 0;
}

private function buildExternalType($type)
Expand Down
6 changes: 1 addition & 5 deletions src/Core/ArrayTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,7 @@ private function isAssoc(array $arr)
private function arrayFilterRemoveNull(array $arr)
{
return array_filter($arr, function ($element) {
if (!is_null($element)) {
return true;
}

return false;
return !is_null($element);
});
}

Expand Down
6 changes: 1 addition & 5 deletions src/Core/Exception/AbortedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ class AbortedException extends ServiceException
public function getRetryDelay()
{
$metadata = array_filter($this->metadata, function ($metadataItem) {
if (array_key_exists('retryDelay', $metadataItem)) {
return true;
}

return false;
return array_key_exists('retryDelay', $metadataItem);
});

if (count($metadata) === 0) {
Expand Down
6 changes: 1 addition & 5 deletions src/Core/GrpcRequestWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,7 @@ public function send(callable $request, array $args, array $options = [])
$backoff = new ExponentialBackoff($retries, function (\Exception $ex) {
$statusCode = $ex->getCode();

if (in_array($statusCode, $this->grpcRetryCodes)) {
return true;
}

return false;
return in_array($statusCode, $this->grpcRetryCodes);
});

if (!isset($grpcOptions['retrySettings'])) {
Expand Down
6 changes: 1 addition & 5 deletions src/Datastore/EntityMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -481,11 +481,7 @@ private function isEncoded($value)
}

// Encode the string again
if (base64_encode($decoded) != $value) {
return false;
}

return true;
return base64_encode($decoded) == $value;
}

/**
Expand Down
6 changes: 1 addition & 5 deletions src/Storage/Bucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -1032,11 +1032,7 @@ public function iam()
*/
private function isObjectNameRequired($data)
{
if (is_string($data) || is_null($data)) {
return true;
}

return false;
return is_string($data) || is_null($data);
}

/**
Expand Down
6 changes: 1 addition & 5 deletions src/Vision/Annotation/LikelihoodTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ private function likelihood($value, $strength)

$levels = $this->likelihoodLevels[$strength];

if (in_array($value, $levels)) {
return true;
}

return false;
return in_array($value, $levels);
}
}
24 changes: 8 additions & 16 deletions tests/snippets/Datastore/DatastoreClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,7 @@ public function testInsert()
$snippet->addLocal('datastore', $this->client);

$this->connection->commit(Argument::that(function ($args) {
if (array_keys($args['mutations'][0])[0] !== 'insert') return false;
return true;
return array_keys($args['mutations'][0])[0] === 'insert';
}))
->shouldBeCalled()
->willReturn([
Expand All @@ -328,8 +327,7 @@ public function testInsertBatch()
$snippet->addLocal('datastore', $this->client);

$this->connection->commit(Argument::that(function ($args) {
if (array_keys($args['mutations'][0])[0] !== 'insert') return false;
return true;
return array_keys($args['mutations'][0])[0] === 'insert';
}))
->shouldBeCalled();

Expand All @@ -351,8 +349,7 @@ public function testUpdate()
]));

$this->connection->commit(Argument::that(function ($args) {
if (array_keys($args['mutations'][0])[0] !== 'update') return false;
return true;
return array_keys($args['mutations'][0])[0] === 'update';
}))
->shouldBeCalled()
->willReturn([
Expand All @@ -376,8 +373,7 @@ public function testUpdateBatch()
]);

$this->connection->commit(Argument::that(function ($args) {
if (array_keys($args['mutations'][0])[0] !== 'update') return false;
return true;
return array_keys($args['mutations'][0])[0] === 'update';
}))
->shouldBeCalled();

Expand All @@ -390,8 +386,7 @@ public function testUpsert()
$snippet->addLocal('datastore', $this->client);

$this->connection->commit(Argument::that(function ($args) {
if (array_keys($args['mutations'][0])[0] !== 'upsert') return false;
return true;
return array_keys($args['mutations'][0])[0] === 'upsert';
}))
->shouldBeCalled()
->willReturn([
Expand All @@ -411,8 +406,7 @@ public function testUpsertBatch()
$snippet->addLocal('datastore', $this->client);

$this->connection->commit(Argument::that(function ($args) {
if (array_keys($args['mutations'][0])[0] !== 'upsert') return false;
return true;
return array_keys($args['mutations'][0])[0] === 'upsert';
}))
->shouldBeCalled();

Expand All @@ -425,8 +419,7 @@ public function testDelete()
$snippet->addLocal('datastore', $this->client);

$this->connection->commit(Argument::that(function ($args) {
if (array_keys($args['mutations'][0])[0] !== 'delete') return false;
return true;
return array_keys($args['mutations'][0])[0] === 'delete';
}))
->shouldBeCalled()
->willReturn([
Expand All @@ -446,8 +439,7 @@ public function testDeleteBatch()
$snippet->addLocal('datastore', $this->client);

$this->connection->commit(Argument::that(function ($args) {
if (array_keys($args['mutations'][0])[0] !== 'delete') return false;
return true;
return array_keys($args['mutations'][0])[0] === 'delete';
}))
->shouldBeCalled();

Expand Down
21 changes: 7 additions & 14 deletions tests/snippets/Datastore/TransactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ public function testInsert()

$this->connection->commit(Argument::that(function ($args) {
if ($args['transaction'] !== $this->transactionId) return false;
if (array_keys($args['mutations'][0])[0] !== 'insert') return false;
return true;
return array_keys($args['mutations'][0])[0] === 'insert';
}))
->shouldBeCalled()
->willReturn([
Expand All @@ -114,8 +113,7 @@ public function testInsertBatch()

$this->connection->commit(Argument::that(function ($args) {
if ($args['transaction'] !== $this->transactionId) return false;
if (array_keys($args['mutations'][0])[0] !== 'insert') return false;
return true;
return array_keys($args['mutations'][0])[0] === 'insert';
}))
->shouldBeCalled()
->willReturn([
Expand All @@ -142,8 +140,7 @@ public function testUpdate()

$this->connection->commit(Argument::that(function ($args) {
if ($args['transaction'] !== $this->transactionId) return false;
if (array_keys($args['mutations'][0])[0] !== 'update') return false;
return true;
return array_keys($args['mutations'][0])[0] === 'update';
}))
->shouldBeCalled()
->willReturn([
Expand All @@ -169,8 +166,7 @@ public function testUpdateBatch()

$this->connection->commit(Argument::that(function ($args) {
if ($args['transaction'] !== $this->transactionId) return false;
if (array_keys($args['mutations'][0])[0] !== 'update') return false;
return true;
return array_keys($args['mutations'][0])[0] === 'update';
}))
->shouldBeCalled();

Expand All @@ -188,8 +184,7 @@ public function testUpsert()

$this->connection->commit(Argument::that(function ($args) {
if ($args['transaction'] !== $this->transactionId) return false;
if (array_keys($args['mutations'][0])[0] !== 'upsert') return false;
return true;
return array_keys($args['mutations'][0])[0] === 'upsert';
}))
->shouldBeCalled()
->willReturn([
Expand All @@ -215,8 +210,7 @@ public function testUpsertBatch()

$this->connection->commit(Argument::that(function ($args) {
if ($args['transaction'] !== $this->transactionId) return false;
if (array_keys($args['mutations'][0])[0] !== 'upsert') return false;
return true;
return array_keys($args['mutations'][0])[0] === 'upsert';
}))
->shouldBeCalled();

Expand All @@ -231,8 +225,7 @@ public function testDelete()

$this->connection->commit(Argument::that(function ($args) {
if ($args['transaction'] !== $this->transactionId) return false;
if (array_keys($args['mutations'][0])[0] !== 'delete') return false;
return true;
return array_keys($args['mutations'][0])[0] === 'delete';
}))
->shouldBeCalled()
->willReturn([
Expand Down
12 changes: 3 additions & 9 deletions tests/unit/Datastore/TransactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ public function testDeleteBatch()
public function testLookup()
{
$this->operation->lookup(Argument::type('array'), Argument::that(function ($arg) {
if ($arg['transaction'] !== $this->transactionId) return false;

return true;
return $arg['transaction'] === $this->transactionId;
}))->willReturn(['found' => ['foo']]);

$this->transaction->setOperation($this->operation->reveal());
Expand All @@ -184,9 +182,7 @@ public function testLookup()
public function testLookupBatch()
{
$this->operation->lookup(Argument::type('array'), Argument::that(function ($arg) {
if ($arg['transaction'] !== $this->transactionId) return false;

return true;
return $arg['transaction'] === $this->transactionId;
}))->willReturn([]);

$this->transaction->setOperation($this->operation->reveal());
Expand All @@ -199,9 +195,7 @@ public function testLookupBatch()
public function testRunQuery()
{
$this->operation->runQuery(Argument::type(QueryInterface::class), Argument::that(function ($arg) {
if ($arg['transaction'] !== $this->transactionId) return false;

return true;
return $arg['transaction'] === $this->transactionId;
}))->willReturn('test');

$this->transaction->setOperation($this->operation->reveal());
Expand Down
5 changes: 2 additions & 3 deletions tests/unit/Firestore/CollectionReferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,8 @@ public function testAdd()
];

unset($args['writes'][0]['update']['name']);
if ($args !== $expected) return false;

return true;

return $args === $expected;
}))->shouldBeCalled()->willReturn([[]]);

$this->collection->___setProperty('connection', $this->connection->reveal());
Expand Down
4 changes: 1 addition & 3 deletions tests/unit/Spanner/SpannerClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,7 @@ public function testCreateInstance()
{
$this->connection->createInstance(Argument::that(function ($arg) {
if ($arg['name'] !== InstanceAdminClient::instanceName(self::PROJECT, self::INSTANCE)) return false;
if ($arg['config'] !== InstanceAdminClient::instanceConfigName(self::PROJECT, self::CONFIG)) return false;

return true;
return $arg['config'] === InstanceAdminClient::instanceConfigName(self::PROJECT, self::CONFIG);
}))
->shouldBeCalled()
->willReturn([
Expand Down
8 changes: 2 additions & 6 deletions tests/unit/Spanner/TransactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,7 @@ public function testExecute()

$this->connection->executeStreamingSql(Argument::that(function ($arg) use ($sql) {
if ($arg['transaction']['id'] !== self::TRANSACTION) return false;
if ($arg['sql'] !== $sql) return false;

return true;
return $arg['sql'] === $sql;
}))->shouldBeCalled()->willReturn($this->resultGenerator());

$this->refreshOperation();
Expand All @@ -212,9 +210,7 @@ public function testRead()
if ($arg['transaction']['id'] !== self::TRANSACTION) return false;
if ($arg['table'] !== $table) return false;
if ($arg['keySet']['all'] !== true) return false;
if ($arg['columns'] !== ['ID']) return false;

return true;
return $arg['columns'] === ['ID'];
}))->shouldBeCalled()->willReturn($this->resultGenerator());

$this->refreshOperation();
Expand Down
6 changes: 1 addition & 5 deletions tests/unit/Translate/TranslateClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ public function testWithNoKey()
$client = new TranslateTestClient();

$this->connection->listTranslations(Argument::that(function($args) {
if (isset($args['key'])) {
return false;
}

return true;
return !isset($args['key']);
}))->shouldBeCalled()->willReturn([]);

$client->setConnection($this->connection->reveal());
Expand Down