bshaffer/google-cloud-new-surface-fixer

此包最新版本(dev-main)没有可用的许可证信息。

dev-main 2024-01-12 02:35 UTC

This package is auto-updated.

Last update: 2024-09-12 04:13:12 UTC


README

此仓库提供了一个Fixer,可与PHP CS Fixer一起使用,自动将您的代码升级到新的Google Cloud PHP客户端表面

**这是一个alpha工具,不建议在不经过彻底测试的情况下使用!它也不受Google的任何保证。

安装

安装fixer

composer require --dev "bshaffer/google-cloud-new-surface-fixer"

注意:此包依赖于"friendsofphp/php-cs-fixer" v3作为依赖项,但您也可以自由地安装您自己的兼容版本

运行fixer

首先,在您的项目中创建一个.php-cs-fixer.google.php,它将被配置为使用自定义fixer

<?php
// .php-cs-fixer.google.php

// The fixer MUST autoload google/cloud classes. This line is only necessary if
// "php-cs-fixer" was installed in a different composer.json, e.g. with
// "composer global require".
require __DIR__ . '/vendor/autoload.php';

// configure the fixer to run with the new surface fixer
return (new PhpCsFixer\Config())
    ->registerCustomFixers([
        new Google\Cloud\Tools\NewSurfaceFixer(),
    ])
    ->setRules([
        'GoogleCloud/new_surface_fixer' => true,
    ])
;

使用以下命令运行此fixer

export DIR=examples
vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.google.php --dry-run --diff $DIR

您应该得到类似以下的输出

--- examples/legacy_optional_args.php
+++ examples/legacy_optional_args.php
@@ -2,10 +2,12 @@

 namespace Google\Cloud\Samples\Dlp;

-use Google\Cloud\Dlp\V2\DlpServiceClient;
+use Google\Cloud\Dlp\V2\Client\DlpServiceClient;
+use Google\Cloud\Dlp\V2\CreateDlpJobRequest;
 use Google\Cloud\Dlp\V2\InspectConfig;
 use Google\Cloud\Dlp\V2\InspectJobConfig;
 use Google\Cloud\Dlp\V2\Likelihood;
+use Google\Cloud\Dlp\V2\ListInfoTypesRequest;
 use Google\Cloud\Dlp\V2\StorageConfig;

 // Instantiate a client.
@@ -12,14 +14,20 @@
 $dlp = new DlpServiceClient();

 // optional args array (variable)
-$infoTypes = $dlp->listInfoTypes($parent);
+$request = (new ListInfoTypesRequest());
+$infoTypes = $dlp->listInfoTypes($request);

 // optional args array (inline array)
-$job = $dlp->createDlpJob($parent, ['jobId' => 'abc', 'locationId' => 'def']);
+$request2 = (new CreateDlpJobRequest())
+    ->setParent($parent)
+    ->setJobId('abc')
+    ->setLocationId('def');
+$job = $dlp->createDlpJob($request2);

 // optional args array (inline with nested arrays)
-$job = $dlp->createDlpJob($parent, [
-    'inspectJob' => new InspectJobConfig([
+$request3 = (new CreateDlpJobRequest())
+    ->setParent($parent)
+    ->setInspectJob(new InspectJobConfig([
         'inspect_config' => (new InspectConfig())
             ->setMinLikelihood(likelihood::LIKELIHOOD_UNSPECIFIED)
             ->setLimits($limits)
@@ -28,5 +36,5 @@
         'storage_config' => (new StorageConfig())
             ->setCloudStorageOptions(($cloudStorageOptions))
             ->setTimespanConfig($timespanConfig),
-    ])
-]);
+    ]));
+$job = $dlp->createDlpJob($request3);

      ----------- end diff -----------