Skip to content

Commit 93072a9

Browse files
authored
feat(ci): add add_rules for cs fixer (#152)
1 parent 2ae887a commit 93072a9

File tree

7 files changed

+25
-17
lines changed

7 files changed

+25
-17
lines changed

.github/workflows/code-standards.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,14 @@ on:
2626
"single_quote": true,
2727
"single_space_around_construct": true,
2828
"cast_spaces": true,
29-
"whitespace_after_comma_in_array": true
29+
"whitespace_after_comma_in_array": true,
30+
"no_whitespace_in_blank_line": true,
31+
"binary_operator_spaces": {"default": "at_least_single_space"},
32+
"no_extra_blank_lines": true
3033
}
34+
add-rules:
35+
type: string
36+
default: "{}"
3137

3238
permissions:
3339
contents: read
@@ -42,15 +48,17 @@ jobs:
4248
uses: shivammathur/setup-php@v2
4349
with:
4450
php-version: '8.2'
51+
- name: 'Setup jq'
52+
uses: dcarbone/install-jq-action@v2
4553
- name: Run PHP CS Fixer
4654
run: |
4755
composer global require friendsofphp/php-cs-fixer:${{ inputs.version }} -q
4856
CONFIG="${{ inputs.config }}"
49-
RULES=$(echo $'${{ inputs.rules }}'|tr -d '\n\t\r ')
57+
RULES=$(echo $'${{ inputs.rules }} ${{ inputs.add-rules }}'|tr -d '\n\t\r '|jq -s '.[0] * .[1]' -crM)
5058
5159
set -x
5260
5361
~/.composer/vendor/bin/php-cs-fixer fix \
5462
${{ inputs.path }} \
55-
$(if [ ! -z "$CONFIG" ]; then echo "--config=$CONFIG"; elif [ ! -z "$RULES" ]; then echo --rules=$RULES; fi) \
63+
$(if [ ! -z "$CONFIG" ]; then echo "--config=$CONFIG"; else echo --rules=$RULES; fi) \
5664
--dry-run --diff

src/Fixers/ClientUpgradeFixer/ClientVar.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ public function isDeclaredAt(Tokens $tokens, int $index): bool
4747

