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

chore: replace cs and staticanalysis with reusable workflows #577

Merged
merged 5 commits into from
Aug 28, 2024
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
4 changes: 2 additions & 2 deletions .github/sync-repo-settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ branchProtectionRules:
- 'PHP 8.3 Unit Test'
- 'PHP 8.3 Unit Test protobuf,grpc'
- 'Run google-cloud-php tests'
- 'PHP Style Check'
- 'PHPStan Static Analysis'
- 'PHP Style Check / PHP Code Standards'
- 'PHPStan Static Analysis / PHPStan Static Analysis'
- 'cla/google'
requiredApprovingReviewCount: 1
requiresCodeOwnerReviews: true
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Generate Documentation
name: Documentation

on:
push:
Expand All @@ -15,7 +15,7 @@ permissions:

jobs:
docs:
name: "Generate and Deploy Documentation"
name: "Generate Documentation"
uses: GoogleCloudPlatform/php-tools/.github/workflows/doctum.yml@main
with:
title: "Google API Core (GAX) Reference Documentation"
Expand Down
38 changes: 5 additions & 33 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,39 +43,11 @@ jobs:
run: vendor/bin/phpunit

style:
runs-on: ubuntu-latest
name: PHP Style Check
steps:
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.2"
- name: Install Dependencies
uses: nick-invision/retry@v3
with:
timeout_minutes: 10
max_attempts: 3
command: composer install
- name: Run Script
run: vendor/bin/phpcs -s --standard=./ruleset.xml

staticanalysis:
runs-on: ubuntu-latest
name: PHPStan Static Analysis
steps:
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
- name: Install Dependencies
uses: nick-invision/retry@v3
uses: GoogleCloudPlatform/php-tools/.github/workflows/code-standards.yml@main
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Niiiice!

with:
timeout_minutes: 10
max_attempts: 3
command: composer install
- name: Run Script
run: |
vendor/bin/phpstan analyse
path: src

static-analysis:
name: PHPStan Static Analysis
uses: GoogleCloudPlatform/php-tools/.github/workflows/static-analysis.yml@main
13 changes: 0 additions & 13 deletions ruleset.xml

This file was deleted.

4 changes: 2 additions & 2 deletions src/AgentHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ public static function buildAgentHeader(array $headerInfo)

$metricsList = [];
foreach ($metricsHeaders as $key => $value) {
$metricsList[] = $key . "/" . $value;
$metricsList[] = $key . '/' . $value;
}
return [self::AGENT_HEADER_KEY => [implode(" ", $metricsList)]];
return [self::AGENT_HEADER_KEY => [implode(' ', $metricsList)]];
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/ApiException.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
use Google\Protobuf\Internal\RepeatedField;
use Google\Rpc\Status;
use GuzzleHttp\Exception\RequestException;
use Google\ApiCore\Testing\MockStatus;
use stdClass;

