From 6b27c796f098bf808e300efe645c7bcf71e1ab67 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Wed, 4 Sep 2024 10:50:58 -0700 Subject: [PATCH 01/11] feat(ci): add add_rules for cs fixer --- .github/workflows/code-standards.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/code-standards.yml b/.github/workflows/code-standards.yml index 538f1c9..45734c5 100644 --- a/.github/workflows/code-standards.yml +++ b/.github/workflows/code-standards.yml @@ -28,6 +28,9 @@ on: "cast_spaces": true, "whitespace_after_comma_in_array": true } + add_rules: + type: string + default: "{}" permissions: contents: read @@ -42,11 +45,15 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: '8.2' + - name: 'Setup jq' + uses: dcarbone/install-jq-action@v2 - name: Run PHP CS Fixer run: | composer global require friendsofphp/php-cs-fixer:${{ inputs.version }} -q CONFIG="${{ inputs.config }}" - RULES=$(echo $'${{ inputs.rules }}'|tr -d '\n\t\r ') + DEFAULT_RULES=$(echo $'${{ inputs.rules }}'|tr -d '\n\t\r ') + ADDITIONAL_RULES=$(echo $'${{ inputs.add_rules }}'|tr -d '\n\t\r ') + RULES=$(echo $RULES $ADDITIONAL_RULES | jq -s '.[0] * .[1]' -crM) set -x From 7eac8e4781ad0948b6ac834615779bfff85936e7 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Wed, 4 Sep 2024 10:55:56 -0700 Subject: [PATCH 02/11] fix varname --- .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 45734c5..a9dcd38 100644 --- a/.github/workflows/code-standards.yml +++ b/.github/workflows/code-standards.yml @@ -53,7 +53,7 @@ jobs: CONFIG="${{ inputs.config }}" DEFAULT_RULES=$(echo $'${{ inputs.rules }}'|tr -d '\n\t\r ') ADDITIONAL_RULES=$(echo $'${{ inputs.add_rules }}'|tr -d '\n\t\r ') - RULES=$(echo $RULES $ADDITIONAL_RULES | jq -s '.[0] * .[1]' -crM) + RULES=$(echo $DEFAULT_RULES $ADDITIONAL_RULES | jq -s '.[0] * .[1]' -crM) set -x From 981742dd3672f4dd6e39a6c5937225783bfead15 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Wed, 4 Sep 2024 12:16:04 -0700 Subject: [PATCH 03/11] add no trailing whitespace rule --- .github/workflows/code-standards.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/code-standards.yml b/.github/workflows/code-standards.yml index a9dcd38..415429c 100644 --- a/.github/workflows/code-standards.yml +++ b/.github/workflows/code-standards.yml @@ -26,7 +26,8 @@ on: "single_quote": true, "single_space_around_construct": true, "cast_spaces": true, - "whitespace_after_comma_in_array": true + "whitespace_after_comma_in_array": true, + "no_trailing_whitespace": true } add_rules: type: string From faeee9c8cc01cc5dc67b6bc64f132ca8d890e816 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Wed, 4 Sep 2024 12:18:29 -0700 Subject: [PATCH 04/11] add no_whitespace_in_blank_line rule --- .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 415429c..1f710ca 100644 --- a/.github/workflows/code-standards.yml +++ b/.github/workflows/code-standards.yml @@ -27,7 +27,7 @@ on: "single_space_around_construct": true, "cast_spaces": true, "whitespace_after_comma_in_array": true, - "no_trailing_whitespace": true + "no_whitespace_in_blank_line": true } add_rules: type: string From e9dfe520e43c98f4ccb89485ce0a5ab3dddd5b6a Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Wed, 4 Sep 2024 12:21:02 -0700 Subject: [PATCH 05/11] add binary_operator_spaces rule --- .github/workflows/code-standards.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/code-standards.yml b/.github/workflows/code-standards.yml index 1f710ca..9620e59 100644 --- a/.github/workflows/code-standards.yml +++ b/.github/workflows/code-standards.yml @@ -27,7 +27,8 @@ on: "single_space_around_construct": true, "cast_spaces": true, "whitespace_after_comma_in_array": true, - "no_whitespace_in_blank_line": true + "no_whitespace_in_blank_line": true, + "binary_operator_spaces": true } add_rules: type: string From d2ac6c5790c4853f3c29644436b988e4798ccc14 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Wed, 4 Sep 2024 12:28:04 -0700 Subject: [PATCH 06/11] add no_extra_blank_lines rule --- .github/workflows/code-standards.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/code-standards.yml b/.github/workflows/code-standards.yml index 9620e59..02da9a2 100644 --- a/.github/workflows/code-standards.yml +++ b/.github/workflows/code-standards.yml @@ -28,7 +28,8 @@ on: "cast_spaces": true, "whitespace_after_comma_in_array": true, "no_whitespace_in_blank_line": true, - "binary_operator_spaces": true + "binary_operator_spaces": true, + "no_extra_blank_lines": true } add_rules: type: string From 397c44422c7bf452d001bb516e263d5d1714b58f Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Wed, 4 Sep 2024 12:32:03 -0700 Subject: [PATCH 07/11] configure binary_operator_space rule --- .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 02da9a2..ddbd3c7 100644 --- a/.github/workflows/code-standards.yml +++ b/.github/workflows/code-standards.yml @@ -28,7 +28,7 @@ on: "cast_spaces": true, "whitespace_after_comma_in_array": true, "no_whitespace_in_blank_line": true, - "binary_operator_spaces": true, + "binary_operator_spaces": {"default": "at_least_single_space"}, "no_extra_blank_lines": true } add_rules: From 455bbf1b27df7225030c570cf450a9240643af19 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Wed, 4 Sep 2024 15:07:36 -0700 Subject: [PATCH 08/11] apply new fixer rules --- src/Fixers/ClientUpgradeFixer/ClientVar.php | 6 +++--- src/Fixers/ClientUpgradeFixer/RpcMethod.php | 12 ++++++------ src/TestUtils/CloudFunctionDeploymentTrait.php | 2 +- src/TestUtils/ExecuteCommandTrait.php | 4 ++-- src/TestUtils/GcloudWrapper/GcloudWrapperTrait.php | 2 +- src/Utils/Project.php | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Fixers/ClientUpgradeFixer/ClientVar.php b/src/Fixers/ClientUpgradeFixer/ClientVar.php index ae230ce..431c59c 100644 --- a/src/Fixers/ClientUpgradeFixer/ClientVar.php +++ b/src/Fixers/ClientUpgradeFixer/ClientVar.php @@ -47,11 +47,11 @@ public function isDeclaredAt(Tokens $tokens, int $index): bool $token = $tokens[$index]; if ($token->isGivenKind(T_VARIABLE) - || ($token->isGivenKind(T_STRING) && $tokens[$index-1]->isGivenKind(T_OBJECT_OPERATOR)) + || ($token->isGivenKind(T_STRING) && $tokens[$index - 1]->isGivenKind(T_OBJECT_OPERATOR)) ) { if ($this->parent) { // look back to ensure the parent matches - if ($tokens[$index-2]->getContent() !== $this->parent) { + if ($tokens[$index - 2]->getContent() !== $this->parent) { return false; } } @@ -141,7 +141,7 @@ public static function getClientVarsFromNewKeyword(Tokens $tokens, array $client if ( $tokens[$prevIndex]->isGivenKind(T_VARIABLE) || ( $tokens[$prevIndex]->isGivenKind(T_STRING) - && $tokens[$prevIndex-1]->isGivenKind(T_OBJECT_OPERATOR) + && $tokens[$prevIndex - 1]->isGivenKind(T_OBJECT_OPERATOR) ) ) { // Handle clients set to $var diff --git a/src/Fixers/ClientUpgradeFixer/RpcMethod.php b/src/Fixers/ClientUpgradeFixer/RpcMethod.php index 6dca677..5a28bfe 100644 --- a/src/Fixers/ClientUpgradeFixer/RpcMethod.php +++ b/src/Fixers/ClientUpgradeFixer/RpcMethod.php @@ -161,16 +161,16 @@ private function settersFromArgumentArray(Tokens $tokens, int $index): array } $setterName = 'set' . ucfirst(trim($tokens[$keyIndex]->getContent(), '"\'')); $tokens->removeLeadingWhitespace($doubleArrowIndex + 1); - $valueEnd = isset($arrayEntryIndices[$i+1]) - ? $tokens->getPrevTokenOfKind($arrayEntryIndices[$i+1], [new Token(',')]) + $valueEnd = isset($arrayEntryIndices[$i + 1]) + ? $tokens->getPrevTokenOfKind($arrayEntryIndices[$i + 1], [new Token(',')]) : $closeIndex; $varTokens = array_slice($tokens->toArray(), $doubleArrowIndex + 1, $valueEnd - $doubleArrowIndex - 1); // Remove trailing whitespace - for ($i = count($varTokens)-1; $varTokens[$i]->isGivenKind(T_WHITESPACE); $i--) { + for ($i = count($varTokens) - 1; $varTokens[$i]->isGivenKind(T_WHITESPACE); $i--) { unset($varTokens[$i]); } // Remove trailing commas - for ($i = count($varTokens)-1; $varTokens[$i]->getContent() === ','; $i--) { + for ($i = count($varTokens) - 1; $varTokens[$i]->getContent() === ','; $i--) { unset($varTokens[$i]); } // Remove leading whitespace @@ -210,8 +210,8 @@ private function settersFromOptionalArgsVar(Tokens $tokens, int $index, string $ new Token([CT::T_ARRAY_SQUARE_BRACE_CLOSE, ']']), ]; $setters[] = [$setterName, $varTokens]; - $valueEnd = isset($arrayEntryIndices[$i+1]) - ? $tokens->getPrevTokenOfKind($arrayEntryIndices[$i+1], [new Token(',')]) + $valueEnd = isset($arrayEntryIndices[$i + 1]) + ? $tokens->getPrevTokenOfKind($arrayEntryIndices[$i + 1], [new Token(',')]) : $closeIndex; $index = $valueEnd; } diff --git a/src/TestUtils/CloudFunctionDeploymentTrait.php b/src/TestUtils/CloudFunctionDeploymentTrait.php index 2363ab2..8c34bbf 100644 --- a/src/TestUtils/CloudFunctionDeploymentTrait.php +++ b/src/TestUtils/CloudFunctionDeploymentTrait.php @@ -176,7 +176,7 @@ private function processFunctionLogs(string $startTime, callable $process, int $ printf('Sleeping for %d second(s)' . PHP_EOL, $sleep); sleep($sleep); } - + // Check for new logs for the function. $attempt = 1; $this->runEventuallyConsistentTest(function () use ($filter, $process, &$attempt) { diff --git a/src/TestUtils/ExecuteCommandTrait.php b/src/TestUtils/ExecuteCommandTrait.php index ecbe232..f6cf0fa 100644 --- a/src/TestUtils/ExecuteCommandTrait.php +++ b/src/TestUtils/ExecuteCommandTrait.php @@ -27,7 +27,7 @@ trait ExecuteCommandTrait use ExponentialBackoffTrait; - private static function runCommand($commandName, $args=[]) + private static function runCommand($commandName, $args = []) { if (!isset(self::$commandFile) || !file_exists(self::$commandFile)) { throw new \LogicException('$commandFile is not set or is missing.'); @@ -106,7 +106,7 @@ private static function createProcess($cmd, $timeout = false) $process = is_array($cmd) ? new Process($cmd) : Process::fromShellCommandline($cmd); - + if (self::$workingDirectory) { $process->setWorkingDirectory(self::$workingDirectory); } diff --git a/src/TestUtils/GcloudWrapper/GcloudWrapperTrait.php b/src/TestUtils/GcloudWrapper/GcloudWrapperTrait.php index 953757f..f7c1900 100644 --- a/src/TestUtils/GcloudWrapper/GcloudWrapperTrait.php +++ b/src/TestUtils/GcloudWrapper/GcloudWrapperTrait.php @@ -99,7 +99,7 @@ protected function runWithRetry(Process $cmd, $retries = 3) if ($cmd->isSuccessful()) { return $cmd->getOutput(); } elseif ($i < $retries) { - $this->errorLog('Retry Attempt #' . ($i+1)); + $this->errorLog('Retry Attempt #' . ($i + 1)); $cmd->clearOutput(); $cmd->clearErrorOutput(); } diff --git a/src/Utils/Project.php b/src/Utils/Project.php index 5b30d75..3691584 100644 --- a/src/Utils/Project.php +++ b/src/Utils/Project.php @@ -72,7 +72,7 @@ protected function validateProjectDir($dir) return realpath($dir); } - public function downloadArchive($name, $url, $dir='') + public function downloadArchive($name, $url, $dir = '') { $tmpdir = sys_get_temp_dir(); $file = $tmpdir . DIRECTORY_SEPARATOR . basename($url); From 3150e868f54fce995f8796b205f2eb64917aaacb Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Thu, 5 Sep 2024 09:29:55 -0700 Subject: [PATCH 09/11] simplify rules --- .github/workflows/code-standards.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/code-standards.yml b/.github/workflows/code-standards.yml index ddbd3c7..a57cf08 100644 --- a/.github/workflows/code-standards.yml +++ b/.github/workflows/code-standards.yml @@ -54,9 +54,7 @@ jobs: run: | composer global require friendsofphp/php-cs-fixer:${{ inputs.version }} -q CONFIG="${{ inputs.config }}" - DEFAULT_RULES=$(echo $'${{ inputs.rules }}'|tr -d '\n\t\r ') - ADDITIONAL_RULES=$(echo $'${{ inputs.add_rules }}'|tr -d '\n\t\r ') - RULES=$(echo $DEFAULT_RULES $ADDITIONAL_RULES | jq -s '.[0] * .[1]' -crM) + RULES=$(echo $'${{ inputs.rules }} ${{ inputs.add_rules }}'|tr -d '\n\t\r '|jq -s '.[0] * .[1]' -crM) set -x From 043b124ed8cc3d9e4acca541f9d9ab18dd180a55 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Thu, 5 Sep 2024 09:45:09 -0700 Subject: [PATCH 10/11] simplify logic --- .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 a57cf08..45f9bc8 100644 --- a/.github/workflows/code-standards.yml +++ b/.github/workflows/code-standards.yml @@ -60,5 +60,5 @@ jobs: ~/.composer/vendor/bin/php-cs-fixer fix \ ${{ inputs.path }} \ - $(if [ ! -z "$CONFIG" ]; then echo "--config=$CONFIG"; elif [ ! -z "$RULES" ]; then echo --rules=$RULES; fi) \ + $(if [ ! -z "$CONFIG" ]; then echo "--config=$CONFIG"; else echo --rules=$RULES; fi) \ --dry-run --diff From f7d94abbd07574ff3d9e546843f04a8b49e4c359 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Thu, 5 Sep 2024 10:23:27 -0700 Subject: [PATCH 11/11] add_rules to add-rules --- .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 45f9bc8..8344149 100644 --- a/.github/workflows/code-standards.yml +++ b/.github/workflows/code-standards.yml @@ -31,7 +31,7 @@ on: "binary_operator_spaces": {"default": "at_least_single_space"}, "no_extra_blank_lines": true } - add_rules: + add-rules: type: string default: "{}" @@ -54,7 +54,7 @@ jobs: run: | composer global require friendsofphp/php-cs-fixer:${{ inputs.version }} -q CONFIG="${{ inputs.config }}" - RULES=$(echo $'${{ inputs.rules }} ${{ inputs.add_rules }}'|tr -d '\n\t\r '|jq -s '.[0] * .[1]' -crM) + RULES=$(echo $'${{ inputs.rules }} ${{ inputs.add-rules }}'|tr -d '\n\t\r '|jq -s '.[0] * .[1]' -crM) set -x