From 22d0bde95b72060cf54f0ea4745703536866a30f Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Thu, 15 Aug 2024 13:40:49 -0700 Subject: [PATCH 01/22] feat: add reusable workflows for cs and static analysis --- .github/workflows/code-standards.yml | 36 ++++++++++++++++++++++++++ .github/workflows/lint.yml | 11 ++++++++ .github/workflows/static-analysis.yml | 37 +++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 .github/workflows/code-standards.yml create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/static-analysis.yml diff --git a/.github/workflows/code-standards.yml b/.github/workflows/code-standards.yml new file mode 100644 index 0000000..df9b7de --- /dev/null +++ b/.github/workflows/code-standards.yml @@ -0,0 +1,36 @@ +name: PHP Code Standards + +on: + workflow_call: + inputs: + version: + type: string + default: "^3.0" + config: + type: string + default: ".php-cs-fixer.dist.php" + path: + type: string + default: "" + +permissions: + contents: read + +jobs: + php_code_standards: + runs-on: ubuntu-latest + name: PHP Code Standards + steps: + - uses: actions/checkout@v4 + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + - name: Run PHP CS Fixer + run: | + composer install + composer global require friendsofphp/php-cs-fixer:${{ inputs.version }} + ~/.composer/vendor/bin/php-cs-fixer fix \ + --config=${{ inputs.config }} \ + ${{ inputs.path }} \ + --dry-run --diff diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..0fc658b --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,11 @@ +name: Lint + +on: + pull_request: + +jobs: + code-standards: + uses: GoogleCloudPlatform/php-tools/.github/workflows/code-standards.yml@reusable-workflow + + static-analysis: + uses: GoogleCloudPlatform/php-tools/.github/workflows/static-analysis.yml@reusable-workflow diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml new file mode 100644 index 0000000..cb831d6 --- /dev/null +++ b/.github/workflows/static-analysis.yml @@ -0,0 +1,37 @@ +name: PHP Static Analysis +on: + workflow_call: + inputs: + version: + type: string + default: "^1.8" + paths: + type: string + default: "src" + autoload-file: + type: string + default: "vendor/autoload.php" + level: + type: number + default: 0 + +permissions: + contents: read + +jobs: + static_analysis: + runs-on: ubuntu-latest + name: PHPStan Static Analysis + steps: + - uses: actions/checkout@v4 + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + - name: Run Script + run: | + composer install + composer global require phpstan/phpstan:${{ inputs.version }} + ~/.composer/vendor/bin/phpstan analyse ${{ inputs.paths }} \ + --autoload-file=${{ inputs.autoload-file }} \ + --level=${{ inputs.level }} From a6ddff48f1bf27377d6bcdd523d190be55c6fa70 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Thu, 15 Aug 2024 13:44:30 -0700 Subject: [PATCH 02/22] fix cs and staticanalysis --- composer.json | 2 +- .../ClientUpgradeFixer/ClientUpgradeFixer.php | 25 ++++++------------- .../ClientUpgradeFixer/RequestClass.php | 1 - .../RequestVariableCounter.php | 2 -- src/Fixers/ClientUpgradeFixer/RpcMethod.php | 1 - src/TestUtils/GcloudWrapper/AppEngine.php | 1 + src/TestUtils/GcloudWrapper/CloudFunction.php | 2 +- src/Utils/ContainerExec.php | 3 ++- src/Utils/Flex/FlexExecCommand.php | 2 +- src/Utils/WordPress/Project.php | 1 + 10 files changed, 14 insertions(+), 26 deletions(-) diff --git a/composer.json b/composer.json index eefcb4d..5b494b5 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,7 @@ "paragonie/random_compat": ">=2", "phpunit/phpunit": "^9", "phpspec/prophecy-phpunit": "^2.0", - "friendsofphp/php-cs-fixer": "^3.21", + "friendsofphp/php-cs-fixer": "^3.62", "google/cloud-dlp": "^1.10", "google/cloud-storage": "^1.33", "google/cloud-secret-manager": "^1.12" diff --git a/src/Fixers/ClientUpgradeFixer/ClientUpgradeFixer.php b/src/Fixers/ClientUpgradeFixer/ClientUpgradeFixer.php index 7adf779..d86cf7d 100644 --- a/src/Fixers/ClientUpgradeFixer/ClientUpgradeFixer.php +++ b/src/Fixers/ClientUpgradeFixer/ClientUpgradeFixer.php @@ -3,23 +3,21 @@ namespace Google\Cloud\Fixers\ClientUpgradeFixer; use PhpCsFixer\AbstractFixer; -use PhpCsFixer\Fixer\FixerInterface; use PhpCsFixer\Fixer\Import\OrderedImportsFixer; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; -use PhpCsFixer\Tokenizer\Analyzer\NamespaceUsesAnalyzer; -use PhpCsFixer\Tokenizer\Analyzer\Analysis\NamespaceUseAnalysis; -use PhpCsFixer\Tokenizer\CT; +use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; -use ReflectionClass; -use ReflectionMethod; use PhpCsFixer\Fixer\ConfigurableFixerInterface; +use PhpCsFixer\Fixer\ConfigurableFixerTrait; use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver; use PhpCsFixer\FixerConfiguration\FixerOptionBuilder; use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface; class ClientUpgradeFixer extends AbstractFixer implements ConfigurableFixerInterface { + use ConfigurableFixerTrait; + /** * Check if the fixer is a candidate for given Tokens collection. * @@ -34,19 +32,10 @@ public function isCandidate(Tokens $tokens): bool return true; } - /** - * @param array $configuration - */ - public function configure(array $configuration): void - { - // no configuration assumes true - $this->configuration = $configuration; - } - /** * Defines the available configuration options of the fixer. */ - public function getConfigurationDefinition(): FixerConfigurationResolverInterface + protected function createConfigurationDefinition(): FixerConfigurationResolverInterface { return new FixerConfigurationResolver([ (new FixerOptionBuilder('clientVars', 'A map of client variables to their new class names')) @@ -199,10 +188,10 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $importedClasses = array_map(fn ($useDeclaration) => $useDeclaration->getFullName(), $useDeclarations); $classesToImport = array_filter( $classesToImport, - fn($requestClass) => !isset($importedClasses[$requestClass->getName()]) + fn ($requestClass) => !isset($importedClasses[$requestClass->getName()]) ); $requestClassImportTokens = array_map( - fn($requestClass) => $requestClass->getImportTokens(), + fn ($requestClass) => $requestClass->getImportTokens(), array_values($classesToImport) ); $tokens->insertAt($importStart, array_merge(...$requestClassImportTokens)); diff --git a/src/Fixers/ClientUpgradeFixer/RequestClass.php b/src/Fixers/ClientUpgradeFixer/RequestClass.php index 78ca769..89c78a2 100644 --- a/src/Fixers/ClientUpgradeFixer/RequestClass.php +++ b/src/Fixers/ClientUpgradeFixer/RequestClass.php @@ -3,7 +3,6 @@ namespace Google\Cloud\Fixers\ClientUpgradeFixer; use PhpCsFixer\Tokenizer\Token; -use PhpCsFixer\Tokenizer\Tokens; use ReflectionClass; class RequestClass diff --git a/src/Fixers/ClientUpgradeFixer/RequestVariableCounter.php b/src/Fixers/ClientUpgradeFixer/RequestVariableCounter.php index 6f7dcc5..07fbf8e 100644 --- a/src/Fixers/ClientUpgradeFixer/RequestVariableCounter.php +++ b/src/Fixers/ClientUpgradeFixer/RequestVariableCounter.php @@ -2,8 +2,6 @@ namespace Google\Cloud\Fixers\ClientUpgradeFixer; -use PhpCsFixer\Tokenizer\Tokens; - class RequestVariableCounter { private array $varCounts = []; diff --git a/src/Fixers/ClientUpgradeFixer/RpcMethod.php b/src/Fixers/ClientUpgradeFixer/RpcMethod.php index 9f3b109..6dca677 100644 --- a/src/Fixers/ClientUpgradeFixer/RpcMethod.php +++ b/src/Fixers/ClientUpgradeFixer/RpcMethod.php @@ -6,7 +6,6 @@ use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; use ReflectionMethod; -use ReflectionParameter; class RpcMethod { diff --git a/src/TestUtils/GcloudWrapper/AppEngine.php b/src/TestUtils/GcloudWrapper/AppEngine.php index 333ecde..1d3702f 100644 --- a/src/TestUtils/GcloudWrapper/AppEngine.php +++ b/src/TestUtils/GcloudWrapper/AppEngine.php @@ -237,4 +237,5 @@ public function getBaseUrl($service = 'default') } } +// @phpstan-ignore-next-line class_alias(AppEngine::class, \Google\Cloud\TestUtils\GcloudWrapper::class); diff --git a/src/TestUtils/GcloudWrapper/CloudFunction.php b/src/TestUtils/GcloudWrapper/CloudFunction.php index a6ca92e..07b05d3 100644 --- a/src/TestUtils/GcloudWrapper/CloudFunction.php +++ b/src/TestUtils/GcloudWrapper/CloudFunction.php @@ -108,7 +108,7 @@ public static function fromArray(array $arr) $args[] = $arr[$key] ?? ''; } - return new static(...$args); + return new self(...$args); } /** diff --git a/src/Utils/ContainerExec.php b/src/Utils/ContainerExec.php index 9e6b95c..72f3875 100644 --- a/src/Utils/ContainerExec.php +++ b/src/Utils/ContainerExec.php @@ -62,7 +62,8 @@ public function __construct( throw new \InvalidArgumentException("$workdir is not a directory"); } $this->gcloud = ($gcloud == null) ? new Gcloud() : $gcloud; - if (class_exists(\Twig_Loader_Filesystem::class)) { + if (class_exists(\Twig_Loader_Filesystem::class) + && class_exists(\Twig_Environment::class)) { $loader = new \Twig_Loader_Filesystem(__DIR__ . '/templates'); $this->twig = new \Twig_Environment($loader); } else { diff --git a/src/Utils/Flex/FlexExecCommand.php b/src/Utils/Flex/FlexExecCommand.php index d60a60e..ea354c4 100644 --- a/src/Utils/Flex/FlexExecCommand.php +++ b/src/Utils/Flex/FlexExecCommand.php @@ -244,7 +244,7 @@ protected function resolveImage( * @param string $service * @param InputInterface $input * @param OutputInterface $output - * @return string The version for the latest deployment for the given + * @return ?string The version for the latest deployment for the given * service. */ protected function detectLatestDeployedVersion( diff --git a/src/Utils/WordPress/Project.php b/src/Utils/WordPress/Project.php index 4c418e5..2004c21 100644 --- a/src/Utils/WordPress/Project.php +++ b/src/Utils/WordPress/Project.php @@ -41,6 +41,7 @@ class Project extends BaseProject private $input; private $output; private $helper; + private $filesystem; private $wordPressDir; public function __construct(InputInterface $input, OutputInterface $output, QuestionHelper $helper = null) From 2bf9450aaa40bfd8b6f0f160992a601eb3d44f92 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Thu, 15 Aug 2024 13:55:17 -0700 Subject: [PATCH 03/22] only run csfixer in src --- .github/workflows/lint.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 0fc658b..6b838ba 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -6,6 +6,9 @@ on: jobs: code-standards: uses: GoogleCloudPlatform/php-tools/.github/workflows/code-standards.yml@reusable-workflow + with: + path: "src" static-analysis: uses: GoogleCloudPlatform/php-tools/.github/workflows/static-analysis.yml@reusable-workflow + From ce356aeb110dacb19e9414e22a143e52add1450c Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 16 Aug 2024 07:39:10 -0700 Subject: [PATCH 04/22] remove level param --- .github/workflows/static-analysis.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index cb831d6..f784083 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -11,9 +11,6 @@ on: autoload-file: type: string default: "vendor/autoload.php" - level: - type: number - default: 0 permissions: contents: read @@ -33,5 +30,4 @@ jobs: composer install composer global require phpstan/phpstan:${{ inputs.version }} ~/.composer/vendor/bin/phpstan analyse ${{ inputs.paths }} \ - --autoload-file=${{ inputs.autoload-file }} \ - --level=${{ inputs.level }} + --autoload-file=${{ inputs.autoload-file }} From 75d2b51b8d4bbd8fa67ad0f4bdf0efe7c7775219 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 16 Aug 2024 07:55:27 -0700 Subject: [PATCH 05/22] use global default for php-cs-fixer --- .github/workflows/code-standards.yml | 2 +- .github/workflows/lint.yml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/code-standards.yml b/.github/workflows/code-standards.yml index df9b7de..8ab87a1 100644 --- a/.github/workflows/code-standards.yml +++ b/.github/workflows/code-standards.yml @@ -8,7 +8,7 @@ on: default: "^3.0" config: type: string - default: ".php-cs-fixer.dist.php" + default: "~/.composer/vendor/google/cloud-tools/.php-cs-fixer.dist.php" path: type: string default: "" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 6b838ba..3f13dee 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -7,7 +7,8 @@ jobs: code-standards: uses: GoogleCloudPlatform/php-tools/.github/workflows/code-standards.yml@reusable-workflow with: - path: "src" + path: src + config: .php-cs-fixer.dist.php static-analysis: uses: GoogleCloudPlatform/php-tools/.github/workflows/static-analysis.yml@reusable-workflow From 9ab1cf5a54fdb7f6b499ddacefbe99ccd0772c86 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 16 Aug 2024 08:23:36 -0700 Subject: [PATCH 06/22] add default rules --- .github/workflows/code-standards.yml | 13 ++++++++++++- .github/workflows/lint.yml | 1 - 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/code-standards.yml b/.github/workflows/code-standards.yml index 8ab87a1..b757ca4 100644 --- a/.github/workflows/code-standards.yml +++ b/.github/workflows/code-standards.yml @@ -12,6 +12,9 @@ on: path: type: string default: "" + rules: + type: string + default: '{"@PSR2":true,"array_syntax":{"syntax":"short"},"concat_space":{"spacing":"one"},"no_unused_imports":true,"ordered_imports":true,"new_with_braces":true,"whitespace_after_comma_in_array":true,"method_argument_space":{"keep_multiple_spaces_after_comma":true,"on_multiline":"ignore"},"return_type_declaration":{"space_before":"none"},"single_quote":true}' permissions: contents: read @@ -30,7 +33,15 @@ jobs: run: | composer install composer global require friendsofphp/php-cs-fixer:${{ inputs.version }} + CONFIG="" + if [ ! -z "${{ inputs.config }}" ]; then + CONFIG="--config=${{ inputs.config }}" + elfi [ ! -z "${{ inputs.rules }}" ]; then + RULES="--rules=${{ inputs.rules }}" + fi + ~/.composer/vendor/bin/php-cs-fixer fix \ - --config=${{ inputs.config }} \ + $CONFIG \ + $RULES \ ${{ inputs.path }} \ --dry-run --diff diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 3f13dee..ed65a78 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -8,7 +8,6 @@ jobs: uses: GoogleCloudPlatform/php-tools/.github/workflows/code-standards.yml@reusable-workflow with: path: src - config: .php-cs-fixer.dist.php static-analysis: uses: GoogleCloudPlatform/php-tools/.github/workflows/static-analysis.yml@reusable-workflow From 93acf7dcbe005ec867f84c69da1ce23a9b7fe176 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 16 Aug 2024 08:25:53 -0700 Subject: [PATCH 07/22] fix syntax --- .github/workflows/code-standards.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/code-standards.yml b/.github/workflows/code-standards.yml index b757ca4..a1edc9e 100644 --- a/.github/workflows/code-standards.yml +++ b/.github/workflows/code-standards.yml @@ -8,7 +8,7 @@ on: default: "^3.0" config: type: string - default: "~/.composer/vendor/google/cloud-tools/.php-cs-fixer.dist.php" + default: "" path: type: string default: "" @@ -34,9 +34,10 @@ jobs: composer install composer global require friendsofphp/php-cs-fixer:${{ inputs.version }} CONFIG="" + RULES="" if [ ! -z "${{ inputs.config }}" ]; then CONFIG="--config=${{ inputs.config }}" - elfi [ ! -z "${{ inputs.rules }}" ]; then + elif [ ! -z "${{ inputs.rules }}" ]; then RULES="--rules=${{ inputs.rules }}" fi From 42ef5908ea07cc2dda9b85b78f433ebd9ee06780 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 16 Aug 2024 08:28:02 -0700 Subject: [PATCH 08/22] fix quotes --- .github/workflows/code-standards.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code-standards.yml b/.github/workflows/code-standards.yml index a1edc9e..a8f51e7 100644 --- a/.github/workflows/code-standards.yml +++ b/.github/workflows/code-standards.yml @@ -38,7 +38,7 @@ jobs: if [ ! -z "${{ inputs.config }}" ]; then CONFIG="--config=${{ inputs.config }}" elif [ ! -z "${{ inputs.rules }}" ]; then - RULES="--rules=${{ inputs.rules }}" + RULES="--rules="'${{ inputs.rules }}' fi ~/.composer/vendor/bin/php-cs-fixer fix \ From 10f23b1e116e93924777e96ade3fe71ba62bd98d Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 16 Aug 2024 08:30:48 -0700 Subject: [PATCH 09/22] add default path --- .github/workflows/code-standards.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code-standards.yml b/.github/workflows/code-standards.yml index a8f51e7..2edc974 100644 --- a/.github/workflows/code-standards.yml +++ b/.github/workflows/code-standards.yml @@ -11,7 +11,7 @@ on: default: "" path: type: string - default: "" + default: "." rules: type: string default: '{"@PSR2":true,"array_syntax":{"syntax":"short"},"concat_space":{"spacing":"one"},"no_unused_imports":true,"ordered_imports":true,"new_with_braces":true,"whitespace_after_comma_in_array":true,"method_argument_space":{"keep_multiple_spaces_after_comma":true,"on_multiline":"ignore"},"return_type_declaration":{"space_before":"none"},"single_quote":true}' From afe1799984c1cdcb1392f625a54363f95725e587 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 16 Aug 2024 08:38:42 -0700 Subject: [PATCH 10/22] experiment with multiline rules --- .github/workflows/code-standards.yml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/code-standards.yml b/.github/workflows/code-standards.yml index 2edc974..68229cc 100644 --- a/.github/workflows/code-standards.yml +++ b/.github/workflows/code-standards.yml @@ -14,7 +14,19 @@ on: default: "." rules: type: string - default: '{"@PSR2":true,"array_syntax":{"syntax":"short"},"concat_space":{"spacing":"one"},"no_unused_imports":true,"ordered_imports":true,"new_with_braces":true,"whitespace_after_comma_in_array":true,"method_argument_space":{"keep_multiple_spaces_after_comma":true,"on_multiline":"ignore"},"return_type_declaration":{"space_before":"none"},"single_quote":true}' + default: | + { + "@PSR2":true, + "array_syntax":{"syntax":"short"}, + "concat_space":{"spacing":"one"}, + "no_unused_imports":true, + "ordered_imports":true, + "new_with_braces":true, + "whitespace_after_comma_in_array":true, + "method_argument_space":{"keep_multiple_spaces_after_comma":true,"on_multiline":"ignore"}, + "return_type_declaration":{"space_before":"none"}, + "single_quote":true + } permissions: contents: read @@ -37,7 +49,7 @@ jobs: RULES="" if [ ! -z "${{ inputs.config }}" ]; then CONFIG="--config=${{ inputs.config }}" - elif [ ! -z "${{ inputs.rules }}" ]; then + elif [ ! -z '${{ inputs.rules }}' ]; then RULES="--rules="'${{ inputs.rules }}' fi From 809a6b6b26bdb6ef17a2d7238711839d2dddeadc Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 16 Aug 2024 08:48:05 -0700 Subject: [PATCH 11/22] fix quotes --- .github/workflows/code-standards.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code-standards.yml b/.github/workflows/code-standards.yml index 68229cc..2a71928 100644 --- a/.github/workflows/code-standards.yml +++ b/.github/workflows/code-standards.yml @@ -50,7 +50,7 @@ jobs: if [ ! -z "${{ inputs.config }}" ]; then CONFIG="--config=${{ inputs.config }}" elif [ ! -z '${{ inputs.rules }}' ]; then - RULES="--rules="'${{ inputs.rules }}' + RULES=--rules=\''${{ inputs.rules }}'\' fi ~/.composer/vendor/bin/php-cs-fixer fix \ From 477956b62a00529eacc558427ed4d05993d6b0cf Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 16 Aug 2024 08:51:06 -0700 Subject: [PATCH 12/22] debug --- .php-cs-fixer.dist.php | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 .php-cs-fixer.dist.php diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php deleted file mode 100644 index 0026c58..0000000 --- a/.php-cs-fixer.dist.php +++ /dev/null @@ -1,16 +0,0 @@ -setRules([ - '@PSR2' => true, - 'concat_space' => ['spacing' => 'one'], - 'no_unused_imports' => true, - 'method_argument_space' => false, - ]) - ->setFinder( - PhpCsFixer\Finder::create()->in(__DIR__) - ) -; - -return $config; From 8a33e911e4b1323ba7f6cdfb4ea710c626890b59 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 16 Aug 2024 08:52:32 -0700 Subject: [PATCH 13/22] debug --- .github/workflows/code-standards.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/code-standards.yml b/.github/workflows/code-standards.yml index 2a71928..fea3345 100644 --- a/.github/workflows/code-standards.yml +++ b/.github/workflows/code-standards.yml @@ -53,6 +53,8 @@ jobs: RULES=--rules=\''${{ inputs.rules }}'\' fi + echo $RULES // for debugging + ~/.composer/vendor/bin/php-cs-fixer fix \ $CONFIG \ $RULES \ From c3dd2ec7d2d9ff434da574fc96e08005e1521b37 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 16 Aug 2024 08:55:31 -0700 Subject: [PATCH 14/22] executable debugging --- .github/workflows/code-standards.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/code-standards.yml b/.github/workflows/code-standards.yml index fea3345..ff07ab5 100644 --- a/.github/workflows/code-standards.yml +++ b/.github/workflows/code-standards.yml @@ -55,6 +55,8 @@ jobs: echo $RULES // for debugging + set -x + ~/.composer/vendor/bin/php-cs-fixer fix \ $CONFIG \ $RULES \ From 692fd119740d6735b39ef1d1999068b9476df6e2 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 16 Aug 2024 09:13:38 -0700 Subject: [PATCH 15/22] hopefully fix bash --- .github/workflows/code-standards.yml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/workflows/code-standards.yml b/.github/workflows/code-standards.yml index ff07ab5..8cfcd62 100644 --- a/.github/workflows/code-standards.yml +++ b/.github/workflows/code-standards.yml @@ -45,16 +45,14 @@ jobs: run: | composer install composer global require friendsofphp/php-cs-fixer:${{ inputs.version }} - CONFIG="" - RULES="" - if [ ! -z "${{ inputs.config }}" ]; then - CONFIG="--config=${{ inputs.config }}" - elif [ ! -z '${{ inputs.rules }}' ]; then - RULES=--rules=\''${{ inputs.rules }}'\' + CONFIG="${{ inputs.config }}" + RULES=$(echo $'${{ inputs.rules }}'|tr -d '\n\t\r ') + if [ ! -z "$CONFIG" ]; then + CONFIG="--config=$CONFIG" + elif [ ! -z "$RULES" ]; then + RULES=--rules=$RULES fi - echo $RULES // for debugging - set -x ~/.composer/vendor/bin/php-cs-fixer fix \ From 6d4a5322889af72dd3d0a28ecdd120cbc692d489 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 16 Aug 2024 09:19:09 -0700 Subject: [PATCH 16/22] update all to new styles --- .github/workflows/code-standards.yml | 2 +- src/Fixers/ClientUpgradeFixer/ClientUpgradeFixer.php | 12 ++++++------ src/TestUtils/CloudFunctionDeploymentTrait.php | 2 +- src/TestUtils/CloudSqlProxyTrait.php | 2 +- src/TestUtils/FileUtil.php | 2 +- src/TestUtils/GcloudWrapper/CloudFunction.php | 4 ++-- src/TestUtils/GcloudWrapper/CloudRun.php | 2 +- src/TestUtils/GcloudWrapper/GcloudWrapperTrait.php | 4 ++-- src/Utils/ContainerExec.php | 2 +- src/Utils/Flex/FlexExecCommand.php | 12 ++++++------ src/Utils/Gcloud.php | 2 +- src/Utils/Project.php | 8 ++++---- src/Utils/WordPress/Project.php | 4 ++-- 13 files changed, 29 insertions(+), 29 deletions(-) diff --git a/.github/workflows/code-standards.yml b/.github/workflows/code-standards.yml index 8cfcd62..28eb902 100644 --- a/.github/workflows/code-standards.yml +++ b/.github/workflows/code-standards.yml @@ -21,7 +21,7 @@ on: "concat_space":{"spacing":"one"}, "no_unused_imports":true, "ordered_imports":true, - "new_with_braces":true, + "new_with_parentheses":true, "whitespace_after_comma_in_array":true, "method_argument_space":{"keep_multiple_spaces_after_comma":true,"on_multiline":"ignore"}, "return_type_declaration":{"space_before":"none"}, diff --git a/src/Fixers/ClientUpgradeFixer/ClientUpgradeFixer.php b/src/Fixers/ClientUpgradeFixer/ClientUpgradeFixer.php index d86cf7d..9f35570 100644 --- a/src/Fixers/ClientUpgradeFixer/ClientUpgradeFixer.php +++ b/src/Fixers/ClientUpgradeFixer/ClientUpgradeFixer.php @@ -3,16 +3,16 @@ namespace Google\Cloud\Fixers\ClientUpgradeFixer; use PhpCsFixer\AbstractFixer; -use PhpCsFixer\Fixer\Import\OrderedImportsFixer; -use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; -use PhpCsFixer\FixerDefinition\FixerDefinition; -use PhpCsFixer\Tokenizer\Token; -use PhpCsFixer\Tokenizer\Tokens; use PhpCsFixer\Fixer\ConfigurableFixerInterface; use PhpCsFixer\Fixer\ConfigurableFixerTrait; +use PhpCsFixer\Fixer\Import\OrderedImportsFixer; use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver; -use PhpCsFixer\FixerConfiguration\FixerOptionBuilder; use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface; +use PhpCsFixer\FixerConfiguration\FixerOptionBuilder; +use PhpCsFixer\FixerDefinition\FixerDefinition; +use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; +use PhpCsFixer\Tokenizer\Token; +use PhpCsFixer\Tokenizer\Tokens; class ClientUpgradeFixer extends AbstractFixer implements ConfigurableFixerInterface { diff --git a/src/TestUtils/CloudFunctionDeploymentTrait.php b/src/TestUtils/CloudFunctionDeploymentTrait.php index 2426639..2363ab2 100644 --- a/src/TestUtils/CloudFunctionDeploymentTrait.php +++ b/src/TestUtils/CloudFunctionDeploymentTrait.php @@ -142,7 +142,7 @@ public function setUpClient() public function getBaseUri() { - return self::$fn->getBaseUrl(getenv("GOOGLE_SKIP_DEPLOYMENT") === 'true'); + return self::$fn->getBaseUrl(getenv('GOOGLE_SKIP_DEPLOYMENT') === 'true'); } /** diff --git a/src/TestUtils/CloudSqlProxyTrait.php b/src/TestUtils/CloudSqlProxyTrait.php index f98014e..617a4e9 100644 --- a/src/TestUtils/CloudSqlProxyTrait.php +++ b/src/TestUtils/CloudSqlProxyTrait.php @@ -17,8 +17,8 @@ namespace Google\Cloud\TestUtils; -use Symfony\Component\Process\Process; use Exception; +use Symfony\Component\Process\Process; /** * Trait CloudSqlTestTrait diff --git a/src/TestUtils/FileUtil.php b/src/TestUtils/FileUtil.php index a76d248..8df98fa 100644 --- a/src/TestUtils/FileUtil.php +++ b/src/TestUtils/FileUtil.php @@ -23,7 +23,7 @@ class FileUtil { public static function randomName($length) { - $array = array(); + $array = []; for ($i = 0; $i < $length; ++$i) { array_push($array, chr(random_int(ord('a'), ord('z')))); } diff --git a/src/TestUtils/GcloudWrapper/CloudFunction.php b/src/TestUtils/GcloudWrapper/CloudFunction.php index 07b05d3..ba1667d 100644 --- a/src/TestUtils/GcloudWrapper/CloudFunction.php +++ b/src/TestUtils/GcloudWrapper/CloudFunction.php @@ -17,9 +17,9 @@ namespace Google\Cloud\TestUtils\GcloudWrapper; -use Symfony\Component\Process\Process; -use Symfony\Component\Process\PhpExecutableFinder; use Symfony\Component\Process\Exception\ProcessFailedException; +use Symfony\Component\Process\PhpExecutableFinder; +use Symfony\Component\Process\Process; /** * Class CloudFunction. diff --git a/src/TestUtils/GcloudWrapper/CloudRun.php b/src/TestUtils/GcloudWrapper/CloudRun.php index 0900185..55d6134 100644 --- a/src/TestUtils/GcloudWrapper/CloudRun.php +++ b/src/TestUtils/GcloudWrapper/CloudRun.php @@ -77,7 +77,7 @@ public function __construct($project, array $options = []) * * @return bool true if deployment suceeds, false upon failure */ - public function build($image, array $options = [], string $source = ".") + public function build($image, array $options = [], string $source = '.') { // Set default optioins $options = array_merge([ diff --git a/src/TestUtils/GcloudWrapper/GcloudWrapperTrait.php b/src/TestUtils/GcloudWrapper/GcloudWrapperTrait.php index d04f7a3..953757f 100644 --- a/src/TestUtils/GcloudWrapper/GcloudWrapperTrait.php +++ b/src/TestUtils/GcloudWrapper/GcloudWrapperTrait.php @@ -17,8 +17,8 @@ namespace Google\Cloud\TestUtils\GcloudWrapper; -use Symfony\Component\Process\Process; use Symfony\Component\Process\Exception\ProcessFailedException; +use Symfony\Component\Process\Process; /** * Trait GcloudWrapperTrait. @@ -89,7 +89,7 @@ protected function execWithRetry($cmd, $retries = 3, &$output = null) */ protected function runWithRetry(Process $cmd, $retries = 3) { - $this->errorLog('Running: ' . str_replace("'", "", $cmd->getCommandLine())); + $this->errorLog('Running: ' . str_replace("'", '', $cmd->getCommandLine())); for ($i = 0; $i <= $retries; ++$i) { // TODO: Use ExponentialBackoffTrait for more sophisticated handling. // Simple geometric backoff, .25 seconds * iteration. diff --git a/src/Utils/ContainerExec.php b/src/Utils/ContainerExec.php index 72f3875..c150b57 100644 --- a/src/Utils/ContainerExec.php +++ b/src/Utils/ContainerExec.php @@ -110,7 +110,7 @@ public function run() implode(PHP_EOL, $cmdOutput) ); if ($result !== 0) { - throw new \RuntimeException("Failed to run the command"); + throw new \RuntimeException('Failed to run the command'); } $ret = ''; if ($this->cloudSqlInstances) { diff --git a/src/Utils/Flex/FlexExecCommand.php b/src/Utils/Flex/FlexExecCommand.php index ea354c4..91da3c2 100644 --- a/src/Utils/Flex/FlexExecCommand.php +++ b/src/Utils/Flex/FlexExecCommand.php @@ -24,8 +24,8 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Exception\IOExceptionInterface; +use Symfony\Component\Filesystem\Filesystem; /** * CLI command for running a command with an image deployed to App Engine @@ -151,7 +151,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } $output->writeln("Using workdir: $workdir"); if ($preserveWorkdir) { - $output->writeln("Preserving the workdir"); + $output->writeln('Preserving the workdir'); } else { register_shutdown_function(function () use ($workdir, $fs) { $fs->remove($workdir); @@ -213,7 +213,7 @@ protected function resolveImage( 'describe', $version, "--service=$service", - "--format=json" + '--format=json' ] ); if ($ret !== 0) { @@ -258,9 +258,9 @@ protected function detectLatestDeployedVersion( 'versions', 'list', "--service=$service", - "--format=get(version.id)", - "--sort-by=~version.createTime", - "--limit=1" + '--format=get(version.id)', + '--sort-by=~version.createTime', + '--limit=1' ] ); if (!empty($cmdOutput)) { diff --git a/src/Utils/Gcloud.php b/src/Utils/Gcloud.php index 59e350f..8f61bb6 100644 --- a/src/Utils/Gcloud.php +++ b/src/Utils/Gcloud.php @@ -28,7 +28,7 @@ class Gcloud public function __construct() { $auths = exec( - escapeshellcmd("gcloud auth list --format=value(account)"), + escapeshellcmd('gcloud auth list --format=value(account)'), $output, $ret ); diff --git a/src/Utils/Project.php b/src/Utils/Project.php index 7a315ca..a34c192 100644 --- a/src/Utils/Project.php +++ b/src/Utils/Project.php @@ -20,8 +20,8 @@ class Project { protected $dir; - private $errors = array(); - private $info = array(); + private $errors = []; + private $info = []; private static $availableDbRegions = [ // North America 'northamerica-northeast1', @@ -80,7 +80,7 @@ public function downloadArchive($name, $url, $dir='') $dir = $this->getRelativeDir($dir); if (substr($url, -3, 3) === 'zip') { - $zip = new \ZipArchive; + $zip = new \ZipArchive(); if ($zip->open($file) === false) { $this->errors[] = 'Failed to open a zip file: ' . $file; return; @@ -135,7 +135,7 @@ public function getDir() public function getInfo() { $ret = $this->info; - $this->info = array(); + $this->info = []; return $ret; } diff --git a/src/Utils/WordPress/Project.php b/src/Utils/WordPress/Project.php index 2004c21..4cb3bb1 100644 --- a/src/Utils/WordPress/Project.php +++ b/src/Utils/WordPress/Project.php @@ -19,12 +19,12 @@ use Exception; use Google\Cloud\Utils\Project as BaseProject; +use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ChoiceQuestion; use Symfony\Component\Console\Question\ConfirmationQuestion; use Symfony\Component\Console\Question\Question; -use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Filesystem\Filesystem; class Project extends BaseProject @@ -261,7 +261,7 @@ public function runComposer() private function report() { foreach ($this->getInfo() as $value) { - $this->output->writeln("" . $value . ""); + $this->output->writeln('' . $value . ''); } if ($this->getErrors()) { throw new Exception(implode("\n", $this->getErrors())); From 8ff217f0b11fece659f136a42a4c552544de3ae1 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 16 Aug 2024 09:21:23 -0700 Subject: [PATCH 17/22] cleaner whitespace in JSON config --- .github/workflows/code-standards.yml | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/.github/workflows/code-standards.yml b/.github/workflows/code-standards.yml index 28eb902..6bee342 100644 --- a/.github/workflows/code-standards.yml +++ b/.github/workflows/code-standards.yml @@ -16,16 +16,19 @@ on: type: string default: | { - "@PSR2":true, - "array_syntax":{"syntax":"short"}, - "concat_space":{"spacing":"one"}, - "no_unused_imports":true, - "ordered_imports":true, - "new_with_parentheses":true, - "whitespace_after_comma_in_array":true, - "method_argument_space":{"keep_multiple_spaces_after_comma":true,"on_multiline":"ignore"}, - "return_type_declaration":{"space_before":"none"}, - "single_quote":true + "@PSR2": true, + "array_syntax": {"syntax":"short"}, + "concat_space": {"spacing":"one"}, + "no_unused_imports": true, + "ordered_imports": true, + "new_with_parentheses": true, + "whitespace_after_comma_in_array": true, + "method_argument_space": { + "keep_multiple_spaces_after_comma": true, + "on_multiline": "ignore" + }, + "return_type_declaration": {"space_before": "none"}, + "single_quote": true } permissions: From c354a3bce082bc84b7cf097a198823c1cc873bbf Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 16 Aug 2024 09:24:30 -0700 Subject: [PATCH 18/22] add quiet mode for composer --- .github/workflows/code-standards.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/code-standards.yml b/.github/workflows/code-standards.yml index 6bee342..46d44cf 100644 --- a/.github/workflows/code-standards.yml +++ b/.github/workflows/code-standards.yml @@ -46,8 +46,8 @@ jobs: php-version: '8.2' - name: Run PHP CS Fixer run: | - composer install - composer global require friendsofphp/php-cs-fixer:${{ inputs.version }} + composer install -q + composer global require friendsofphp/php-cs-fixer:${{ inputs.version }} -q CONFIG="${{ inputs.config }}" RULES=$(echo $'${{ inputs.rules }}'|tr -d '\n\t\r ') if [ ! -z "$CONFIG" ]; then From 893bc4eac57b432567759ddce6eb6f304ee281e5 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 16 Aug 2024 09:59:12 -0700 Subject: [PATCH 19/22] Update .github/workflows/lint.yml --- .github/workflows/lint.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ed65a78..e531b87 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -5,10 +5,10 @@ on: jobs: code-standards: - uses: GoogleCloudPlatform/php-tools/.github/workflows/code-standards.yml@reusable-workflow + uses: .github/workflows/code-standards.yml with: path: src static-analysis: - uses: GoogleCloudPlatform/php-tools/.github/workflows/static-analysis.yml@reusable-workflow + uses: .github/workflows/static-analysis.yml From fdcf698b072a0e48045f3af605b2e250f21bf859 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 16 Aug 2024 10:05:52 -0700 Subject: [PATCH 20/22] consolidate workflow files --- .github/workflows/lint.yml | 14 -------------- .github/workflows/tests.yml | 25 ++++++++----------------- 2 files changed, 8 insertions(+), 31 deletions(-) delete mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index e531b87..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,14 +0,0 @@ -name: Lint - -on: - pull_request: - -jobs: - code-standards: - uses: .github/workflows/code-standards.yml - with: - path: src - - static-analysis: - uses: .github/workflows/static-analysis.yml - diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index becf09a..8243c8c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -31,20 +31,11 @@ jobs: - name: Run Script run: vendor/bin/phpunit - style: - runs-on: ubuntu-latest - name: PHP Style Check - steps: - - uses: actions/checkout@v4 - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: "8.1" - - name: Install Dependencies - uses: nick-invision/retry@v3 - with: - timeout_minutes: 10 - max_attempts: 3 - command: composer install - - name: Run Script - run: vendor/bin/php-cs-fixer fix . + code-standards: + uses: ./.github/workflows/code-standards.yml + with: + path: src + + static-analysis: + uses: ./.github/workflows/static-analysis.yml + From b9743ac9831b6a6a196bad815a5081407bca877a Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 16 Aug 2024 10:07:30 -0700 Subject: [PATCH 21/22] composer tweaks --- .github/workflows/code-standards.yml | 1 - .github/workflows/static-analysis.yml | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/code-standards.yml b/.github/workflows/code-standards.yml index 46d44cf..501ac3a 100644 --- a/.github/workflows/code-standards.yml +++ b/.github/workflows/code-standards.yml @@ -46,7 +46,6 @@ jobs: php-version: '8.2' - name: Run PHP CS Fixer run: | - composer install -q composer global require friendsofphp/php-cs-fixer:${{ inputs.version }} -q CONFIG="${{ inputs.config }}" RULES=$(echo $'${{ inputs.rules }}'|tr -d '\n\t\r ') diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index f784083..880fd88 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -27,7 +27,7 @@ jobs: php-version: '8.2' - name: Run Script run: | - composer install - composer global require phpstan/phpstan:${{ inputs.version }} + composer install -q + composer global require phpstan/phpstan:${{ inputs.version }} -q ~/.composer/vendor/bin/phpstan analyse ${{ inputs.paths }} \ --autoload-file=${{ inputs.autoload-file }} From cb340ed44e4d0f7b497bd8c0c4f9af156aeb5d8a Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 16 Aug 2024 10:14:53 -0700 Subject: [PATCH 22/22] cleanup cs bash --- .github/workflows/code-standards.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/code-standards.yml b/.github/workflows/code-standards.yml index 501ac3a..84190e5 100644 --- a/.github/workflows/code-standards.yml +++ b/.github/workflows/code-standards.yml @@ -49,16 +49,10 @@ jobs: composer global require friendsofphp/php-cs-fixer:${{ inputs.version }} -q CONFIG="${{ inputs.config }}" RULES=$(echo $'${{ inputs.rules }}'|tr -d '\n\t\r ') - if [ ! -z "$CONFIG" ]; then - CONFIG="--config=$CONFIG" - elif [ ! -z "$RULES" ]; then - RULES=--rules=$RULES - fi set -x ~/.composer/vendor/bin/php-cs-fixer fix \ - $CONFIG \ - $RULES \ ${{ inputs.path }} \ + $(if [ ! -z "$CONFIG" ]; then echo "--config=$CONFIG"; elif [ ! -z "$RULES" ]; then echo --rules=$RULES; fi) \ --dry-run --diff