Skip to content

Commit e0a63c5

Browse files
authored
style(phpcs): Adapt same code style as in PHPCS 4 (#3552621)
1 parent 333597c commit e0a63c5

File tree

201 files changed

+1353
-2127
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

201 files changed

+1353
-2127
lines changed

coder_sniffer/Drupal/Sniffs/Arrays/ArraySniff.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
class ArraySniff implements Sniff
2828
{
2929

30-
3130
/**
3231
* The limit that the length of a line should not exceed.
3332
*
@@ -51,8 +50,7 @@ public function register()
5150
T_ARRAY,
5251
T_OPEN_SHORT_ARRAY,
5352
];
54-
55-
}//end register()
53+
}
5654

5755

5856
/**
@@ -304,8 +302,5 @@ public function process(File $phpcsFile, $stackPtr)
304302

305303
$lineStart = $newLineStart;
306304
}//end while
307-
308-
}//end process()
309-
310-
311-
}//end class
305+
}
306+
}

coder_sniffer/Drupal/Sniffs/Attributes/ValidHookNameSniff.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ class ValidHookNameSniff implements Sniff
3131
public function register()
3232
{
3333
return [T_ATTRIBUTE];
34-
35-
}//end register()
34+
}
3635

3736

3837
/**
@@ -75,8 +74,5 @@ public function process(File $phpcsFile, $stackPtr)
7574
}
7675
}
7776
}//end if
78-
79-
}//end process()
80-
81-
82-
}//end class
77+
}
78+
}

coder_sniffer/Drupal/Sniffs/Classes/ClassDeclarationSniff.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ public function register()
4646
T_TRAIT,
4747
T_ENUM,
4848
];
49-
50-
}//end register()
49+
}
5150

5251

5352
/**
@@ -106,7 +105,7 @@ public function process(File $phpcsFile, $stackPtr)
106105
$openingBrace = $tokens[$stackPtr]['scope_opener'];
107106
if ($tokens[($openingBrace - 1)]['code'] !== T_WHITESPACE) {
108107
$length = 0;
109-
} else if ($tokens[($openingBrace - 1)]['content'] === "\t") {
108+
} elseif ($tokens[($openingBrace - 1)]['content'] === "\t") {
110109
$length = '\t';
111110
} else {
112111
$length = strlen($tokens[($openingBrace - 1)]['content']);
@@ -129,8 +128,7 @@ public function process(File $phpcsFile, $stackPtr)
129128
$this->processOpen($phpcsFile, $stackPtr);
130129

131130
$this->processClose($phpcsFile, $stackPtr);
132-
133-
}//end process()
131+
}
134132

135133

136134
/**
@@ -171,7 +169,7 @@ public function processClose(File $phpcsFile, $stackPtr)
171169
$phpcsFile->fixer->replaceToken($i, '');
172170
}
173171

174-
$phpcsFile->fixer->replaceToken($closeBrace, $phpcsFile->eolChar.$phpcsFile->eolChar.$tokens[$closeBrace]['content']);
172+
$phpcsFile->fixer->replaceToken($closeBrace, $phpcsFile->eolChar . $phpcsFile->eolChar . $tokens[$closeBrace]['content']);
175173

176174
$phpcsFile->fixer->endChangeset();
177175
}
@@ -188,8 +186,5 @@ public function processClose(File $phpcsFile, $stackPtr)
188186
$data = [$tokens[$stackPtr]['content']];
189187
$phpcsFile->addError($error, $closeBrace, 'CloseBraceSameLine', $data);
190188
}
191-
192-
}//end processClose()
193-
194-
195-
}//end class
189+
}
190+
}

coder_sniffer/Drupal/Sniffs/Classes/FullyQualifiedNamespaceSniff.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ public function register()
3535
T_NAME_FULLY_QUALIFIED,
3636
T_NAME_QUALIFIED,
3737
];
38-
39-
}//end register()
38+
}
4039

4140

4241
/**
@@ -201,8 +200,5 @@ public function process(File $phpcsFile, $stackPtr)
201200

202201
$phpcsFile->fixer->endChangeset();
203202
}//end if
204-
205-
}//end process()
206-
207-
208-
}//end class
203+
}
204+
}

coder_sniffer/Drupal/Sniffs/Classes/PropertyDeclarationSniff.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ class PropertyDeclarationSniff implements Sniff
3535
public function register()
3636
{
3737
return [T_VAR];
38-
39-
}//end register()
38+
}
4039

4140

4241
/**
@@ -55,8 +54,5 @@ public function process(File $phpcsFile, $stackPtr)
5554
if ($fix === true) {
5655
$phpcsFile->fixer->replaceToken($stackPtr, 'public');
5756
}
58-
59-
}//end process()
60-
61-
62-
}//end class
57+
}
58+
}

coder_sniffer/Drupal/Sniffs/Classes/UseGlobalClassSniff.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ class UseGlobalClassSniff implements Sniff
3232
public function register()
3333
{
3434
return [T_USE];
35-
36-
}//end register()
35+
}
3736

3837

3938
/**
@@ -74,7 +73,7 @@ public function process(File $phpcsFile, $stackPtr)
7473

7574
$lineStart = $stackPtr;
7675
// Iterate through a potential multiline use statement.
77-
while (false !== $lineEnd = $phpcsFile->findNext([T_SEMICOLON, T_COMMA], ($lineStart + 1), ($stmtEnd + 1))) {
76+
while (($lineEnd = $phpcsFile->findNext([T_SEMICOLON, T_COMMA], ($lineStart + 1), ($stmtEnd + 1))) !== false) {
7877
// Skip function imports.
7978
if ($phpcsFile->findNext(T_STRING, $lineStart, $lineEnd, false, 'function') !== false) {
8079
$lineStart = $lineEnd;
@@ -108,11 +107,11 @@ public function process(File $phpcsFile, $stackPtr)
108107
// If there are lines before this one,
109108
// then leave the ending delimiter in place.
110109
$end = ($lineEnd - 1);
111-
} else if ($tokens[$lineEnd]['code'] === T_COMMA) {
110+
} elseif ($tokens[$lineEnd]['code'] === T_COMMA) {
112111
// If there are lines after, but not before,
113112
// then leave the use keyword.
114113
$start = $class;
115-
} else if ($tokens[$next]['code'] === T_USE) {
114+
} elseif ($tokens[$next]['code'] === T_USE) {
116115
// If the whole statement is removed, and there is one after it,
117116
// then also remove the linebreaks.
118117
$end = ($next - 1);
@@ -125,17 +124,14 @@ public function process(File $phpcsFile, $stackPtr)
125124
// Find all usages of the class, and add a leading backslash.
126125
// Only start looking after the end of the use statement block.
127126
$i = $bodyStart;
128-
while (false !== $i = $phpcsFile->findNext(T_STRING, ($i + 1), null, false, $aliasName)) {
129-
$phpcsFile->fixer->replaceToken($i, '\\'.$className);
127+
while (($i = $phpcsFile->findNext(T_STRING, ($i + 1), null, false, $aliasName)) !== false) {
128+
$phpcsFile->fixer->replaceToken($i, '\\' . $className);
130129
}
131130

132131
$phpcsFile->fixer->endChangeset();
133132
}//end if
134133

135134
$lineStart = $lineEnd;
136135
}//end while
137-
138-
}//end process()
139-
140-
141-
}//end class
136+
}
137+
}

coder_sniffer/Drupal/Sniffs/Commenting/ClassCommentSniff.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ public function register()
3838
T_TRAIT,
3939
T_ENUM,
4040
];
41-
42-
}//end register()
41+
}
4342

4443

4544
/**
@@ -118,11 +117,11 @@ public function process(File $phpcsFile, $stackPtr)
118117
$phpcsFile->fixer->beginChangeset();
119118
$comment = '';
120119
for ($i = $commentEnd; $tokens[$i]['code'] === T_COMMENT; $i--) {
121-
$comment = ' *'.ltrim($tokens[$i]['content'], '/* ').$comment;
120+
$comment = ' *' . ltrim($tokens[$i]['content'], '/* ') . $comment;
122121
$phpcsFile->fixer->replaceToken($i, '');
123122
}
124123

125-
$phpcsFile->fixer->replaceToken($commentEnd, "/**\n".rtrim($comment, "*/\n")."\n */");
124+
$phpcsFile->fixer->replaceToken($commentEnd, "/**\n" . rtrim($comment, "*/\n") . "\n */");
126125
$phpcsFile->fixer->endChangeset();
127126
}
128127

@@ -167,8 +166,5 @@ public function process(File $phpcsFile, $stackPtr)
167166
}
168167
}
169168
}
170-
171-
}//end process()
172-
173-
174-
}//end class
169+
}
170+
}