/**
Expand Down
8 changes: 4 additions & 4 deletions src/BidiStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ public function __construct(BidiStreamingCall $bidiStreamingCall, array $streami
public function write($request)
{
if ($this->isComplete) {
throw new ValidationException("Cannot call write() after streaming call is complete.");
throw new ValidationException('Cannot call write() after streaming call is complete.');
}
if ($this->writesClosed) {
throw new ValidationException("Cannot call write() after calling closeWrite().");
throw new ValidationException('Cannot call write() after calling closeWrite().');
}
$this->call->write($request);
}
Expand Down Expand Up @@ -99,7 +99,7 @@ public function closeWrite()
{
if ($this->isComplete) {
throw new ValidationException(
"Cannot call closeWrite() after streaming call is complete."
'Cannot call closeWrite() after streaming call is complete.'
);
}
if (!$this->writesClosed) {
Expand All @@ -119,7 +119,7 @@ public function closeWrite()
public function read()
{
if ($this->isComplete) {
throw new ValidationException("Cannot call read() after streaming call is complete.");
throw new ValidationException('Cannot call read() after streaming call is complete.');
}
$resourcesGetMethod = $this->resourcesGetMethod;
if (!is_null($resourcesGetMethod)) {
Expand Down
2 changes: 1 addition & 1 deletion src/ClientStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ClientStream
* @param ClientStreamingCall $clientStreamingCall The gRPC client streaming call object
* @param array $streamingDescriptor
*/
public function __construct( // @phpstan-ignore-line
public function __construct(// @phpstan-ignore-line
ClientStreamingCall $clientStreamingCall,
array $streamingDescriptor = []
) {
Expand Down
9 changes: 3 additions & 6 deletions src/CredentialsWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,15 @@
use DomainException;
use Exception;
use Google\Auth\ApplicationDefaultCredentials;
use Google\Auth\ProjectIdProviderInterface;
use Google\Auth\Cache\MemoryCacheItemPool;
use Google\Auth\Credentials\GCECredentials;
use Google\Auth\Credentials\ServiceAccountCredentials;
use Google\Auth\CredentialsLoader;
use Google\Auth\FetchAuthTokenCache;
use Google\Auth\FetchAuthTokenInterface;
use Google\Auth\GetQuotaProjectInterface;
use Google\Auth\GetUniverseDomainInterface;
use Google\Auth\Credentials\GCECredentials;
use Google\Auth\HttpHandler\Guzzle6HttpHandler;
use Google\Auth\HttpHandler\Guzzle7HttpHandler;
use Google\Auth\HttpHandler\HttpHandlerFactory;
use Google\Auth\ProjectIdProviderInterface;
use Google\Auth\UpdateMetadataInterface;
use Psr\Cache\CacheItemPoolInterface;

Expand Down Expand Up @@ -335,7 +332,7 @@ private static function buildApplicationDefaultCredentials(
$defaultScopes
);
} catch (DomainException $ex) {
throw new ValidationException("Could not construct ApplicationDefaultCredentials", $ex->getCode(), $ex);
throw new ValidationException('Could not construct ApplicationDefaultCredentials', $ex->getCode(), $ex);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/FixedSizeCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function __construct(Page $initialPage, int $collectionSize)
if ($collectionSize < $initialPage->getPageElementCount()) {
$ipc = $initialPage->getPageElementCount();
throw new InvalidArgumentException(
"collectionSize must be greater than or equal to the number of " .
'collectionSize must be greater than or equal to the number of ' .
"elements in initialPage. collectionSize: $collectionSize, " .
"initialPage size: $ipc"
);
Expand Down Expand Up @@ -178,8 +178,8 @@ private static function createPageArray(Page $initialPage, int $collectionSize)
$currentPage = $currentPage->getNextPage($remainingCount);
$rxElementCount = $currentPage->getPageElementCount();
if ($rxElementCount > $remainingCount) {
throw new LengthException("API returned a number of elements " .
"exceeding the specified page size limit. page size: " .
throw new LengthException('API returned a number of elements ' .
'exceeding the specified page size limit. page size: ' .
"$remainingCount, elements received: $rxElementCount");
}
array_push($pageList, $currentPage);
Expand Down
1 change: 0 additions & 1 deletion src/Middleware/CredentialsWrapperMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

use Google\ApiCore\Call;
use Google\ApiCore\CredentialsWrapper;
use GuzzleHttp\Promise\PromiseInterface;

/**
* Middleware which adds a CredentialsWrapper object to the call options.
Expand Down
1 change: 0 additions & 1 deletion src/Middleware/FixedHeaderMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
namespace Google\ApiCore\Middleware;

use Google\ApiCore\Call;
use GuzzleHttp\Promise\PromiseInterface;

/**
* Middleware to add fixed headers to an API call.
Expand Down
4 changes: 2 additions & 2 deletions src/Middleware/MiddlewareInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@

namespace Google\ApiCore\Middleware;

use Google\ApiCore\BidiStream;
use Google\ApiCore\Call;
use GuzzleHttp\Promise\PromiseInterface;
use Google\ApiCore\ClientStream;
use Google\ApiCore\ServerStream;
use Google\ApiCore\BidiStream;
use GuzzleHttp\Promise\PromiseInterface;

/**
* Middlewares must take a MiddlewareInterface as their first constructor
Expand Down
1 change: 0 additions & 1 deletion src/Middleware/OperationsMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
use Google\ApiCore\Call;
use Google\ApiCore\OperationResponse;
use Google\Protobuf\Internal\Message;
use GuzzleHttp\Promise\PromiseInterface;

/**
* Middleware which wraps the response in an OperationResponse object.
Expand Down
1 change: 0 additions & 1 deletion src/Middleware/OptionsFilterMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

use Google\ApiCore\ArrayTrait;
use Google\ApiCore\Call;
use GuzzleHttp\Promise\PromiseInterface;

/**
* Middleware which filters the $options array.
Expand Down
1 change: 0 additions & 1 deletion src/Middleware/PagedMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
use Google\ApiCore\PagedListResponse;
use Google\ApiCore\PageStreamingDescriptor;
use Google\Protobuf\Internal\Message;
use GuzzleHttp\Promise\PromiseInterface;

/**
* Middleware which wraps the response in an PagedListResponses object.
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/RequestAutoPopulationMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function __invoke(Call $call, array $options)
break;
default:
throw new \UnexpectedValueException(sprintf(
"Value type %s::%s not supported for auto population of the field %s",
'Value type %s::%s not supported for auto population of the field %s',
Format::class,
Format::name($valueType),
$fieldName
Expand Down
6 changes: 3 additions & 3 deletions src/OperationResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@

namespace Google\ApiCore;

use Google\LongRunning\Client\OperationsClient;
use Google\LongRunning\OperationsClient as LegacyOperationsClient;
use Google\LongRunning\CancelOperationRequest;
use Google\LongRunning\Client\OperationsClient;
use Google\LongRunning\DeleteOperationRequest;
use Google\LongRunning\GetOperationRequest;
use Google\LongRunning\Operation;
use Google\LongRunning\OperationsClient as LegacyOperationsClient;
use Google\Protobuf\Any;
use Google\Protobuf\Internal\Message;
use Google\Rpc\Status;
Expand Down Expand Up @@ -272,7 +272,7 @@ public function pollUntilComplete(array $options = [])
public function reload()
{
if ($this->deleted) {
throw new ValidationException("Cannot call reload() on a deleted operation");
throw new ValidationException('Cannot call reload() on a deleted operation');
}

$requestClass = $this->isNewSurfaceOperationsClient() ? $this->getOperationRequest : null;
Expand Down
2 changes: 1 addition & 1 deletion src/Options/ClientOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@

use ArrayAccess;
use Closure;
use InvalidArgumentException;
use Google\ApiCore\CredentialsWrapper;
use Google\ApiCore\Transport\TransportInterface;
use Google\Auth\FetchAuthTokenInterface;
use InvalidArgumentException;

/**
* The ClientOptions class adds typing to the associative array of options
Expand Down
2 changes: 1 addition & 1 deletion src/Options/OptionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

namespace Google\ApiCore\Options;

use Google\ApiCore\ValidationException;
use BadMethodCallException;
use Google\ApiCore\ValidationException;

/**
* Trait implemented by any class representing an associative array of PHP options.
Expand Down
4 changes: 2 additions & 2 deletions src/Options/TransportOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@

namespace Google\ApiCore\Options;

use Google\ApiCore\Options\TransportOptions\GrpcTransportOptions;
use ArrayAccess;
use Google\ApiCore\Options\TransportOptions\GrpcFallbackTransportOptions;
use Google\ApiCore\Options\TransportOptions\GrpcTransportOptions;
use Google\ApiCore\Options\TransportOptions\RestTransportOptions;
use ArrayAccess;

class TransportOptions implements ArrayAccess
{
Expand Down
2 changes: 1 addition & 1 deletion src/Options/TransportOptions/GrpcTransportOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
use ArrayAccess;
use Closure;
use Google\ApiCore\Options\OptionsTrait;
use Google\ApiCore\Transport\Grpc\UnaryInterceptorInterface;
use Grpc\Channel;
use Grpc\Interceptor;
use Google\ApiCore\Transport\Grpc\UnaryInterceptorInterface;

/**
* The GrpcTransportOptions class provides typing to the associative array of options used to
Expand Down
20 changes: 10 additions & 10 deletions src/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
*/
class Page implements IteratorAggregate
{
const FINAL_PAGE_TOKEN = "";
const FINAL_PAGE_TOKEN = '';

private $call;
private $callable;
Expand Down Expand Up @@ -243,26 +243,26 @@ public function expandToFixedSizeCollection($collectionSize)
{
if (!$this->pageStreamingDescriptor->requestHasPageSizeField()) {
throw new ValidationException(
"FixedSizeCollection is not supported for this method, because " .
"the method does not support an optional argument to set the " .
"page size."
'FixedSizeCollection is not supported for this method, because ' .
'the method does not support an optional argument to set the ' .
'page size.'
);
}
$request = $this->getRequestObject();
$pageSizeGetMethod = $this->pageStreamingDescriptor->getRequestPageSizeGetMethod();
$pageSize = $request->$pageSizeGetMethod();
if (is_null($pageSize)) {
throw new ValidationException(
"Error while expanding Page to FixedSizeCollection: No page size " .
"parameter found. The page size parameter must be set in the API " .
"optional arguments array, and must be less than the collectionSize " .
"parameter, in order to create a FixedSizeCollection object."
'Error while expanding Page to FixedSizeCollection: No page size ' .
'parameter found. The page size parameter must be set in the API ' .
'optional arguments array, and must be less than the collectionSize ' .
'parameter, in order to create a FixedSizeCollection object.'
);
}
if ($pageSize > $collectionSize) {
throw new ValidationException(
"Error while expanding Page to FixedSizeCollection: collectionSize " .
"parameter is less than the page size optional argument specified in " .
'Error while expanding Page to FixedSizeCollection: collectionSize ' .
'parameter is less than the page size optional argument specified in ' .
"the API call. collectionSize: $collectionSize, page size: $pageSize"
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/RequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function build(string $path, Message $message, array $headers = [])

// Request enum fields will be encoded as numbers rather than strings (in the response).
if ($numericEnums) {
$queryParams['$alt'] = "json;enum-encoding=int";
$queryParams['$alt'] = 'json;enum-encoding=int';
}

$uri = $this->buildUri($pathTemplate, $queryParams);
Expand All @@ -132,8 +132,8 @@ public function build(string $path, Message $message, array $headers = [])
}

throw new ValidationException("Could not map bindings for $path to any Uri template.\n" .
"Bindings: " . print_r($bindings, true) .
"UriTemplates: " . print_r($uriTemplates, true));
'Bindings: ' . print_r($bindings, true) .
'UriTemplates: ' . print_r($uriTemplates, true));
}

/**
Expand Down
Loading