4848
$token = $tokens[$index];
4949
if ($token->isGivenKind(T_VARIABLE)
50-
|| ($token->isGivenKind(T_STRING) && $tokens[$index-1]->isGivenKind(T_OBJECT_OPERATOR))
50+
|| ($token->isGivenKind(T_STRING) && $tokens[$index - 1]->isGivenKind(T_OBJECT_OPERATOR))
5151
) {
5252
if ($this->parent) {
5353
// look back to ensure the parent matches
54-
if ($tokens[$index-2]->getContent() !== $this->parent) {
54+
if ($tokens[$index - 2]->getContent() !== $this->parent) {
5555
return false;
5656
}
5757
}
@@ -141,7 +141,7 @@ public static function getClientVarsFromNewKeyword(Tokens $tokens, array $client
141141
if (
142142
$tokens[$prevIndex]->isGivenKind(T_VARIABLE) || (
143143
$tokens[$prevIndex]->isGivenKind(T_STRING)
144-
&& $tokens[$prevIndex-1]->isGivenKind(T_OBJECT_OPERATOR)
144+
&& $tokens[$prevIndex - 1]->isGivenKind(T_OBJECT_OPERATOR)
145145
)
146146
) {
147147
// Handle clients set to $var

src/Fixers/ClientUpgradeFixer/RpcMethod.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,16 @@ private function settersFromArgumentArray(Tokens $tokens, int $index): array
161161
}
162162
$setterName = 'set' . ucfirst(trim($tokens[$keyIndex]->getContent(), '"\''));
163163
$tokens->removeLeadingWhitespace($doubleArrowIndex + 1);
164-
$valueEnd = isset($arrayEntryIndices[$i+1])
165-
? $tokens->getPrevTokenOfKind($arrayEntryIndices[$i+1], [new Token(',')])
164+
$valueEnd = isset($arrayEntryIndices[$i + 1])
165+
? $tokens->getPrevTokenOfKind($arrayEntryIndices[$i + 1], [new Token(',')])
166166
: $closeIndex;
167167
$varTokens = array_slice($tokens->toArray(), $doubleArrowIndex + 1, $valueEnd - $doubleArrowIndex - 1);
168168
// Remove trailing whitespace
169-
for ($i = count($varTokens)-1; $varTokens[$i]->isGivenKind(T_WHITESPACE); $i--) {
169+
for ($i = count($varTokens) - 1; $varTokens[$i]->isGivenKind(T_WHITESPACE); $i--) {
170170
unset($varTokens[$i]);
171171
}
172172
// Remove trailing commas
173-
for ($i = count($varTokens)-1; $varTokens[$i]->getContent() === ','; $i--) {
173+
for ($i = count($varTokens) - 1; $varTokens[$i]->getContent() === ','; $i--) {
174174
unset($varTokens[$i]);
175175
}
176176
// Remove leading whitespace
@@ -210,8 +210,8 @@ private function settersFromOptionalArgsVar(Tokens $tokens, int $index, string $
210210
new Token([CT::T_ARRAY_SQUARE_BRACE_CLOSE, ']']),
211211
];
212212
$setters[] = [$setterName, $varTokens];
213-
$valueEnd = isset($arrayEntryIndices[$i+1])
214-
? $tokens->getPrevTokenOfKind($arrayEntryIndices[$i+1], [new Token(',')])
213+
$valueEnd = isset($arrayEntryIndices[$i + 1])
214+
? $tokens->getPrevTokenOfKind($arrayEntryIndices[$i + 1], [new Token(',')])
215215
: $closeIndex;
216216
$index = $valueEnd;
217217
}

src/TestUtils/CloudFunctionDeploymentTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ private function processFunctionLogs(string $startTime, callable $process, int $
176176
printf('Sleeping for %d second(s)' . PHP_EOL, $sleep);
177177
sleep($sleep);
178178
}
179-
179+
180180
// Check for new logs for the function.
181181
$attempt = 1;
182182
$this->runEventuallyConsistentTest(function () use ($filter, $process, &$attempt) {

src/TestUtils/ExecuteCommandTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ trait ExecuteCommandTrait
2727

2828
use ExponentialBackoffTrait;
2929

30-
private static function runCommand($commandName, $args=[])
30+
private static function runCommand($commandName, $args = [])
3131
{
3232
if (!isset(self::$commandFile) || !file_exists(self::$commandFile)) {
3333
throw new \LogicException('$commandFile is not set or is missing.');
@@ -106,7 +106,7 @@ private static function createProcess($cmd, $timeout = false)
106106
$process = is_array($cmd) ?
107107
new Process($cmd) :
108108
Process::fromShellCommandline($cmd);
109-
109+
110110
if (self::$workingDirectory) {
111111
$process->setWorkingDirectory(self::$workingDirectory);
112112
}

src/TestUtils/GcloudWrapper/GcloudWrapperTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ protected function runWithRetry(Process $cmd, $retries = 3)
9999
if ($cmd->isSuccessful()) {
100100
return $cmd->getOutput();
101101
} elseif ($i < $retries) {
102-
$this->errorLog('Retry Attempt #' . ($i+1));
102+
$this->errorLog('Retry Attempt #' . ($i + 1));
103103
$cmd->clearOutput();
104104
$cmd->clearErrorOutput();
105105
}

src/Utils/Project.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ protected function validateProjectDir($dir)
7272
return realpath($dir);
7373
}
7474

75-
public function downloadArchive($name, $url, $dir='')
75+
public function downloadArchive($name, $url, $dir = '')
7676
{
7777
$tmpdir = sys_get_temp_dir();
7878
$file = $tmpdir . DIRECTORY_SEPARATOR . basename($url);

0 commit comments

Comments
 (0)