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: add PHP codesniffer and fix errors/warnings #1770

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
25 changes: 22 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,38 @@ on:
pull_request:

jobs:
styles:
php_cs_fixer:
name: PHP CS Fixer
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'

- name: Run Script
run: testing/run_cs_check.sh

staticanalysis:
php_code_sniffer:
name: PHP Code Sniffer
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
php-version: '7.4'
php-version: '8.1'

- name: Install Dependencies
uses: nick-invision/retry@v2
with:
timeout_minutes: 10
max_attempts: 3
command: composer global require squizlabs/php_codesniffer
- name: Run PHPCS Code Style Checker
run: ~/.composer/vendor/bin/phpcs --standard=phpcs-ruleset.xml -p -s

phpstan_static_analysis:
name: PHPStan Static Analysis
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function run_report_with_dimension_and_metric_filters(string $propertyId)
'value' => 'in_app_purchase',
])
])
]),
]),
],
]),
]),
Expand Down
2 changes: 2 additions & 0 deletions analyticsdata/test/quickstartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* limitations under the License.
*/

namespace Google\Cloud\Samples\AnalyticsData\Test;

use Google\Cloud\TestUtils\TestTrait;
use PHPUnit\Framework\TestCase;

Expand Down
7 changes: 6 additions & 1 deletion asset/src/batch_get_assets_history.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ function batch_get_assets_history(string $projectId, array $assetNames)
$contentType = ContentType::RESOURCE;
$readTimeWindow = new TimeWindow(['start_time' => new Timestamp(['seconds' => time()])]);

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

# Do things with response.
print($resp->serializeToString());
Expand Down
3 changes: 2 additions & 1 deletion auth/src/auth_http_explicit.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ function auth_http_explicit($projectId, $serviceAccountPath)
# and Google Auth library's ServiceAccountCredentials class.
$serviceAccountCredentials = new ServiceAccountCredentials(
'https://www.googleapis.com/auth/cloud-platform',
$serviceAccountPath);
$serviceAccountPath
);
$middleware = new AuthTokenMiddleware($serviceAccountCredentials);
$stack = HandlerStack::create();
$stack->push($middleware);
Expand Down
3 changes: 2 additions & 1 deletion auth/src/auth_http_implicit.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ function auth_http_implicit($projectId)
# Get the credentials and project ID from the environment using Google Auth
# library's ApplicationDefaultCredentials class.
$middleware = ApplicationDefaultCredentials::getMiddleware(
'https://www.googleapis.com/auth/cloud-platform');
'https://www.googleapis.com/auth/cloud-platform'
);
$stack = HandlerStack::create();
$stack->push($middleware);

Expand Down
3 changes: 2 additions & 1 deletion bigquery/api/src/dry_run_query.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
* Dry runs the given query
*
* @param string $projectId The project Id of your Google Cloud Project.
* @param string $query The query to be run. For eg: $query = 'SELECT id, view_count FROM `bigquery-public-data.stackoverflow.posts_questions`'
* @param string $query The query to be run. For eg:
* 'SELECT id, view_count FROM `bigquery-public-data.stackoverflow.posts_questions`'
*/
function dry_run_query(string $projectId, string $query): void
{
Expand Down
4 changes: 3 additions & 1 deletion bigquery/api/src/import_from_storage_json_truncate.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ function import_from_storage_json_truncate(

// create the import job
$gcsUri = 'gs://cloud-samples-data/bigquery/us-states/us-states.json';
$loadConfig = $table->loadFromStorage($gcsUri)->sourceFormat('NEWLINE_DELIMITED_JSON')->writeDisposition('WRITE_TRUNCATE');
$loadConfig = $table->loadFromStorage($gcsUri)
->sourceFormat('NEWLINE_DELIMITED_JSON')
->writeDisposition('WRITE_TRUNCATE');
$job = $table->runJob($loadConfig);

// check if the job is complete
Expand Down
2 changes: 2 additions & 0 deletions bigquery/stackoverflow/test/stackoverflowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* limitations under the License.
*/

namespace Google\Cloud\Samples\BigQuery\StackOverflow\Test;

use PHPUnit\Framework\TestCase;

class stackoverflowTest extends TestCase
Expand Down
2 changes: 2 additions & 0 deletions bigquerydatatransfer/test/quickstartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* limitations under the License.
*/

namespace Google\Cloud\Samples\BigQueryDataTransfer\Tests;

use PHPUnit\Framework\TestCase;

class quickstartTest extends TestCase
Expand Down
6 changes: 4 additions & 2 deletions bigtable/src/create_app_profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
*
* @param string $projectId The Google Cloud project ID
* @param string $instanceId The ID of the Bigtable instance
* @param string $clusterId The ID of the cluster where the new App Profile will route it's requests(in case of single cluster routing)
* @param string $clusterId The ID of the cluster where the new App Profile will route it's requests
* (in case of single cluster routing)
* @param string $appProfileId The ID of the App Profile to create
*/
function create_app_profile(
Expand All @@ -52,7 +53,8 @@ function create_app_profile(
]);

// create a new routing policy
// allow_transactional_writes refers to Single-Row-Transactions(https://cloud.google.com/bigtable/docs/app-profiles#single-row-transactions)
// allow_transactional_writes refers to Single-Row-Transactions
// (https://cloud.google.com/bigtable/docs/app-profiles#single-row-transactions)
$routingPolicy = new SingleClusterRouting([
'cluster_id' => $clusterId,
'allow_transactional_writes' => false
Expand Down
3 changes: 2 additions & 1 deletion bigtable/src/delete_app_profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ function delete_app_profile(
printf('Deleting the App Profile: %s' . PHP_EOL, $appProfileId);

try {
// If $ignoreWarnings is set to false, Bigtable will warn you that all future requests using the AppProfile will fail
// If $ignoreWarnings is set to false, Bigtable will warn you that all
// future requests using the AppProfile will fail
$instanceAdminClient->deleteAppProfile($appProfileName, $ignoreWarnings);
printf('App Profile %s deleted.' . PHP_EOL, $appProfileId);
} catch (ApiException $e) {
Expand Down
3 changes: 2 additions & 1 deletion bigtable/src/filter_composing_chain.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ function filter_composing_chain(
]);

foreach ($rows as $key => $row) {
// The "print_row" helper function is defined in https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
// The "print_row" helper function is defined in
// https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
print_row($key, $row);
}
}
Expand Down
3 changes: 2 additions & 1 deletion bigtable/src/filter_composing_condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ function filter_composing_condition(
]);

foreach ($rows as $key => $row) {
// The "print_row" helper function is defined in https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
// The "print_row" helper function is defined in
// https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
print_row($key, $row);
}
}
Expand Down
3 changes: 2 additions & 1 deletion bigtable/src/filter_composing_interleave.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ function filter_composing_interleave(
]);

foreach ($rows as $key => $row) {
// The "print_row" helper function is defined in https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
// The "print_row" helper function is defined in
// https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
print_row($key, $row);
}
}
Expand Down
3 changes: 2 additions & 1 deletion bigtable/src/filter_limit_block_all.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ function filter_limit_block_all(
]);

