diff --git a/.github/workflows/code-standards.yml b/.github/workflows/code-standards.yml index 538f1c9..8344149 100644 --- a/.github/workflows/code-standards.yml +++ b/.github/workflows/code-standards.yml @@ -26,8 +26,14 @@ 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_whitespace_in_blank_line": true, + "binary_operator_spaces": {"default": "at_least_single_space"}, + "no_extra_blank_lines": true } + add-rules: + type: string + default: "{}" permissions: contents: read @@ -42,15 +48,17 @@ 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 ') + RULES=$(echo $'${{ inputs.rules }} ${{ inputs.add-rules }}'|tr -d '\n\t\r '|jq -s '.[0] * .[1]' -crM) set -x ~/.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 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);