Skip to content

Commit 53eb405

Browse files
authored
fixes CS and adds CS check to CI (GoogleCloudPlatform#780)
1 parent 1b85789 commit 53eb405

Some content is hidden

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

41 files changed

+100
-161
lines changed

.kokoro/docker/Dockerfile.template

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ RUN apt-get update && apt-get install -y \
77
zlib1g-dev \
88
jq
99

10-
RUN git clone https://github.com/GoogleCloudPlatform/php-tools.git ${HOME}/php-tools \
11-
&& ${HOME}/php-tools/scripts/install_test_deps.sh
12-
1310
# install / enable PHP extensions
1411
RUN pecl install grpc \
1512
&& echo "extension=grpc.so" >> /opt/PHP_VERSION/lib/conf.d/ext-grpc.ini \

.kokoro/php72.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ env_vars: {
1515
key: "GOOGLE_ALT_CREDENTIALS_FILENAME"
1616
value: "service-account-php72.json"
1717
}
18+
env_vars: {
19+
key: "RUN_CS_CHECK"
20+
value: "true"
21+
}

.kokoro/system_tests.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,12 @@ mkdir -p build/logs
4444

4545
export IS_PULL_REQUEST=$KOKORO_GITHUB_PULL_REQUEST_COMMIT
4646

47+
# Run code standards check when appropriate
48+
if [ "${RUN_CS_CHECK}" = "true" ]; then
49+
curl -L https://cs.sensiolabs.org/download/php-cs-fixer-v2.phar -o php-cs-fixer \
50+
&& chmod a+x php-cs-fixer
51+
bash testing/run_cs_check.sh
52+
fi
53+
4754
# Run tests
4855
bash testing/run_test_suite.sh

appengine/php72/tasks/apps/handler/index.php

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -28,54 +28,54 @@
2828

2929
// Front-controller to route requests.
3030
switch (@parse_url($_SERVER['REQUEST_URI'])['path']) {
31-
case '/':
32-
print "Hello, World!\n";
33-
break;
34-
case '/task_handler':
35-
// Taskname and Queuename are two of several useful Cloud Tasks headers available on the request.
36-
$taskName = $_SERVER['HTTP_X_APPENGINE_TASKNAME'] ?? '';
37-
$queueName = $_SERVER['HTTP_X_APPENGINE_QUEUENAME'] ?? '';
31+
case '/':
32+
print "Hello, World!\n";
33+
break;
34+
case '/task_handler':
35+
// Taskname and Queuename are two of several useful Cloud Tasks headers available on the request.
36+
$taskName = $_SERVER['HTTP_X_APPENGINE_TASKNAME'] ?? '';
37+
$queueName = $_SERVER['HTTP_X_APPENGINE_QUEUENAME'] ?? '';
3838

39-
try {
40-
handle_task(
41-
$queueName,
42-
$taskName,
43-
file_get_contents('php://input')
44-
);
45-
} catch (Exception $e) {
46-
http_response_code(400);
47-
exit($e->getMessage());
48-
}
49-
break;
50-
default:
51-
http_response_code(404);
52-
exit('Not Found');
39+
try {
40+
handle_task(
41+
$queueName,
42+
$taskName,
43+
file_get_contents('php://input')
44+
);
45+
} catch (Exception $e) {
46+
http_response_code(400);
47+
exit($e->getMessage());
48+
}
49+
break;
50+
default:
51+
http_response_code(404);
52+
exit('Not Found');
5353
}
5454

5555
/**
5656
* Process a Cloud Tasks HTTP Request.
57-
*
57+
*
5858
* @param string $queueName provides the name of the queue which dispatched the task.
5959
* @param string $taskName provides the identifier of the task.
6060
* @param string $body The task details from the HTTP request.
6161
*/
62-
function handle_task($queueName, $taskName, $body = '')
62+
function handle_task($queueName, $taskName, $body = '')
6363
{
64-
global $logger;
64+
global $logger;
6565

66-
if (empty($taskName)) {
67-
// You may use the presence of the X-Appengine-Taskname header to validate
68-
// the request comes from Cloud Tasks.
69-
$logger->warning('Invalid Task: No X-Appengine-Taskname request header found');
70-
throw new Exception('Bad Request - Invalid Task');
71-
}
66+
if (empty($taskName)) {
67+
// You may use the presence of the X-Appengine-Taskname header to validate
68+
// the request comes from Cloud Tasks.
69+
$logger->warning('Invalid Task: No X-Appengine-Taskname request header found');
70+
throw new Exception('Bad Request - Invalid Task');
71+
}
7272

73-
$output = sprintf('Completed task: task queue(%s), task name(%s), payload(%s)', $queueName, $taskName, $body);
74-
$logger->info($output);
73+
$output = sprintf('Completed task: task queue(%s), task name(%s), payload(%s)', $queueName, $taskName, $body);
74+
$logger->info($output);
7575

76-
// Set a non-2xx status code to indicate a failure in task processing that should be retried.
77-
// For example, http_response_code(500) to indicate a server error.
78-
print $output;
76+
// Set a non-2xx status code to indicate a failure in task processing that should be retried.
77+
// For example, http_response_code(500) to indicate a server error.
78+
print $output;
7979
}
8080

8181
// [END cloud_tasks_appengine_quickstart]

appengine/php72/tasks/apps/handler/test/DeployTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public function testIndex()
3939
);
4040
}
4141