foreach ($rows as $key => $row) {
// The "print_row" helper function is defined in https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
// The "print_row" helper function is defined in
// https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
print_row($key, $row);
}
}
Expand Down
3 changes: 2 additions & 1 deletion bigtable/src/filter_limit_cells_per_col.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ function filter_limit_cells_per_col(
]);

foreach ($rows as $key => $row) {
// The "print_row" helper function is defined in https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
// The "print_row" helper function is defined in
// https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
print_row($key, $row);
}
}
Expand Down
3 changes: 2 additions & 1 deletion bigtable/src/filter_limit_cells_per_row.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ function filter_limit_cells_per_row(
]);

foreach ($rows as $key => $row) {
// The "print_row" helper function is defined in https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
// The "print_row" helper function is defined in
// https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
print_row($key, $row);
}
}
Expand Down
3 changes: 2 additions & 1 deletion bigtable/src/filter_limit_cells_per_row_offset.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ function filter_limit_cells_per_row_offset(
]);

foreach ($rows as $key => $row) {
// The "print_row" helper function is defined in https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
// The "print_row" helper function is defined in
// https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
print_row($key, $row);
}
}
Expand Down
3 changes: 2 additions & 1 deletion bigtable/src/filter_limit_col_family_regex.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ function filter_limit_col_family_regex(
]);

foreach ($rows as $key => $row) {
// The "print_row" helper function is defined in https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
// The "print_row" helper function is defined in
// https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
print_row($key, $row);
}
}
Expand Down
3 changes: 2 additions & 1 deletion bigtable/src/filter_limit_col_qualifier_regex.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ function filter_limit_col_qualifier_regex(
]);

foreach ($rows as $key => $row) {
// The "print_row" helper function is defined in https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
// The "print_row" helper function is defined in
// https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
print_row($key, $row);
}
}
Expand Down
3 changes: 2 additions & 1 deletion bigtable/src/filter_limit_col_range.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ function filter_limit_col_range(
]);

foreach ($rows as $key => $row) {
// The "print_row" helper function is defined in https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
// The "print_row" helper function is defined in
// https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
print_row($key, $row);
}
}
Expand Down
3 changes: 2 additions & 1 deletion bigtable/src/filter_limit_pass_all.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ function filter_limit_pass_all(
]);

foreach ($rows as $key => $row) {
// The "print_row" helper function is defined in https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
// The "print_row" helper function is defined in
// https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
print_row($key, $row);
}
}
Expand Down
3 changes: 2 additions & 1 deletion bigtable/src/filter_limit_row_regex.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ function filter_limit_row_regex(
]);

foreach ($rows as $key => $row) {
// The "print_row" helper function is defined in https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
// The "print_row" helper function is defined in
// https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
print_row($key, $row);
}
}
Expand Down
3 changes: 2 additions & 1 deletion bigtable/src/filter_limit_row_sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ function filter_limit_row_sample(
]);

