diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 907e2b3a85..fe390624bd 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -6,17 +6,20 @@ on: pull_request: jobs: - styles: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Install PHP - uses: shivammathur/setup-php@v2 - with: - php-version: '8.2' - - name: Run Script - run: testing/run_cs_check.sh + style: + name: PHP Style Check + uses: GoogleCloudPlatform/php-tools/.github/workflows/code-standards.yml@main + with: + add_rules: | + { + "method_argument_space": { + "keep_multiple_spaces_after_comma": true, + "on_multiline": "ignore" + }, + "ordered_imports": false, + "new_with_parentheses": false + } staticanalysis: runs-on: ubuntu-latest diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php deleted file mode 100644 index b2adc48a14..0000000000 --- a/.php-cs-fixer.dist.php +++ /dev/null @@ -1,42 +0,0 @@ -setRules([ - '@PSR2' => true, - 'concat_space' => ['spacing' => 'one'], - 'no_unused_imports' => true, - 'whitespace_after_comma_in_array' => true, - 'method_argument_space' => [ - 'keep_multiple_spaces_after_comma' => true, - 'on_multiline' => 'ignore' - ], - 'return_type_declaration' => [ - 'space_before' => 'none' - ], - // only converts simple strings in double quotes to single quotes - // ignores strings using variables, escape characters or single quotes inside - 'single_quote' => true, - // there should be a single space b/w the cast and it's operand - 'cast_spaces' => ['space' => 'single'], - // there shouldn't be any trailing whitespace at the end of a non-blank line - 'no_trailing_whitespace' => true, - // there shouldn't be any trailing whitespace at the end of a blank line - 'no_whitespace_in_blank_line' => true, - // there should be a space around binary operators like (=, => etc) - 'binary_operator_spaces' => ['default' => 'single_space'], - // deals with rogue empty blank lines - 'no_extra_blank_lines' => ['tokens' => ['extra']], - // reduces multi blank lines b/w phpdoc description and @param to a single line - // NOTE: Doesn't add a blank line if none exist - 'phpdoc_trim_consecutive_blank_line_separation' => true, - ]) - ->setFinder( - PhpCsFixer\Finder::create() - ->in(__DIR__) - ) -; - -return $config; diff --git a/appengine/flexible/memcache/app.php b/appengine/flexible/memcache/app.php index 37d37b2300..1597133639 100644 --- a/appengine/flexible/memcache/app.php +++ b/appengine/flexible/memcache/app.php @@ -56,7 +56,7 @@ 'MEMCACHE_PORT_11211_TCP_ADDR', 'MEMCACHE_PORT_11211_TCP_PORT' ]; - $lines = array(); + $lines = []; foreach ($vars as $var) { $val = getenv($var); array_push($lines, "$var = $val"); diff --git a/appengine/flexible/memcache/test/DeployTest.php b/appengine/flexible/memcache/test/DeployTest.php index a2b6ce2317..51ba2074e5 100644 --- a/appengine/flexible/memcache/test/DeployTest.php +++ b/appengine/flexible/memcache/test/DeployTest.php @@ -71,7 +71,7 @@ private function put($path, $body) { $url = join('/', [trim(self::$gcloudWrapper->getBaseUrl(), '/'), trim($path, '/')]); - $request = new \GuzzleHttp\Psr7\Request('PUT', $url, array(), $body); + $request = new \GuzzleHttp\Psr7\Request('PUT', $url, [], $body); $this->client->send($request); } diff --git a/appengine/flexible/metadata/app.php b/appengine/flexible/metadata/app.php index bc355f73c1..9325b4a3b2 100644 --- a/appengine/flexible/metadata/app.php +++ b/appengine/flexible/metadata/app.php @@ -35,7 +35,7 @@ function get_external_ip_using_curl() $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Metadata-Flavor: Google')); + curl_setopt($ch, CURLOPT_HTTPHEADER, ['Metadata-Flavor: Google']); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); return curl_exec($ch); } diff --git a/appengine/flexible/supervisord/replacement/index.php b/appengine/flexible/supervisord/replacement/index.php index 88d346ca68..8c39dc2deb 100644 --- a/appengine/flexible/supervisord/replacement/index.php +++ b/appengine/flexible/supervisord/replacement/index.php @@ -13,9 +13,9 @@ $server = new Server(function (ServerRequestInterface $request) { return new Response( 200, - array( + [ 'Content-Type' => 'text/plain' - ), + ], "Hello World!\n" ); }); diff --git a/appengine/standard/getting-started/src/CloudSqlDataModel.php b/appengine/standard/getting-started/src/CloudSqlDataModel.php index 33f858d472..14e553e3e1 100644 --- a/appengine/standard/getting-started/src/CloudSqlDataModel.php +++ b/appengine/standard/getting-started/src/CloudSqlDataModel.php @@ -35,7 +35,7 @@ public function __construct(PDO $pdo) { $this->pdo = $pdo; - $columns = array( + $columns = [ 'id serial PRIMARY KEY ', 'title VARCHAR(255)', 'author VARCHAR(255)', @@ -44,7 +44,7 @@ public function __construct(PDO $pdo) 'description VARCHAR(255)', 'created_by VARCHAR(255)', 'created_by_id VARCHAR(255)', - ); + ]; $this->columnNames = array_map(function ($columnDefinition) { return explode(' ', $columnDefinition)[0]; @@ -83,7 +83,7 @@ public function listBooks($limit = 10, $cursor = 0) // while ($row = $statement->fetch(PDO::FETCH_ASSOC)) { // var_dump($row); // } - $rows = array(); + $rows = []; $nextCursor = null; while ($row = $statement->fetch(PDO::FETCH_ASSOC)) { array_push($rows, $row); diff --git a/appengine/standard/getting-started/src/controllers.php b/appengine/standard/getting-started/src/controllers.php index c17ae9e9c0..e62977da57 100644 --- a/appengine/standard/getting-started/src/controllers.php +++ b/appengine/standard/getting-started/src/controllers.php @@ -46,7 +46,7 @@ $app->get('/books/add', function (Request $request, Response $response) use ($container) { return $container->get('view')->render($response, 'form.html.twig', [ 'action' => 'Add', - 'book' => array(), + 'book' => [], ]); }); diff --git a/appengine/standard/getting-started/test/CloudSqlTest.php b/appengine/standard/getting-started/test/CloudSqlTest.php index d9ba1dd447..c806f7a89f 100644 --- a/appengine/standard/getting-started/test/CloudSqlTest.php +++ b/appengine/standard/getting-started/test/CloudSqlTest.php @@ -56,7 +56,7 @@ public function testDataModel() { $model = $this->model; // Iterate over the existing books and count the rows. - $fetch = array('cursor' => null); + $fetch = ['cursor' => null]; $rowCount = 0; do { $fetch = $model->listBooks(10, $fetch['cursor']); @@ -64,23 +64,23 @@ public function testDataModel() } while ($fetch['cursor']); // Insert two books. - $breakfastId = $model->create(array( + $breakfastId = $model->create([ 'title' => 'Breakfast of Champions', 'author' => 'Kurt Vonnegut', 'published_date' => 'April 20th, 2016' - )); + ]); - $bellId = $model->create(array( + $bellId = $model->create([ 'title' => 'For Whom the Bell Tolls', 'author' => 'Ernest Hemingway' - )); + ]); // Try to create a book with a bad property name. try { - $model->create(array( + $model->create([ 'bogus' => 'Teach your owl to drive!' - )); + ]); $this->fail('Should have thrown exception'); } catch (\Exception $e) { // Good. An exception is expected. diff --git a/appengine/standard/metadata/index.php b/appengine/standard/metadata/index.php index 77734f8a79..cdc6a06d21 100644 --- a/appengine/standard/metadata/index.php +++ b/appengine/standard/metadata/index.php @@ -53,7 +53,7 @@ function request_metadata_using_curl($metadataKey) $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Metadata-Flavor: Google')); + curl_setopt($ch, CURLOPT_HTTPHEADER, ['Metadata-Flavor: Google']); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); return curl_exec($ch); diff --git a/cdn/test/signUrlTest.php b/cdn/test/signUrlTest.php index 68988eb98c..42f1d9b5b0 100644 --- a/cdn/test/signUrlTest.php +++ b/cdn/test/signUrlTest.php @@ -45,14 +45,14 @@ public function testSignUrl() { $encoded_key = 'nZtRohdNF9m3cKM24IcK4w=='; // base64url encoded key - $cases = array( - array('http://35.186.234.33/index.html', 'my-key', 1558131350, - 'http://35.186.234.33/index.html?Expires=1558131350&KeyName=my-key&Signature=fm6JZSmKNsB5sys8VGr-JE4LiiE='), - array('https://www.google.com/', 'my-key', 1549751401, - 'https://www.google.com/?Expires=1549751401&KeyName=my-key&Signature=M_QO7BGHi2sGqrJO-MDr0uhDFuc='), - array('https://www.example.com/some/path?some=query&another=param', 'my-key', 1549751461, - 'https://www.example.com/some/path?some=query&another=param&Expires=1549751461&KeyName=my-key&Signature=sTqqGX5hUJmlRJ84koAIhWW_c3M='), - ); + $cases = [ + ['http://35.186.234.33/index.html', 'my-key', 1558131350, + 'http://35.186.234.33/index.html?Expires=1558131350&KeyName=my-key&Signature=fm6JZSmKNsB5sys8VGr-JE4LiiE='], + ['https://www.google.com/', 'my-key', 1549751401, + 'https://www.google.com/?Expires=1549751401&KeyName=my-key&Signature=M_QO7BGHi2sGqrJO-MDr0uhDFuc='], + ['https://www.example.com/some/path?some=query&another=param', 'my-key', 1549751461, + 'https://www.example.com/some/path?some=query&another=param&Expires=1549751461&KeyName=my-key&Signature=sTqqGX5hUJmlRJ84koAIhWW_c3M='], + ]; foreach ($cases as $c) { $this->assertEquals(sign_url($c[0], $c[1], $encoded_key, $c[2]), $c[3]); diff --git a/compute/firewall/src/print_firewall_rule.php b/compute/firewall/src/print_firewall_rule.php index d91ab44cfd..bab5a7bc5e 100644 --- a/compute/firewall/src/print_firewall_rule.php +++ b/compute/firewall/src/print_firewall_rule.php @@ -56,12 +56,12 @@ function print_firewall_rule(string $projectId, string $firewallRuleName) print('--Allowed--' . PHP_EOL); foreach ($response->getAllowed() as $item) { printf('Protocol: %s' . PHP_EOL, $item->getIPProtocol()); - foreach ($item->getPorts()as $ports) { + foreach ($item->getPorts() as $ports) { printf(' - Ports: %s' . PHP_EOL, $ports); } } print('--Source Ranges--' . PHP_EOL); - foreach ($response->getSourceRanges()as $ranges) { + foreach ($response->getSourceRanges() as $ranges) { printf(' - Range: %s' . PHP_EOL, $ranges); } } diff --git a/compute/instances/src/set_usage_export_bucket.php b/compute/instances/src/set_usage_export_bucket.php index cf95472b5c..d69126fe1c 100644 --- a/compute/instances/src/set_usage_export_bucket.php +++ b/compute/instances/src/set_usage_export_bucket.php @@ -48,10 +48,10 @@ function set_usage_export_bucket( string $reportNamePrefix = '' ) { // Initialize UsageExportLocation object with provided bucket name and no report name prefix. - $usageExportLocation = new UsageExportLocation(array( + $usageExportLocation = new UsageExportLocation([ 'bucket_name' => $bucketName, 'report_name_prefix' => $reportNamePrefix - )); + ]); if (strlen($reportNamePrefix) == 0) { // Sending empty value for report_name_prefix results in the next usage report diff --git a/compute/instances/src/start_instance_with_encryption_key.php b/compute/instances/src/start_instance_with_encryption_key.php index e3f8e1e4d2..6201e0d990 100644 --- a/compute/instances/src/start_instance_with_encryption_key.php +++ b/compute/instances/src/start_instance_with_encryption_key.php @@ -75,7 +75,7 @@ function start_instance_with_encryption_key( // Set request with one disk. $instancesStartWithEncryptionKeyRequest = (new InstancesStartWithEncryptionKeyRequest()) - ->setDisks(array($diskData)); + ->setDisks([$diskData]); // Start the instance with encrypted disk. $request2 = (new StartWithEncryptionKeyInstanceRequest()) diff --git a/compute/logging/index.php b/compute/logging/index.php index f389f2c92e..72dc6d12f8 100644 --- a/compute/logging/index.php +++ b/compute/logging/index.php @@ -26,11 +26,11 @@ function fluentd_exception_handler(Exception $e) { global $logger; - $msg = array( + $msg = [ 'message' => $e->getMessage(), - 'serviceContext' => array('service' => 'myapp'), + 'serviceContext' => ['service' => 'myapp'], // ... add more metadata - ); + ]; $logger->post('myapp.errors', $msg); } diff --git a/datastore/api/src/run_projection_query.php b/datastore/api/src/run_projection_query.php index 3b5e877d00..77519e91c1 100644 --- a/datastore/api/src/run_projection_query.php +++ b/datastore/api/src/run_projection_query.php @@ -36,8 +36,8 @@ function run_projection_query(Query $query = null, string $namespaceId = null) } // [START datastore_run_query_projection] - $priorities = array(); - $percentCompletes = array(); + $priorities = []; + $percentCompletes = []; $result = $datastore->runQuery($query); /* @var Entity $task */ foreach ($result as $task) { @@ -46,7 +46,7 @@ function run_projection_query(Query $query = null, string $namespaceId = null) } // [END datastore_run_query_projection] - print_r(array($priorities, $percentCompletes)); + print_r([$priorities, $percentCompletes]); } // The following 2 lines are only needed to run the samples diff --git a/dialogflow/test/entityTypeTest.php b/dialogflow/test/entityTypeTest.php index 0a64bbd704..d39e0b4bc9 100644 --- a/dialogflow/test/entityTypeTest.php +++ b/dialogflow/test/entityTypeTest.php @@ -42,7 +42,7 @@ public function testCreateEntityType() $this->assertStringContainsString(self::$entityTypeDisplayName, $output); - $response = str_replace(array("\r", "\n"), '', $response); + $response = str_replace(["\r", "\n"], '', $response); $response = explode('/', $response); $entityTypeId = end($response); return $entityTypeId; diff --git a/dialogflow/test/intentTest.php b/dialogflow/test/intentTest.php index eddd195e40..6463067f87 100644 --- a/dialogflow/test/intentTest.php +++ b/dialogflow/test/intentTest.php @@ -46,7 +46,7 @@ public function testCreateIntent() $this->assertStringContainsString(self::$displayName, $output); - $response = str_replace(array("\r", "\n"), '', $response); + $response = str_replace(["\r", "\n"], '', $response); $response = explode('/', $response); $intentId = end($response); return $intentId; diff --git a/dialogflow/test/sessionEntityTypeTest.php b/dialogflow/test/sessionEntityTypeTest.php index 3e90e98672..3f3023da95 100644 --- a/dialogflow/test/sessionEntityTypeTest.php +++ b/dialogflow/test/sessionEntityTypeTest.php @@ -51,7 +51,7 @@ public function testCreateSessionEntityType() $this->assertStringContainsString(self::$entityTypeDisplayName, $output); - $response = str_replace(array("\r", "\n"), '', $response); + $response = str_replace(["\r", "\n"], '', $response); $response = explode('/', $response); $entityTypeId = end($response); return $entityTypeId; diff --git a/firestore/src/data_set_from_map_nested.php b/firestore/src/data_set_from_map_nested.php index 856fe67e9c..74f8ab3c64 100644 --- a/firestore/src/data_set_from_map_nested.php +++ b/firestore/src/data_set_from_map_nested.php @@ -46,7 +46,7 @@ function data_set_from_map_nested(string $projectId): void 'booleanExample' => true, 'numberExample' => 3.14159265, 'dateExample' => new Timestamp(new DateTime()), - 'arrayExample' => array(5, true, 'hello'), + 'arrayExample' => [5, true, 'hello'], 'nullExample' => null, 'objectExample' => ['a' => 5, 'b' => true], 'documentReferenceExample' => $db->collection('samples/php/data')->document('two'), diff --git a/functions/firebase_analytics/test/IntegrationTest.php b/functions/firebase_analytics/test/IntegrationTest.php index 88d83ccf00..a42edeef98 100644 --- a/functions/firebase_analytics/test/IntegrationTest.php +++ b/functions/firebase_analytics/test/IntegrationTest.php @@ -49,10 +49,10 @@ public function dataProvider() 'type' => 'google.firebase.remoteconfig.v1.updated', 'data' => [ // eventDim is a list of dictionaries - 'eventDim' => array([ + 'eventDim' => [[ 'name' => 'test_event', 'timestampMicros' => time() * 1000, - ]), + ]], 'userDim' => [ 'geoInfo' => [ 'city' => 'San Francisco', diff --git a/functions/firebase_firestore/test/IntegrationTest.php b/functions/firebase_firestore/test/IntegrationTest.php index c7bce4862a..a0d72e554d 100644 --- a/functions/firebase_firestore/test/IntegrationTest.php +++ b/functions/firebase_firestore/test/IntegrationTest.php @@ -49,8 +49,8 @@ public function dataProvider() 'type' => 'google.cloud.firestore.document.v1.created', 'data' => [ 'resource' => 'projects/_/instances/my-instance/refs/messages', - 'oldValue' => array('old' => 'value'), - 'value' => array('new' => 'value'), + 'oldValue' => ['old' => 'value'], + 'value' => ['new' => 'value'], ], ]), 'statusCode' => '200', diff --git a/functions/slack_slash_command/index.php b/functions/slack_slash_command/index.php index d87a11de1f..4d41b0cbca 100644 --- a/functions/slack_slash_command/index.php +++ b/functions/slack_slash_command/index.php @@ -88,7 +88,7 @@ function formatSlackMessage(Google_Service_Kgsearch_SearchResponse $kgResponse, $attachmentJson['image_url'] = $imageJson['contentUrl']; } - $responseJson['attachments'] = array($attachmentJson); + $responseJson['attachments'] = [$attachmentJson]; return json_encode($responseJson); } diff --git a/kms/test/kmsTest.php b/kms/test/kmsTest.php index 4fbd78effa..abb7b6b9d8 100644 --- a/kms/test/kmsTest.php +++ b/kms/test/kmsTest.php @@ -423,10 +423,10 @@ public function testDestroyRestoreKeyVersion() ]); $this->assertStringContainsString('Destroyed key version', $output); - $this->assertContains($version->getState(), array( + $this->assertContains($version->getState(), [ CryptoKeyVersionState::DESTROYED, CryptoKeyVersionState::DESTROY_SCHEDULED, - )); + ]); list($version, $output) = $this->runFunctionSnippet('restore_key_version', [ self::$projectId, diff --git a/spanner/src/dml_batch_update_request_priority.php b/spanner/src/dml_batch_update_request_priority.php index 9b366a8919..57fddd0a22 100644 --- a/spanner/src/dml_batch_update_request_priority.php +++ b/spanner/src/dml_batch_update_request_priority.php @@ -68,7 +68,7 @@ function dml_batch_update_request_priority(string $instanceId, string $databaseI . 'SET MarketingBudget = MarketingBudget * 2 ' . 'WHERE SingerId = 2 and AlbumId = 3' ], - ], array('priority' => $priority)); + ], ['priority' => $priority]); $t->commit(); $rowCounts = count($result->rowCounts()); printf('Executed %s SQL statements using Batch DML with PRIORITY_LOW.' . PHP_EOL, diff --git a/testing/run_cs_check.sh b/testing/run_cs_check.sh deleted file mode 100755 index 69b7199c98..0000000000 --- a/testing/run_cs_check.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash -# Copyright 2016 Google Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -ex - -PROJECT_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/.." -DIR="${1:-$PROJECT_ROOT}" - -# we run the script from PROJECT_ROOT -cd "$PROJECT_ROOT" - -# install local version of php-cs-fixer 3.0 from composer.json -composer -q install -d testing/ - -# run php-cs-fixer -PHP_CS_FIXER="php-cs-fixer" -if [ -f "testing/vendor/bin/php-cs-fixer" ]; then - PHP_CS_FIXER="testing/vendor/bin/php-cs-fixer" -fi - -$PHP_CS_FIXER fix --dry-run --diff --config="${PROJECT_ROOT}/.php-cs-fixer.dist.php" --path-mode=intersection "$DIR" diff --git a/texttospeech/quickstart.php b/texttospeech/quickstart.php index 375781b657..d9426f0e7c 100644 --- a/texttospeech/quickstart.php +++ b/texttospeech/quickstart.php @@ -47,7 +47,7 @@ // select the type of audio file you want returned $audioConfig = (new AudioConfig()) ->setAudioEncoding(AudioEncoding::MP3) - ->setEffectsProfileId(array($effectsProfileId)); + ->setEffectsProfileId([$effectsProfileId]); // perform text-to-speech request on the text input with selected voice // parameters and audio file type diff --git a/texttospeech/src/synthesize_text_effects_profile.php b/texttospeech/src/synthesize_text_effects_profile.php index 2517961289..5af3d8138a 100644 --- a/texttospeech/src/synthesize_text_effects_profile.php +++ b/texttospeech/src/synthesize_text_effects_profile.php @@ -53,7 +53,7 @@ function synthesize_text_effects_profile(string $text, string $effectsProfileId) // define effects profile id. $audioConfig = (new AudioConfig()) ->setAudioEncoding(AudioEncoding::MP3) - ->setEffectsProfileId(array($effectsProfileId)); + ->setEffectsProfileId([$effectsProfileId]); $request = (new SynthesizeSpeechRequest()) ->setInput($inputText) ->setVoice($voice) diff --git a/texttospeech/src/synthesize_text_effects_profile_file.php b/texttospeech/src/synthesize_text_effects_profile_file.php index a437bcd4bd..87793c61dd 100644 --- a/texttospeech/src/synthesize_text_effects_profile_file.php +++ b/texttospeech/src/synthesize_text_effects_profile_file.php @@ -54,7 +54,7 @@ function synthesize_text_effects_profile_file(string $path, string $effectsProfi $audioConfig = (new AudioConfig()) ->setAudioEncoding(AudioEncoding::MP3) - ->setEffectsProfileId(array($effectsProfileId)); + ->setEffectsProfileId([$effectsProfileId]); $request = (new SynthesizeSpeechRequest()) ->setInput($inputText) ->setVoice($voice)