42-
public function testTaskHandlerInvalid() {
42+
public function testTaskHandlerInvalid()
43+
{
4344
$this->expectException(ClientException::class);
4445
$response = $this->client->get('/task_handler');
4546
}

appengine/php72/tasks/snippets/src/create_task.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
# [START cloud_tasks_appengine_create_task]
3333
use Google\Cloud\Tasks\V2beta3\AppEngineHttpRequest;
3434
use Google\Cloud\Tasks\V2beta3\CloudTasksClient;
35-
use Google\Cloud\Tasks\V2beta3\CreateTaskRequest;
3635
use Google\Cloud\Tasks\V2beta3\HttpMethod;
3736
use Google\Cloud\Tasks\V2beta3\Task;
3837

asset/asset.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
use Symfony\Component\Console\Application;
2323
use Symfony\Component\Console\Command\Command;
2424
use Symfony\Component\Console\Input\InputArgument;
25-
use Symfony\Component\Console\Input\InputOption;
26-
use InvalidArgumentException;
2725

2826
$application = new Application();
2927

asset/src/batch_get_assets_history.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,19 @@
2020
# [START asset_quickstart_batch_get_assets_history]
2121
use Google\Cloud\Asset\V1beta1\AssetServiceClient;
2222
use Google\Cloud\Asset\V1beta1\ContentType;
23-
use Google\Cloud\Asset\V1beta1\GcsDestination;
24-
use Google\Cloud\Asset\V1beta1\OutputConfig;
2523
use Google\Cloud\Asset\V1beta1\TimeWindow;
2624
use Google\Protobuf\Timestamp;
2725

2826
function batch_get_assets_history($projectId, $assetNames)
2927
{
30-
$client = new AssetServiceClient();
31-
$formattedParent = $client->projectName($projectId);
32-
$contentType = ContentType::RESOURCE;
33-
$readTimeWindow = new TimeWindow(['start_time' => new Timestamp(['seconds' => time()])]);
28+
$client = new AssetServiceClient();
29+
$formattedParent = $client->projectName($projectId);
30+
$contentType = ContentType::RESOURCE;
31+
$readTimeWindow = new TimeWindow(['start_time' => new Timestamp(['seconds' => time()])]);
3432

35-
$resp = $client->batchGetAssetsHistory($formattedParent, $contentType, $readTimeWindow, ['assetNames' => $assetNames]);
33+
$resp = $client->batchGetAssetsHistory($formattedParent, $contentType, $readTimeWindow, ['assetNames' => $assetNames]);
3634

37-
# Do things with response.
38-
print($resp->serializeToString());
35+
# Do things with response.
36+
print($resp->serializeToString());
3937
}
4038
# [END asset_quickstart_batch_get_assets_history]

asset/src/export_assets.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,20 @@
3131
*/
3232
function export_assets($projectId, $dumpFilePath)
3333
{
34-
$client = new AssetServiceClient();
34+
$client = new AssetServiceClient();
3535

36-
$gcsDestination = new GcsDestination(['uri' => $dumpFilePath]);
37-
$outputConfig = new OutputConfig(['gcs_destination' => $gcsDestination]);
36+
$gcsDestination = new GcsDestination(['uri' => $dumpFilePath]);
37+
$outputConfig = new OutputConfig(['gcs_destination' => $gcsDestination]);
3838

39-
$resp = $client->exportAssets("projects/$projectId", $outputConfig);
39+
$resp = $client->exportAssets("projects/$projectId", $outputConfig);
4040

41-
$resp->pollUntilComplete();
41+
$resp->pollUntilComplete();
4242

43-
if ($resp->operationSucceeded()) {
44-
print('The result is dumped to $dumpFilePath successfully.' . PHP_EOL);
45-
} else {
46-
$error = $operationResponse->getError();
47-
// handleError($error)
48-
}
43+
if ($resp->operationSucceeded()) {
44+
print('The result is dumped to $dumpFilePath successfully.' . PHP_EOL);
45+
} else {
46+
$error = $operationResponse->getError();
47+
// handleError($error)
48+
}
4949
}
5050
# [END asset_quickstart_export_assets]

asset/test/assetTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
use Google\Cloud\TestUtils\TestTrait;
2222
use Google\Cloud\TestUtils\ExecuteCommandTrait;
2323
use Google\Cloud\TestUtils\EventuallyConsistentTestTrait;
24-
use Google\Cloud\Core\Exception\NotFoundException;
25-
use Google\Cloud\Core\Exception\BadRequestException;
2624
use PHPUnit\Framework\TestCase;
2725

2826
/**

bigtable/api/src/create_cluster.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
use Google\Cloud\Bigtable\Admin\V2\StorageType;
3939
use Google\ApiCore\ApiException;
4040

41-
4241
/** Uncomment and populate these variables in your code */
4342
// $project_id = 'The Google project ID';
4443
// $instance_id = 'The Bigtable instance ID';

bigtable/api/src/create_family_gc_intersection.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,11 @@
3333
// [START bigtable_create_family_gc_intersection]
3434
use Google\Cloud\Bigtable\Admin\V2\GcRule\Intersection as GcRuleIntersection;
3535
use Google\Cloud\Bigtable\Admin\V2\ModifyColumnFamiliesRequest\Modification;
36-
use Google\Cloud\Bigtable\Admin\V2\BigtableInstanceAdminClient;
3736
use Google\Cloud\Bigtable\Admin\V2\BigtableTableAdminClient;
3837
use Google\Cloud\Bigtable\Admin\V2\ColumnFamily;
3938
use Google\Cloud\Bigtable\Admin\V2\GcRule;
4039
use Google\Protobuf\Duration;
4140

42-
4341
/** Uncomment and populate these variables in your code */
4442
// $project_id = 'The Google project ID';
4543
// $instance_id = 'The Bigtable instance ID';

bigtable/api/src/create_family_gc_max_age.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,11 @@
3232

3333
// [START bigtable_create_family_gc_max_age]
3434
use Google\Cloud\Bigtable\Admin\V2\ModifyColumnFamiliesRequest\Modification;
35-
use Google\Cloud\Bigtable\Admin\V2\BigtableInstanceAdminClient;
3635
use Google\Cloud\Bigtable\Admin\V2\BigtableTableAdminClient;
3736
use Google\Cloud\Bigtable\Admin\V2\ColumnFamily;
38-
use Google\Cloud\Bigtable\Admin\V2\Table\View;
3937
use Google\Cloud\Bigtable\Admin\V2\GcRule;
4038
use Google\Protobuf\Duration;
4139

42-
4340
/** Uncomment and populate these variables in your code */
4441
// $project_id = 'The Google project ID';
4542
// $instance_id = 'The Bigtable instance ID';
@@ -66,4 +63,4 @@
6663
$tableAdminClient->modifyColumnFamilies($tableName, [$columnModification]);
6764
print('Created column family cf1 with MaxAge GC Rule.' . PHP_EOL);
6865

69-
// [END bigtable_create_family_gc_max_age]
66+
// [END bigtable_create_family_gc_max_age]

bigtable/api/src/create_family_gc_max_versions.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@
3333
// [START bigtable_create_family_gc_max_versions]
3434

3535
use Google\Cloud\Bigtable\Admin\V2\ModifyColumnFamiliesRequest\Modification;
36-
use Google\Cloud\Bigtable\Admin\V2\BigtableInstanceAdminClient;
3736
use Google\Cloud\Bigtable\Admin\V2\BigtableTableAdminClient;
3837
use Google\Cloud\Bigtable\Admin\V2\ColumnFamily;
3938
use Google\Cloud\Bigtable\Admin\V2\GcRule;
4039

41-
4240
/** Uncomment and populate these variables in your code */
4341
// $project_id = 'The Google project ID';
4442
// $instance_id = 'The Bigtable instance ID';
@@ -61,4 +59,4 @@
6159

6260
print('Created column family cf2 with Max Versions GC Rule.' . PHP_EOL);
6361

64-
// [END bigtable_create_family_gc_max_versions]
62+
// [END bigtable_create_family_gc_max_versions]

bigtable/api/src/create_family_gc_nested.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,12 @@
3434

3535
use Google\Cloud\Bigtable\Admin\V2\GcRule\Intersection as GcRuleIntersection;
3636
use Google\Cloud\Bigtable\Admin\V2\ModifyColumnFamiliesRequest\Modification;
37-
use Google\Cloud\Bigtable\Admin\V2\BigtableInstanceAdminClient;
3837
use Google\Cloud\Bigtable\Admin\V2\GcRule\Union as GcRuleUnion;
3938
use Google\Cloud\Bigtable\Admin\V2\BigtableTableAdminClient;
4039
use Google\Cloud\Bigtable\Admin\V2\ColumnFamily;
4140
use Google\Cloud\Bigtable\Admin\V2\GcRule;
4241
use Google\Protobuf\Duration;
4342

44-
4543
/** Uncomment and populate these variables in your code */
4644
// $project_id = 'The Google project ID';
4745
// $instance_id = 'The Bigtable instance ID';
@@ -89,4 +87,4 @@
8987

9088
print('Created column family cf5 with a Nested GC rule.' . PHP_EOL);
9189

92-
// [END bigtable_create_family_gc_nested]
90+
// [END bigtable_create_family_gc_nested]

bigtable/api/src/create_family_gc_union.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
// [START bigtable_create_family_gc_union]
3434

3535
use Google\Cloud\Bigtable\Admin\V2\ModifyColumnFamiliesRequest\Modification;
36-
use Google\Cloud\Bigtable\Admin\V2\BigtableInstanceAdminClient;
3736
use Google\Cloud\Bigtable\Admin\V2\GcRule\Union as GcRuleUnion;
3837
use Google\Cloud\Bigtable\Admin\V2\BigtableTableAdminClient;
3938
use Google\Cloud\Bigtable\Admin\V2\ColumnFamily;
@@ -78,4 +77,4 @@
7877

7978
print('Created column family cf3 with Union GC rule.' . PHP_EOL);
8079

81-
// [END bigtable_create_family_gc_union]
80+
// [END bigtable_create_family_gc_union]

bigtable/api/src/create_table.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
use Google\Cloud\Bigtable\Admin\V2\Table;
3939
use Google\ApiCore\ApiException;
4040

41-
4241
/** Uncomment and populate these variables in your code */
4342
// $project_id = 'The Google project ID';
4443
// $instance_id = 'The Bigtable instance ID';
@@ -72,4 +71,4 @@
7271
throw $e;
7372
}
7473
}
75-
// [END bigtable_create_table]
74+
// [END bigtable_create_table]

