Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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
2 changes: 0 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
},
"autoload-dev": {
"psr-4": {
"Google\\ApiCore\\Dev\\": "dev/src",
"Google\\ApiCore\\Tests\\": "tests",
"GPBMetadata\\Google\\": "metadata/Google",
"Google\\Showcase\\": "tests/Conformance/src",
"GPBMetadata\\Google\\Showcase\\": "tests/Conformance/metadata"
}
Expand Down
59 changes: 0 additions & 59 deletions dev/src/Docs/doctum-protobuf-config.php

This file was deleted.

3 changes: 0 additions & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" colors="true">
<php>
<env name="GOOGLE_APPLICATION_CREDENTIALS" value="tests/Unit/testdata/json-key-file.json"/>
</php>
<coverage>
<include>
<directory suffix=".php">src/ApiCore</directory>
Expand Down
3 changes: 1 addition & 2 deletions src/ClientOptionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ private function buildClientOptions(array|ClientOptions $options)
$options['logger'] = ApplicationDefaultCredentials::getDefaultLogger();
}

if (
$options['logger'] !== null
if ($options['logger'] !== null
&& $options['logger'] !== false
&& !$options['logger'] instanceof LoggerInterface
) {
Expand Down
2 changes: 1 addition & 1 deletion src/OperationResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class OperationResponse
* OperationResponse constructor.
*
* @param string $operationName
* @param object $operationsClient
* @param object|null $operationsClient
* @param array $options {
* Optional. Options for configuring the operation response object.
*
Expand Down
2 changes: 1 addition & 1 deletion src/ResourceTemplate/AbsoluteResourceTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
class AbsoluteResourceTemplate implements ResourceTemplateInterface
{
private RelativeResourceTemplate $resourceTemplate;
/** @var string|bool */
/** @var string */
private $verb;

/**
Expand Down
4 changes: 2 additions & 2 deletions src/ResourceTemplate/Segment.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class Segment
private ?string $value;
private ?string $key;
private ?RelativeResourceTemplate $template;
private ?string $stringRepr;
private ?string $separator;
private string $stringRepr;
private string $separator;

/**
* Segment constructor.
Expand Down
31 changes: 26 additions & 5 deletions src/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@
use Google\Protobuf\DescriptorPool;
use Google\Protobuf\FieldDescriptor;
use Google\Protobuf\Internal\Message;
use Google\Rpc\BadRequest;
use Google\Rpc\DebugInfo;
use Google\Rpc\ErrorInfo;
use Google\Rpc\Help;
use Google\Rpc\LocalizedMessage;
use Google\Rpc\PreconditionFailure;
use Google\Rpc\QuotaFailure;
use Google\Rpc\RequestInfo;
use Google\Rpc\ResourceInfo;
use Google\Rpc\RetryInfo;
use Google\Rpc\Status;
use RuntimeException;

/**
Expand Down Expand Up @@ -180,7 +191,7 @@
$result = [];
// If metadata contains a "status" bin, use that instead
if (isset($metadata['grpc-status-details-bin'])) {
$status = new \Google\Rpc\Status();
$status = new Status();
$status->mergeFromString($metadata['grpc-status-details-bin'][0]);
foreach ($status->getDetails() as $any) {
if (isset(KnownTypes::TYPE_URLS[$any->getTypeUrl()])) {
Expand Down Expand Up @@ -212,7 +223,18 @@
if (self::hasBinaryHeaderSuffix($key)) {
if (isset(KnownTypes::BIN_TYPES[$key])) {
$class = KnownTypes::BIN_TYPES[$key];
/** @var Message $message */
/**
* @var BadRequest
* | DebugInfo
* | ErrorInfo
* | Help
* | LocalizedMessage
* | PreconditionFailure
* | QuotaFailure
* | RequestInfo
* | ResourceInfo
* | RetryInfo $message
*/
$message = new $class();
try {
$message->mergeFromString($value);
Expand Down Expand Up @@ -467,15 +489,14 @@
*/
private function checkFieldRepeated(FieldDescriptor $field): bool
{
// @phpstan-ignore function.alreadyNarrowedType
Comment thread
bshaffer marked this conversation as resolved.
Outdated
if (method_exists($field, 'isRepeated')) {

Check failure on line 493 in src/Serializer.php

View workflow job for this annotation

GitHub Actions / PHPStan Static Analysis / PHPStan Static Analysis

No error with identifier function.alreadyNarrowedType is reported on line 493.
return $field->isRepeated();
}

if (method_exists($field, 'getLabel')) {
return $field->getLabel() === GPBLabel::REPEATED;
}

throw new \Exception('No field repeated method avaialble');
throw new \LogicException('unable to check field repeated');
Comment thread
bshaffer marked this conversation as resolved.
Outdated
Comment thread
bshaffer marked this conversation as resolved.
Outdated
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/Testing/MockRequest.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/Testing/MockRequestBody.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/Testing/MockResponse.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Transport/Rest/JsonStreamDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function __construct(StreamInterface $stream, string $decodeType, array $
public function decode()
{
try {
foreach ($this->_decode() as $response) {
foreach ($this->doDecode() as $response) {
yield $response;
}
} catch (RuntimeException $re) {
Expand All @@ -112,7 +112,7 @@ public function decode()
/**
* @return \Generator
*/
private function _decode()
private function doDecode()
{
$decodeType = $this->decodeType;
$str = false;
Expand Down
4 changes: 2 additions & 2 deletions src/Transport/Rest/RestServerStreamingCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class RestServerStreamingCall implements ServerStreamingCallInterface
private array $decoderOptions;

private RequestInterface $originalRequest;
private ?JsonStreamDecoder $decoder;
private JsonStreamDecoder $decoder;
private string $decodeType;
private ?ResponseInterface $response;
private stdClass $status;
Expand Down Expand Up @@ -181,7 +181,7 @@ public function getPeer()
*/
public function cancel()
{
if (!is_null($this->decoder)) {
if (isset($this->decoder)) {
$this->decoder->close();
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Transport/RestTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public function startServerStreamingCall(Call $call, array $options)
$request = $this->requestBuilder->build(
$call->getMethod(),
$call->getMessage()
// Exclude headers here because they will be added in _serverStreamRequest().
// Exclude headers here because they will be added in doServerStreamRequest().
);

$decoderOptions = [];
Expand All @@ -209,7 +209,7 @@ public function startServerStreamingCall(Call $call, array $options)
}

return new ServerStream(
$this->_serverStreamRequest(
$this->doServerStreamRequest(
$this->httpHandler,
$request,
$headers,
Expand All @@ -233,7 +233,7 @@ public function startServerStreamingCall(Call $call, array $options)
*
* @return RestServerStreamingCall
*/
private function _serverStreamRequest(
private function doServerStreamRequest(
$httpHandler,
$request,
$headers,
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/AgentHeaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ public function testWithNullVersionInput()

public function testGetGapicVersionWithVersionFile()
{
require_once __DIR__ . '/testdata/src/GapicClientStub.php';
require_once __DIR__ . '/testdata/mocks/src/GapicClientStub.php';
$expectedVersion = '1.2.3-dev';
$actualVersion = AgentHeader::readGapicVersionFromFile(\GapicClientStub::class);
$actualVersion = AgentHeader::readGapicVersionFromFile(GapicClientStub::class);
$this->assertEquals($expectedVersion, $actualVersion);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/ApiExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function testWithMetadataWithoutErrorInfo($metadata, $metadataArray, $uns
$this->assertSame(Code::OK, $apiException->getCode());
$this->assertSame($expectedMessageWithoutErrorDetails, $apiException->getMessage());
$this->assertSame($metadata, $apiException->getMetadata());
$this->assertCount($unserializedErrorsCount ,$apiException->getErrorDetails());
$this->assertCount($unserializedErrorsCount, $apiException->getErrorDetails());
}

/**
Expand All @@ -123,7 +123,7 @@ public function testCreateFromApiResponse($metadata, $metadataArray, $unserializ
$this->assertSame(Code::OK, $apiException->getCode());
$this->assertSame($expectedMessage, $apiException->getMessage());
$this->assertSame($metadata, $apiException->getMetadata());
$this->assertCount($unserializedErrorsCount ,$apiException->getErrorDetails());
$this->assertCount($unserializedErrorsCount, $apiException->getErrorDetails());
}

public function getMetadata()
Expand Down Expand Up @@ -242,7 +242,7 @@ public function testWithMetadataWithErrorInfo($metadata, $metadataArray)
'code' => Code::OK,
'status' => 'OK',
'details' => $metadataArray,
],
],
JSON_PRETTY_PRINT
);

Expand Down
23 changes: 10 additions & 13 deletions tests/Unit/ArrayTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,16 @@ class ArrayTraitTest extends TestCase

public function setUp(): void
{
$this->implementation = new ArrayTraitStub();
$this->implementation = new class() {
use ArrayTrait {
arrayFilterRemoveNull as public;
isAssoc as public;
pluck as public;
pluckArray as public;
subsetArray as public;
arrayMergeRecursive as public;
}
};
}

public function testPluck()
Expand Down Expand Up @@ -182,15 +191,3 @@ public function testArrayMergeRecursive()
$this->assertEquals($expected, $res);
}
}

class ArrayTraitStub
{
use ArrayTrait {
arrayFilterRemoveNull as public;
isAssoc as public;
pluck as public;
pluckArray as public;
subsetArray as public;
arrayMergeRecursive as public;
}
}
3 changes: 2 additions & 1 deletion tests/Unit/BidiStreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ public function testReadCallsLogger()

$stream->writeAll($requests);

foreach ($stream->closeWriteAndReadAll() as $_) {}
foreach ($stream->closeWriteAndReadAll() as $_) {
}
}
}
Loading
Loading