Skip to content

Commit 82baba4

Browse files
committed
types cleanup
1 parent bef90d4 commit 82baba4

48 files changed

Lines changed: 408 additions & 679 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/system-tests-spanner-emulator.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
- name: Install dependencies
5050
run: |
5151
# ensure composer uses local Core instead of pulling from packagist
52-
# composer config repositories.local --json '{"type":"path", "url": "../Core", "options": {"versions": {"google/cloud-core": "1.100"}}}' -d Spanner
52+
composer config repositories.local --json '{"type":"path", "url": "../Core", "options": {"versions": {"google/cloud-core": "1.100"}},"canonical":false}' -d Spanner
5353
composer update --prefer-dist --no-interaction --no-suggest -d Spanner/
5454
5555
- name: Run system tests

Core/src/RequestHandler.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ class RequestHandler
4646

4747
/**
4848
* @param Serializer $serializer
49-
* @param array<string|object> $clientClasses
49+
* @param array<string|object> $clients
5050
* @param array $clientConfig
5151
*/
5252
public function __construct(
5353
Serializer $serializer,
54-
array $clientClasses,
54+
array $clients,
5555
array $clientConfig = []
5656
) {
5757
//@codeCoverageIgnoreStart
@@ -75,7 +75,7 @@ public function __construct(
7575
//@codeCoverageIgnoreEnd
7676

7777
// Initialize the client classes and store them in memory
78-
foreach ($clientClasses as $client) {
78+
foreach ($clients as $client) {
7979
if (is_object($client)) {
8080
$this->clients[get_class($client)] = $client;
8181
} else {

Core/src/Timestamp.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
namespace Google\Cloud\Core;
1919

20+
use DateTimeInterface;
21+
2022
/**
2123
* Represents a Timestamp value.
2224
*
@@ -85,9 +87,9 @@ public function __construct(\DateTimeInterface $value, $nanoSeconds = null)
8587
* $dateTime = $timestamp->get();
8688
* ```
8789
*
88-
* @return \DateTimeInterface
90+
* @return DateTimeInterface
8991
*/
90-
public function get()
92+
public function get(): DateTimeInterface
9193
{
9294
return $this->value;
9395
}
@@ -102,7 +104,7 @@ public function get()
102104
*
103105
* @return int
104106
*/
105-
public function nanoSeconds()
107+
public function nanoSeconds(): int
106108
{
107109
return $this->nanoSeconds === null
108110
? (int) $this->value->format('u') * 1000
@@ -119,7 +121,7 @@ public function nanoSeconds()
119121
*
120122
* @return string
121123
*/
122-
public function formatAsString()
124+
public function formatAsString(): string
123125
{
124126
return $this->formatTimeAsString(
125127
$this->value,
@@ -143,7 +145,7 @@ public function __toString()
143145
*
144146
* @return array
145147
*/
146-
public function formatForApi()
148+
public function formatForApi(): array
147149
{
148150
return $this->formatTimeAsArray($this->value, $this->nanoSeconds());
149151
}
@@ -155,7 +157,7 @@ public function formatForApi()
155157
* @access private
156158
*/
157159
#[\ReturnTypeWillChange]
158-
public function jsonSerialize()
160+
public function jsonSerialize(): string
159161
{
160162
return $this->formatAsString();
161163
}

Core/tests/Unit/ServiceBuilderTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
use Google\Cloud\Firestore\FirestoreClient;
2525
use Google\Cloud\Language\LanguageClient;
2626
use Google\Cloud\Logging\LoggingClient;
27-
use Google\Cloud\Speech\SpeechClient;
2827
use Google\Cloud\Storage\StorageClient;
2928
use Google\Cloud\Core\Tests\Unit\Fixtures;
3029
use GuzzleHttp\Psr7\Response;
@@ -161,10 +160,6 @@ public function serviceProvider()
161160
], [
162161
'language',
163162
LanguageClient::class
164-
], [
165-
'speech',
166-
SpeechClient::class,
167-
['languageCode' => 'en-US']
168163
], [
169164
'storage',
170165
StorageClient::class

Spanner/src/ArrayType.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,11 @@
6161
*/
6262
class ArrayType
6363
{
64-
/**
65-
* @var int|null
66-
*/
67-
private $type;
68-
69-
/**
70-
* @var StructType|null
71-
*/
72-
private $structType;
64+
private int|string|null $type;
65+
private StructType|null $structType;
7366

7467
/**
75-
* @param int|string|null|StructType $type A value type code or nested struct
68+
* @param int|string|StructType|null $type A value type code or nested struct
7669
* definition. Accepted integer and string values are defined as constants on
7770
* {@see \Google\Cloud\Spanner\Database}, and are as follows:
7871
* `Database::TYPE_BOOL`, `Database::TYPE_INT64`,
@@ -87,7 +80,7 @@ class ArrayType
8780
* a struct is defined but the given type is not
8881
* `Database::TYPE_STRUCT`.
8982
*/
90-
public function __construct($type)
83+
public function __construct(int|string|StructType|null $type)
9184
{
9285
if ($type === Database::TYPE_STRUCT) {
9386
throw new \InvalidArgumentException(

Spanner/src/Backup.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function __construct(
100100
* @throws \InvalidArgumentException
101101
*/
102102
public function create(
103-
$database,
103+
string $database,
104104
DateTimeInterface $expireTime,
105105
array $options = []
106106
): LongRunningOperation {
@@ -362,7 +362,7 @@ public function updateExpireTime(DateTimeInterface $newTimestamp, array $options
362362
* @param string $operationName The Long Running Operation name.
363363
* @return LongRunningOperation
364364
*/
365-
public function resumeOperation($operationName, array $options = []): LongRunningOperation
365+
public function resumeOperation(string $operationName, array $options = []): LongRunningOperation
366366
{
367367
return new LongRunningOperation(
368368
new LongRunningClientConnection($this->databaseAdminClient, $this->serializer),
@@ -423,7 +423,7 @@ function (OperationProto $operation) {
423423
*
424424
* @return string
425425
*/
426-
private function fullyQualifiedBackupName($name): string
426+
private function fullyQualifiedBackupName(string $name): string
427427
{
428428
$instance = DatabaseAdminClient::parseName($this->instance->name())['instance'];
429429

Spanner/src/Batch/BatchClient.php

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -108,30 +108,15 @@ class BatchClient
108108
use TransactionConfigurationTrait;
109109

110110
const PARTITION_TYPE_KEY = '__partitionTypeName';
111-
112-
/**
113-
* @var Operation
114-
*/
115-
private $operation;
116-
117-
/**
118-
* @var string
119-
*/
120-
private $databaseName;
121-
122-
/**
123-
* @var string|null
124-
*/
125-
private $databaseRole;
126-
127-
/**
128-
* @var array
129-
*/
130-
private $allowedPartitionTypes = [
111+
private const ALLOWED_PARTITION_TYPES = [
131112
QueryPartition::class,
132113
ReadPartition::class
133114
];
134115

116+
private Operation $operation;
117+
private string $databaseName;
118+
private string|null $databaseRole;
119+
135120
/**
136121
* @param Operation $operation A Cloud Spanner Operations wrapper.
137122
* @param string $databaseName The database name to which the batch client
@@ -262,7 +247,7 @@ public function partitionFromString($partition)
262247
}
263248

264249
$class = $data[self::PARTITION_TYPE_KEY];
265-
if (!in_array($class, $this->allowedPartitionTypes)) {
250+
if (!in_array($class, self::ALLOWED_PARTITION_TYPES)) {
266251
throw new \InvalidArgumentException('Invalid partition type.');
267252
}
268253

Spanner/src/Batch/BatchSnapshot.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function __construct(Operation $operation, Session $session, array $optio
9292
* @param array $options [optional] Configuration Options
9393
* @return void
9494
*/
95-
public function close(array $options = [])
95+
public function close(array $options = []): void
9696
{
9797
$this->session->delete($options);
9898
}
@@ -131,7 +131,7 @@ public function close(array $options = [])
131131
* }
132132
* @return ReadPartition[]
133133
*/
134-
public function partitionRead($table, KeySet $keySet, array $columns, array $options = [])
134+
public function partitionRead($table, KeySet $keySet, array $columns, array $options = []): array
135135
{
136136
return $this->operation->partitionRead(
137137
$this->session,
@@ -194,7 +194,7 @@ public function partitionRead($table, KeySet $keySet, array $columns, array $opt
194194
* }
195195
* @return QueryPartition[]
196196
*/
197-
public function partitionQuery($sql, array $options = [])
197+
public function partitionQuery($sql, array $options = []): array
198198
{
199199
return $this->operation->partitionQuery(
200200
$this->session,
@@ -218,11 +218,10 @@ public function partitionQuery($sql, array $options = [])
218218
* ```
219219
*
220220
* @param PartitionInterface $partition The partition to read.
221-
* @param array $options Configuration Options.
222221
* @return Result
223222
* @throws \BadMethodCallException If an invalid partition type is given.
224223
*/
225-
public function executePartition(PartitionInterface $partition, array $options = [])
224+
public function executePartition(PartitionInterface $partition): Result
226225
{
227226
if ($partition instanceof QueryPartition) {
228227
return $this->executeQuery($partition);
@@ -243,7 +242,7 @@ public function executePartition(PartitionInterface $partition, array $options =
243242
*
244243
* @return string
245244
*/
246-
public function serialize()
245+
public function serialize(): string
247246
{
248247
return base64_encode(json_encode([
249248
'sessionName' => $this->session->name(),
@@ -269,7 +268,7 @@ public function __toString()
269268
* @param QueryPartition $partition The partition.
270269
* @return Result
271270
*/
272-
private function executeQuery(QueryPartition $partition)
271+
private function executeQuery(QueryPartition $partition): Result
273272
{
274273
return $this->execute($partition->sql(), [
275274
'partitionToken' => $partition->token()
@@ -282,7 +281,7 @@ private function executeQuery(QueryPartition $partition)
282281
* @param ReadPartition $partition The partition.
283282
* @return Result
284283
*/
285-
private function executeRead(ReadPartition $partition)
284+
private function executeRead(ReadPartition $partition): Result
286285
{
287286
return $this->read($partition->table(), $partition->keySet(), $partition->columns(), [
288287
'partitionToken' => $partition->token()

Spanner/src/Batch/PartitionInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ public function __toString();
3030
/**
3131
* @return string
3232
*/
33-
public function serialize();
33+
public function serialize(): string;
3434

3535
/**
3636
* @param array $data
3737
* @return PartitionInterface
3838
*/
39-
public static function hydrate(array $data);
39+
public static function hydrate(array $data): PartitionInterface;
4040
}

Spanner/src/Batch/PartitionTrait.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,8 @@
2222
*/
2323
trait PartitionTrait
2424
{
25-
/**
26-
* @var string
27-
*/
28-
private $token;
29-
30-
/**
31-
* @var array
32-
*/
33-
private $options;
25+
private string $token;
26+
private array $options;
3427

3528
/**
3629
* Returns the partition token.
@@ -42,7 +35,7 @@ trait PartitionTrait
4235
*
4336
* @return string
4437
*/
45-
public function token()
38+
public function token(): string
4639
{
4740
return $this->token;
4841
}
@@ -57,7 +50,7 @@ public function token()
5750
*
5851
* @return array
5952
*/
60-
public function options()
53+
public function options(): array
6154
{
6255
return $this->options;
6356
}

0 commit comments

Comments
 (0)