bigtable/api/src/delete_family.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@
3434
// [START bigtable_delete_family]
3535

3636
use Google\Cloud\Bigtable\Admin\V2\ModifyColumnFamiliesRequest\Modification;
37-
use Google\Cloud\Bigtable\Admin\V2\BigtableInstanceAdminClient;
3837
use Google\Cloud\Bigtable\Admin\V2\BigtableTableAdminClient;
3938

40-
4139
/** Uncomment and populate these variables in your code */
4240
// $project_id = 'The Google project ID';
4341
// $instance_id = 'The Bigtable instance ID';

bigtable/api/src/delete_instance.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,3 @@
5656
}
5757
}
5858
// [END bigtable_delete_instance]
59-
60-

bigtable/api/src/list_column_families.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232

3333
// [START bigtable_list_column_families]
3434

35-
use Google\Cloud\Bigtable\Admin\V2\BigtableInstanceAdminClient;
3635
use Google\Cloud\Bigtable\Admin\V2\BigtableTableAdminClient;
3736

3837
/** Uncomment and populate these variables in your code */
@@ -53,4 +52,4 @@
5352
print('GC Rule:' . PHP_EOL);
5453
printf('%s' . PHP_EOL, $columnFamily->serializeToJsonString());
5554
}
56-
// [END bigtable_list_column_families]
55+
// [END bigtable_list_column_families]

bigtable/api/src/list_instance.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@
5151
print($instance->getDisplayName() . PHP_EOL);
5252
}
5353

54-
// [END bigtable_list_instances]
54+
// [END bigtable_list_instances]

bigtable/api/src/list_instance_clusters.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@
5151
foreach ($clusters as $cluster) {
5252
print($cluster->getName() . PHP_EOL);
5353
}
54-
// [END bigtable_get_clusters]
54+
// [END bigtable_get_clusters]

bigtable/api/src/list_tables.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@
4646

4747
printf("Listing Tables:" . PHP_EOL);
4848
$tables = $tableAdminClient->listTables($instanceName)->iterateAllElements();
49-
if(empty($tables)){
50-
print('No table exists.' . PHP_EOL);
51-
exit(0);
49+
if (empty($tables)) {
50+
print('No table exists.' . PHP_EOL);
51+
return;
5252
}
5353
foreach ($tables as $table) {
54-
print($table->getName() . PHP_EOL);
54+
print($table->getName() . PHP_EOL);
5555
}
5656
// [END bigtable_list_tables]

0 commit comments

Comments
 (0)