foreach ($rows as $key => $row) {
// The "print_row" helper function is defined in https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
// The "print_row" helper function is defined in
// https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
print_row($key, $row);
}
}
Expand Down
3 changes: 2 additions & 1 deletion bigtable/src/filter_limit_timestamp_range.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ function filter_limit_timestamp_range(
]);

foreach ($rows as $key => $row) {
// The "print_row" helper function is defined in https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
// The "print_row" helper function is defined in
// https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
print_row($key, $row);
}
}
Expand Down
3 changes: 2 additions & 1 deletion bigtable/src/filter_limit_value_range.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ function filter_limit_value_range(
]);

foreach ($rows as $key => $row) {
// The "print_row" helper function is defined in https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
// The "print_row" helper function is defined in
// https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
print_row($key, $row);
}
}
Expand Down
3 changes: 2 additions & 1 deletion bigtable/src/filter_limit_value_regex.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ function filter_limit_value_regex(
]);

foreach ($rows as $key => $row) {
// The "print_row" helper function is defined in https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
// The "print_row" helper function is defined in
// https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
print_row($key, $row);
}
}
Expand Down
3 changes: 2 additions & 1 deletion bigtable/src/filter_modify_apply_label.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ function filter_modify_apply_label(
]);

foreach ($rows as $key => $row) {
// The "print_row" helper function is defined in https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
// The "print_row" helper function is defined in
// https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
print_row($key, $row);
}
}
Expand Down
3 changes: 2 additions & 1 deletion bigtable/src/filter_modify_strip_value.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ function filter_modify_strip_value(
]);

foreach ($rows as $key => $row) {
// The "print_row" helper function is defined in https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
// The "print_row" helper function is defined in
// https://cloud.google.com/bigtable/docs/samples/bigtable-reads-print
print_row($key, $row);
}
}
Expand Down
15 changes: 9 additions & 6 deletions bigtable/src/get_cluster.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ function get_cluster(
printf('Printing Details:' . PHP_EOL);

// Fetch some commonly used metadata
printf('Name: ' . $cluster->getName() . PHP_EOL);
printf('Location: ' . $cluster->getLocation() . PHP_EOL);
printf('State: ' . State::name($cluster->getState()) . PHP_EOL);
printf('Default Storage Type: ' . StorageType::name($cluster->getDefaultStorageType()) . PHP_EOL);
printf('Nodes: ' . $cluster->getServeNodes() . PHP_EOL);
printf('Encryption Config: ' . ($cluster->hasEncryptionConfig() ? $cluster->getEncryptionConfig()->getKmsKeyName() : 'N/A') . PHP_EOL);
printf('Name: %s' . PHP_EOL, $cluster->getName());
printf('Location: %s' . PHP_EOL, $cluster->getLocation());
printf('State: %s' . PHP_EOL, State::name($cluster->getState()));
printf('Default Storage Type: %s' . PHP_EOL, StorageType::name($cluster->getDefaultStorageType()));
printf('Nodes: %s' . PHP_EOL, $cluster->getServeNodes());
printf(
'Encryption Config: %s' . PHP_EOL,
$cluster->hasEncryptionConfig() ? $cluster->getEncryptionConfig()->getKmsKeyName() : 'N/A'
);
}
// [END bigtable_get_cluster]

Expand Down
3 changes: 2 additions & 1 deletion bigtable/src/get_iam_policy.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ function get_iam_policy(
$instanceName = $instanceAdminClient->instanceName($projectId, $instanceId);

try {
// we could instantiate the BigtableTableAdminClient and pass the tableName to get the IAM policy for the table resource as well.
// we could instantiate the BigtableTableAdminClient and pass the
// tableName to get the IAM policy for the table resource as well.
$iamPolicy = $instanceAdminClient->getIamPolicy($instanceName);

printf($iamPolicy->getVersion() . PHP_EOL);
Expand Down
5 changes: 4 additions & 1 deletion bigtable/src/get_instance.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ function get_instance(
// Labels are an object of the MapField class which implement the IteratorAggregate, Countable
// and ArrayAccess interfaces so you can do the following:
printf("\tNum of Labels: " . $labels->count() . PHP_EOL);
printf("\tLabel with a key(dev-label): " . ($labels->offsetExists('dev-label') ? $labels['dev-label'] : 'N/A') . PHP_EOL);
printf(
"\tLabel with a key(dev-label): %s\n",
$labels->offsetExists('dev-label') ? $labels['dev-label'] : 'N/A'
);

// we can even loop over all the labels
foreach ($labels as $key => $val) {
Expand Down
3 changes: 2 additions & 1 deletion bigtable/src/set_iam_policy.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
* @param string $projectId The Google Cloud project ID
* @param string $instanceId The ID of the Bigtable instance
* @param string $email The email of the member to be assigned the role(Format: 'user:EMAIL_ID')
* @param string $role The role to be assigned. For a list of roles check out https://cloud.google.com/bigtable/docs/access-control
* @param string $role The role to be assigned. For a list of roles check out
* https://cloud.google.com/bigtable/docs/access-control
*/
function set_iam_policy(
string $projectId,
Expand Down
Loading