There is no license information available for the latest version (dev-main) of this package.

dev-main 2023-08-25 00:16 UTC

This package is auto-updated.

Last update: 2023-11-25 15:05:55 UTC


This repo provides a Fixer, to be used with PHP CS Fixer, which will automatically** upgrade your code to the new Google Cloud PHP client surface.

** this is an alpha tool and NOT recommended to use without thorough testing! It is also not guanteed by Google in any way.


Install the fixer:

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

NOTE:This package relies on "friendsofphp/php-cs-fixer" v3 as a dependency, but feel free to install your own compatible version as well:

Running the fixer

First, create a in your project which will be configured to use the custom fixer:


// 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())
        new Google\Cloud\Tools\NewSurfaceFixer(),
        'GoogleCloud/new_surface_fixer' => true,
        'ordered_imports' => true,

Run this fixer with the following command:

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

You should get an output similar to this

--- 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())
@@ -28,5 +36,5 @@
         'storage_config' => (new StorageConfig())
-    ])
+    ]));
+$job = $dlp->createDlpJob($request3);

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