Skip to content

chore(ci): reuse style workflow from php-tools #2047

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
23 changes: 13 additions & 10 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 0 additions & 42 deletions .php-cs-fixer.dist.php

This file was deleted.

2 changes: 1 addition & 1 deletion appengine/flexible/memcache/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion appengine/flexible/memcache/test/DeployTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion appengine/flexible/metadata/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions appengine/flexible/supervisord/replacement/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
$server = new Server(function (ServerRequestInterface $request) {
return new Response(
200,
array(
[
'Content-Type' => 'text/plain'
),
],
"Hello World!\n"
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
Expand All @@ -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];
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion appengine/standard/getting-started/src/controllers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [],
]);
});

Expand Down
14 changes: 7 additions & 7 deletions appengine/standard/getting-started/test/CloudSqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,31 @@ 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']);
$rowCount += count($fetch['books']);
} 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.
Expand Down
2 changes: 1 addition & 1 deletion appengine/standard/metadata/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions cdn/test/signUrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
4 changes: 2 additions & 2 deletions compute/firewall/src/print_firewall_rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions compute/instances/src/set_usage_export_bucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
6 changes: 3 additions & 3 deletions compute/logging/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions datastore/api/src/run_projection_query.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dialogflow/test/entityTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion dialogflow/test/intentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion dialogflow/test/sessionEntityTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion firestore/src/data_set_from_map_nested.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
4 changes: 2 additions & 2 deletions functions/firebase_analytics/test/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions functions/firebase_firestore/test/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion functions/slack_slash_command/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions kms/test/kmsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion spanner/src/dml_batch_update_request_priority.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading