Skip to content

Commit ebc9c26

Browse files
feat: new rules for php-cs-fixer (GoogleCloudPlatform#1533)
1 parent 62f55c2 commit ebc9c26

File tree

188 files changed

+517
-491
lines changed

Some content is hidden

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

188 files changed

+517
-491
lines changed

.kokoro/secrets-example.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ export POSTGRES_DSN=
6060
export POSTGRES_DATABASE=
6161
export POSTGRES_USER=
6262
export POSTGRES_PASSWORD=
63+
export SQLSERVER_DSN=
64+
export SQLSERVER_DATABASE=
65+
export SQLSERVER_USER=
66+
export SQLSERVER_PASSWORD=
67+
export DB_SOCKET_DIR=
6368

6469
# Datastore
6570
export CLOUD_DATASTORE_NAMESPACE=

.php-cs-fixer.dist.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@
1616
'return_type_declaration' => [
1717
'space_before' => 'none'
1818
],
19+
// only converts simple strings in double quotes to single quotes
20+
// ignores strings using variables, escape characters or single quotes inside
21+
'single_quote' => true,
22+
// there should be a single space b/w the cast and it's operand
23+
'cast_spaces' => ['space' => 'single'],
24+
// there shouldn't be any trailing whitespace at the end of a non-blank line
25+
'no_trailing_whitespace' => true,
26+
// there shouldn't be any trailing whitespace at the end of a blank line
27+
'no_whitespace_in_blank_line' => true,
28+
// there should be a space around binary operators like (=, => etc)
29+
'binary_operator_spaces' => ['default' => 'single_space'],
30+
// deals with rogue empty blank lines
31+
'no_extra_blank_lines' => ['tokens' => ['extra']],
32+
// reduces multi blank lines b/w phpdoc description and @param to a single line
33+
// NOTE: Doesn't add a blank line if none exist
34+
'phpdoc_trim_consecutive_blank_line_separation' => true,
1935
])
2036
->setFinder(
2137
PhpCsFixer\Finder::create()

analyticsdata/quickstart_json_credentials.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
*/
4444
$property_id = 'YOUR-GA4-PROPERTY-ID';
4545

46-
4746
// [START analyticsdata_json_credentials_initialize]
4847
/* TODO(developer): Replace this variable with a valid path to the
4948
* credentials.json file for your service account downloaded from the

appengine/flexible/datastore/app.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
$entity['user_ip']);
7373
}
7474
# [END gae_flex_datastore_query]
75-
array_unshift($visits, "Last 10 visits:");
75+
array_unshift($visits, 'Last 10 visits:');
7676
$response->getBody()->write(implode("\n", $visits));
7777

7878
return $response

appengine/flexible/datastore/test/DeployTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ public function testIndex()
3030
$this->assertEquals('200', $resp->getStatusCode(),
3131
'top page status code');
3232

33-
$this->assertStringContainsString("Last 10 visits:", (string) $resp->getBody());
33+
$this->assertStringContainsString('Last 10 visits:', (string) $resp->getBody());
3434
}
3535
}

appengine/flexible/datastore/test/LocalTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ public function testIndex()
3333
$response = $app->handle($request);
3434
$this->assertEquals(200, $response->getStatusCode());
3535
$text = (string) $response->getBody();
36-
$this->assertStringContainsString("Last 10 visits:", $text);
36+
$this->assertStringContainsString('Last 10 visits:', $text);
3737
}
3838
}

appengine/flexible/logging/test/DeployTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function testIndex()
4141
$this->assertEquals('200', $resp->getStatusCode(),
4242
'top page status code');
4343

44-
$this->assertStringContainsString("Logs:", (string) $resp->getBody());
44+
$this->assertStringContainsString('Logs:', (string) $resp->getBody());
4545
}
4646
public function testAsyncLog()
4747
{

appengine/flexible/logging/test/LocalTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function testSomeLogs()
3333

3434
$this->assertEquals(200, $response->getStatusCode());
3535
$text = (string) $response->getBody();
36-
$this->assertStringContainsString("Logs:", $text);
36+
$this->assertStringContainsString('Logs:', $text);
3737
}
3838

3939
public function testAsyncLog()

appengine/flexible/memcache/test/DeployTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ public function testIndex()
5050
$key = rand(0, 1000);
5151

5252
// Test the /memcached REST API.
53-
$this->put("/memcached/test$key", "sour");
54-
$this->assertEquals("sour", $this->get("/memcached/test$key"));
55-
$this->put("/memcached/test$key", "sweet");
56-
$this->assertEquals("sweet", $this->get("/memcached/test$key"));
53+
$this->put("/memcached/test$key", 'sour');
54+
$this->assertEquals('sour', $this->get("/memcached/test$key"));
55+
$this->put("/memcached/test$key", 'sweet');
56+
$this->assertEquals('sweet', $this->get("/memcached/test$key"));
5757

5858
// Make sure it handles a POST request too, which will increment the
5959
// counter.

appengine/flexible/memcache/test/LocalTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,26 +62,26 @@ public function testGetAndPut()
6262
// Use a random key to avoid colliding with simultaneous tests.
6363

6464
// Test the /memcached REST API.
65-
$request1 = (new RequestFactory)->createRequest('PUT', "/memcached/testkey1");
65+
$request1 = (new RequestFactory)->createRequest('PUT', '/memcached/testkey1');
6666
$request1->getBody()->write('sour');
6767
$response1 = $app->handle($request1);
6868
$this->assertEquals(200, (string) $response1->getStatusCode());
6969

7070
// Check that the key was written as expected
71-
$request2 = (new RequestFactory)->createRequest('GET', "/memcached/testkey1");
71+
$request2 = (new RequestFactory)->createRequest('GET', '/memcached/testkey1');
7272
$response2 = $app->handle($request2);
73-
$this->assertEquals("sour", (string) $response2->getBody());
73+
$this->assertEquals('sour', (string) $response2->getBody());
7474

7575
// Test the /memcached REST API with a new value.
76-
$request3 = (new RequestFactory)->createRequest('PUT', "/memcached/testkey2");
76+
$request3 = (new RequestFactory)->createRequest('PUT', '/memcached/testkey2');
7777
$request3->getBody()->write('sweet');
7878
$response3 = $app->handle($request3);
7979
$this->assertEquals(200, (string) $response3->getStatusCode());
8080

8181
// Check that the key was written as expected
82-
$request4 = (new RequestFactory)->createRequest('GET', "/memcached/testkey2");
82+
$request4 = (new RequestFactory)->createRequest('GET', '/memcached/testkey2');
8383
$response4 = $app->handle($request4);
84-
$this->assertEquals("sweet", (string) $response4->getBody());
84+
$this->assertEquals('sweet', (string) $response4->getBody());
8585
}
8686
}
8787

appengine/flexible/twilio/app.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
$app->addErrorMiddleware(true, true, true);
2929

3030
$twilioAccountSid = getenv('TWILIO_ACCOUNT_SID');
31-
$twilioAuthToken = getenv('TWILIO_AUTH_TOKEN');
31+
$twilioAuthToken = getenv('TWILIO_AUTH_TOKEN');
3232
$twilioNumber = getenv('TWILIO_FROM_NUMBER');
3333

3434
# [START gae_flex_twilio_receive_call]

appengine/flexible/websockets/socket-demo.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function onOpen(ConnectionInterface $conn)
4242

4343
public function onMessage(ConnectionInterface $from, $msg)
4444
{
45-
$output = "Message received: " . $msg . "\n";
45+
$output = 'Message received: ' . $msg . "\n";
4646
echo $output;
4747
foreach ($this->clients as $client) {
4848
$client->send($output);
@@ -59,7 +59,7 @@ public function onClose(ConnectionInterface $conn)
5959
public function onError(ConnectionInterface $conn, \Exception $e)
6060
{
6161
$conn->close();
62-
echo "Connection closed due to error: " . $e->getMessage() . "\n";
62+
echo 'Connection closed due to error: ' . $e->getMessage() . "\n";
6363
echo "\t" . $this->clients->count() . " connection(s) active.\n";
6464
}
6565
}

appengine/flexible/websockets/test/LocalTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ public function testIndex()
5454
return $endPromise;
5555
})
5656
->otherwise(function ($e) {
57-
echo "Error: " . $e->getMessage() . "\n";
57+
echo 'Error: ' . $e->getMessage() . "\n";
5858
throw $e;
5959
});
6060

6161
$this->loop->run();
6262
$resolvedMsg = Block\await($basePromise, $this->loop);
6363
$this->assertStringContainsString(
64-
"Message received: Hello World!",
64+
'Message received: Hello World!',
6565
strval($resolvedMsg)
6666
);
6767
}

appengine/flexible/wordpress/files/wp-config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
* You can have multiple installations in one database if you give each
9898
* a unique prefix. Only numbers, letters, and underscores please!
9999
*/
100-
$table_prefix = 'wp_';
100+
$table_prefix = 'wp_';
101101

102102
/**
103103
* For developers: WordPress debugging mode.

appengine/standard/errorreporting/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function throwException()
4343
print('Triggering a PHP Fatal Error by including a file with a syntax error.');
4444
print($linkText);
4545
$filename = tempnam(sys_get_temp_dir(), 'php_syntax_error');
46-
file_put_contents($filename, "");
46+
file_put_contents($filename, '');
4747
require($filename);
4848
break;
4949
default:

appengine/standard/getting-started/test/CloudSqlTest.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,36 @@
2020
use Google\Cloud\Samples\AppEngine\GettingStarted\CloudSqlDataModel;
2121
use PHPUnit\Framework\TestCase;
2222
use PDO;
23+
use Symfony\Component\Process\Process;
2324

2425
class CloudSqlTest extends TestCase
2526
{
2627
use TestTrait;
28+
private static $process;
2729

2830
public function setUp(): void
2931
{
3032
$connection = $this->requireEnv('CLOUDSQL_CONNECTION_NAME');
3133
$dbUser = $this->requireEnv('CLOUDSQL_USER');
3234
$dbPass = $this->requireEnv('CLOUDSQL_PASSWORD');
3335
$dbName = getenv('CLOUDSQL_DATABASE_NAME') ?: 'bookshelf';
34-
$socket = "/tmp/cloudsql/${connection}";
36+
$socketDir = $this->requireEnv('DB_SOCKET_DIR');
37+
$socket = "${socketDir}/${connection}";
38+
39+
// create the directory to store the unix socket for cloud_sql_proxy
40+
if (!is_dir($socketDir)) {
41+
mkdir($socketDir, 0755, true);
42+
}
43+
44+
self::$process = new Process(['cloud_sql_proxy', '-instances=' . $connection, '-dir', $socketDir]);
45+
self::$process->start();
46+
self::$process->waitUntil(function ($type, $buffer) {
47+
return str_contains($buffer, 'Ready for new connections');
48+
});
3549

3650
if (!file_exists($socket)) {
3751
$this->markTestSkipped(
38-
"You must run 'cloud_sql_proxy -instances=${connection} -dir=/cloudsql'"
52+
"You must run 'cloud_sql_proxy -instances=${connection} -dir=${socketDir}'"
3953
);
4054
}
4155
$dsn = "mysql:unix_socket=${socket};dbname=${dbName}";
@@ -46,6 +60,11 @@ public function setUp(): void
4660
$this->model = new CloudSqlDataModel($pdo);
4761
}
4862

63+
public static function tearDownAfterClass(): void
64+
{
65+
self::$process->stop();
66+
}
67+
4968
public function testDataModel()
5069
{
5170
$model = $this->model;
@@ -144,11 +163,11 @@ public function testDataModel()
144163

145164
// Clean up.
146165
$result = $model->delete($breakfastId);
147-
$this->assertTrue((bool)$result);
166+
$this->assertTrue((bool) $result);
148167
$this->assertFalse($model->read($breakfastId));
149-
$this->assertTrue((bool)$model->read($bellId));
168+
$this->assertTrue((bool) $model->read($bellId));
150169
$result = $model->delete($bellId);
151-
$this->assertTrue((bool)$result);
170+
$this->assertTrue((bool) $result);
152171
$this->assertFalse($model->read($bellId));
153172
}
154173
}

appengine/standard/grpc/monitoring.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
$r = new MonitoredResource();
4242
$r->setType('gce_instance');
4343
$r->setLabels([
44-
'instance_id' =>$instanceId,
44+
'instance_id' => $instanceId,
4545
'zone' => 'us-central1-f',
4646
]);
4747

appengine/standard/grpc/speech.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
$strm->write($strmReq);
4848

4949
$strmReq = new StreamingRecognizeRequest();
50-
$f = fopen($audioFile, "rb");
50+
$f = fopen($audioFile, 'rb');
5151
$fsize = filesize($audioFile);
5252
$bytes = fread($f, $fsize);
5353
$strmReq->setAudioContent($bytes);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
22

3-
echo "hello world!";
3+
echo 'hello world!';

bigquery/api/src/browse_table.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
list($_, $projectId, $datasetId, $tableId) = $argv;
3131
$startIndex = isset($argv[4]) ? $argv[4] : 0;
3232

33-
3433
# [START bigquery_browse_table]
3534
use Google\Cloud\BigQuery\BigQueryClient;
3635

bigquery/api/src/stream_row.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
return printf("Usage: php %s PROJECT_ID DATASET_ID TABLE_ID [DATA]\n", __FILE__);
3131
}
3232
list($_, $projectId, $datasetId, $tableId) = $argv;
33-
$data = isset($argv[4]) ? json_decode($argv[4], true) : ["field1" => "value1"];
33+
$data = isset($argv[4]) ? json_decode($argv[4], true) : ['field1' => 'value1'];
3434

3535
# [START bigquery_table_insert_rows]
3636
use Google\Cloud\BigQuery\BigQueryClient;

bigtable/src/create_cluster.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,18 @@ function create_cluster(
4848
$instanceName = $instanceAdminClient->instanceName($projectId, $instanceId);
4949
$clusterName = $instanceAdminClient->clusterName($projectId, $instanceId, $clusterId);
5050

51-
printf("Adding Cluster to Instance %s" . PHP_EOL, $instanceId);
51+
printf('Adding Cluster to Instance %s' . PHP_EOL, $instanceId);
5252
try {
5353
$instanceAdminClient->getInstance($instanceName);
5454
} catch (ApiException $e) {
5555
if ($e->getStatus() === 'NOT_FOUND') {
56-
printf("Instance %s does not exists." . PHP_EOL, $instanceId);
56+
printf('Instance %s does not exists.' . PHP_EOL, $instanceId);
5757
return;
5858
} else {
5959
throw $e;
6060
}
6161
}
62-
printf("Listing Clusters:" . PHP_EOL);
62+
printf('Listing Clusters:' . PHP_EOL);
6363

6464
$storage_type = StorageType::SSD;
6565
$serve_nodes = 3;
@@ -81,18 +81,18 @@ function create_cluster(
8181
);
8282
try {
8383
$instanceAdminClient->getCluster($clusterName);
84-
printf("Cluster %s already exists, aborting...", $clusterId);
84+
printf('Cluster %s already exists, aborting...', $clusterId);
8585
} catch (ApiException $e) {
8686
if ($e->getStatus() === 'NOT_FOUND') {
8787
$operationResponse = $instanceAdminClient->createCluster($instanceName, $clusterId, $cluster);
8888

8989
$operationResponse->pollUntilComplete();
9090
if ($operationResponse->operationSucceeded()) {
9191
$result = $operationResponse->getResult();
92-
printf("Cluster created: %s", $clusterId);
92+
printf('Cluster created: %s', $clusterId);
9393
} else {
9494
$error = $operationResponse->getError();
95-
printf("Cluster not created: %s", $error);
95+
printf('Cluster not created: %s', $error);
9696
}
9797
} else {
9898
throw $e;

bigtable/src/create_dev_instance.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function create_dev_instance(
5050
$projectName = $instanceAdminClient->projectName($projectId);
5151
$instanceName = $instanceAdminClient->instanceName($projectId, $instanceId);
5252

53-
printf("Creating a DEVELOPMENT Instance" . PHP_EOL);
53+
printf('Creating a DEVELOPMENT Instance' . PHP_EOL);
5454
// Set options to create an Instance
5555

5656
$storageType = StorageType::HDD;
@@ -78,10 +78,10 @@ function create_dev_instance(
7878
// Create development instance with given options
7979
try {
8080
$instanceAdminClient->getInstance($instanceName);
81-
printf("Instance %s already exists." . PHP_EOL, $instanceId);
81+
printf('Instance %s already exists.' . PHP_EOL, $instanceId);
8282
} catch (ApiException $e) {
8383
if ($e->getStatus() === 'NOT_FOUND') {
84-
printf("Creating a development Instance: %s" . PHP_EOL, $instanceId);
84+
printf('Creating a development Instance: %s' . PHP_EOL, $instanceId);
8585
$operationResponse = $instanceAdminClient->createInstance(
8686
$projectName,
8787
$instanceId,
@@ -92,7 +92,7 @@ function create_dev_instance(
9292
if (!$operationResponse->operationSucceeded()) {
9393
print('Error: ' . $operationResponse->getError()->getMessage());
9494
} else {
95-
printf("Instance %s created." . PHP_EOL, $instanceId);
95+
printf('Instance %s created.' . PHP_EOL, $instanceId);
9696
}
9797
} else {
9898
throw $e;

0 commit comments

Comments
 (0)