Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions .github/workflows/code-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
6 changes: 3 additions & 3 deletions src/Fixers/ClientUpgradeFixer/ClientVar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/Fixers/ClientUpgradeFixer/RpcMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/TestUtils/CloudFunctionDeploymentTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/TestUtils/ExecuteCommandTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/TestUtils/GcloudWrapper/GcloudWrapperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down