coder_sniffer/Drupal/Sniffs/Commenting/DataTypeNamespaceSniff.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ class DataTypeNamespaceSniff implements Sniff
3232
public function register()
3333
{
3434
return [T_USE];
35-
36-
}//end register()
35+
}
3736

3837

3938
/**
@@ -93,15 +92,12 @@ public function process(File $phpcsFile, $stackPtr)
9392
$data = [$tokens[$tag]['content']];
9493
$fix = $phpcsFile->addFixableError($error, ($tag + 2), 'DataTypeNamespace', $data);
9594
if ($fix === true) {
96-
$replacement = '\\'.$fullNamespace.substr($tokens[($tag + 2)]['content'], strlen($className));
95+
$replacement = '\\' . $fullNamespace . substr($tokens[($tag + 2)]['content'], strlen($className));
9796
$phpcsFile->fixer->replaceToken(($tag + 2), $replacement);
9897
}
9998
}
10099

101100
$tag = $phpcsFile->findNext(T_DOC_COMMENT_TAG, ($tag + 1));
102101
}//end while
103-
104-
}//end process()
105-
106-
107-
}//end class
102+
}
103+
}

coder_sniffer/Drupal/Sniffs/Commenting/DeprecatedSniff.php

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ public function register()
4545
}
4646

4747
return [T_DOC_COMMENT_TAG];
48-
49-
}//end register()
48+
}
5049

5150

5251
/**
@@ -96,7 +95,7 @@ public function process(File $phpcsFile, $stackPtr)
9695

9796
// The standard format for the deprecation text is:
9897
// @deprecated in %in-version% and is removed from %removal-version%. %extra-info%.
99-
$standardFormat = "@deprecated in %%deprecation-version%% and is removed from %%removal-version%%. %%extra-info%%.";
98+
$standardFormat = '@deprecated in %%deprecation-version%% and is removed from %%removal-version%%. %%extra-info%%.';
10099

101100
// Use (?U) 'ungreedy' before the removal-version so that only the text
102101
// up to the first dot+space is matched, as there may be more than one
@@ -110,7 +109,7 @@ public function process(File $phpcsFile, $stackPtr)
110109
// The full text does not match the standard. Try to find fixes by
111110
// testing with a relaxed set of criteria, based on common
112111
// formatting variations. This is designed for Core fixes only.
113-
$error = "The text '@deprecated %s' does not match the standard format: ".$standardFormat;
112+
$error = "The text '@deprecated %s' does not match the standard format: " . $standardFormat;
114113
// All of the standard text should be on the first comment line, so
115114
// try to match with common formatting errors to allow an automatic
116115
// fix. If not possible then report a normal error.
@@ -131,9 +130,9 @@ public function process(File $phpcsFile, $stackPtr)
131130
// It is a Drupal core deprecation and is fixable.
132131
if (empty($matchesFix[1]) === false && $this->debug === true) {
133132
// For info, to check it is acceptable to remove the text in [1].
134-
echo('DEBUG: File: '.$phpcsFile->path.', line '.$tokens[($stackPtr)]['line'].PHP_EOL);
135-
echo('DEBUG: "@deprecated '.$text1.'"'.PHP_EOL);
136-
echo('DEBUG: Fix will remove: "'.$matchesFix[1].'"'.PHP_EOL);
133+
echo('DEBUG: File: ' . $phpcsFile->path . ', line ' . $tokens[($stackPtr)]['line'] . PHP_EOL);
134+
echo('DEBUG: "@deprecated ' . $text1 . '"' . PHP_EOL);
135+
echo('DEBUG: Fix will remove: "' . $matchesFix[1] . '"' . PHP_EOL);
137136
}
138137

139138
$ver1 = str_Replace(['-dev', 'x'], ['', '0'], trim($matchesFix[5], '.'));
@@ -147,14 +146,14 @@ public function process(File $phpcsFile, $stackPtr)
147146
$ver2 .= '.0';
148147
}
149148

150-
$correctedText = trim('in drupal:'.$ver1.' and is removed from drupal:'.$ver2.'. '.trim($matchesFix[14]));
149+
$correctedText = trim('in drupal:' . $ver1 . ' and is removed from drupal:' . $ver2 . '. ' . trim($matchesFix[14]));
151150
// If $correctedText is longer than 65 this will make the whole line
152151
// exceed 80 so give a warning if running with debug.
153152
if (strlen($correctedText) > 65 && $this->debug === true) {
154-
echo('WARNING: File '.$phpcsFile->path.', line '.$tokens[($stackPtr)]['line'].PHP_EOL);
155-
echo('WARNING: Original = * @deprecated '.$text1.PHP_EOL);
156-
echo('WARNING: Corrected = * @deprecated '.$correctedText.PHP_EOL);
157-
echo('WARNING: New line length '.(strlen($correctedText) + 15).' exceeds standard 80 character limit'.PHP_EOL);
153+
echo('WARNING: File ' . $phpcsFile->path . ', line ' . $tokens[($stackPtr)]['line'] . PHP_EOL);
154+
echo('WARNING: Original = * @deprecated ' . $text1 . PHP_EOL);
155+
echo('WARNING: Corrected = * @deprecated ' . $correctedText . PHP_EOL);
156+
echo('WARNING: New line length ' . (strlen($correctedText) + 15) . ' exceeds standard 80 character limit' . PHP_EOL);
158157
}
159158

160159
$fix = $phpcsFile->addFixableError($error, $key, 'IncorrectTextLayout', [$fullText]);
@@ -184,7 +183,7 @@ public function process(File $phpcsFile, $stackPtr)
184183
// except for missing extra info. This is a common fault so provide
185184
// a separate check and message for this.
186185
if ($matches[3] === '') {
187-
$error = 'The @deprecated tag must have %extra-info%. The standard format is: '.str_replace('%%', '%', $standardFormat);
186+
$error = 'The @deprecated tag must have %extra-info%. The standard format is: ' . str_replace('%%', '%', $standardFormat);
188187
$phpcsFile->addError($error, $stackPtr, 'MissingExtraInfo', []);
189188
}
190189
}//end if
@@ -220,12 +219,9 @@ public function process(File $phpcsFile, $stackPtr)
220219
$content = substr($crLink, 0, -(strlen($matches[4])));
221220
$phpcsFile->fixer->replaceToken($string, $content);
222221
}//end if
223-
} else if (empty($matches) === true) {
222+
} elseif (empty($matches) === true) {
224223
$error = "The @see url '%s' does not match the standard: http(s)://www.drupal.org/node/n or http(s)://www.drupal.org/project/aaa/issues/n";
225224
$phpcsFile->addWarning($error, $seeTag, 'DeprecatedWrongSeeUrlFormat', [$crLink]);
226225
}
227-
228-
}//end process()
229-
230-
231-
}//end class
226+
}
227+
}

coder_sniffer/Drupal/Sniffs/Commenting/DocCommentAlignmentSniff.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ class DocCommentAlignmentSniff implements Sniff
3535
public function register()
3636
{
3737
return [T_DOC_COMMENT_OPEN_TAG];
38-
39-
}//end register()
38+
}
4039

4140

4241
/**
@@ -127,7 +126,7 @@ public function process(File $phpcsFile, $stackPtr)
127126
if ($fix === true) {
128127
$phpcsFile->fixer->addContent($i, ' ');
129128
}
130-
} else if ($tokens[($i + 2)]['code'] === T_DOC_COMMENT_TAG
129+
} elseif ($tokens[($i + 2)]['code'] === T_DOC_COMMENT_TAG
131130
&& $tokens[($i + 1)]['content'] !== ' '
132131
// Special @code/@endcode/@see tags can have more than 1 space.
133132
&& in_array(
@@ -149,8 +148,5 @@ public function process(File $phpcsFile, $stackPtr)
149148
}
150149
}//end if
151150
}//end for
152-
153-
}//end process()
154-
155-
156-
}//end class
151+
}
152+
}

0 commit comments

Comments
 (0)