Skip to content

Commit 2f970c0

Browse files
committed
Let PHP_CodeSniffer run sprintf as needed
1 parent 183c05c commit 2f970c0

17 files changed

+126
-95
lines changed

Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php

+10-7
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ public function process(File $phpcsFile, $stackPtr)
6666

6767
if ($this->PHPDocFormattingValidator->providesMeaning($namePtr, $commentStartPtr, $tokens) !== true) {
6868
$phpcsFile->addWarning(
69-
sprintf(
70-
'%s description must contain meaningful information beyond what its name provides or be removed.',
71-
ucfirst($tokens[$stackPtr]['content'])
72-
),
69+
'%s description must contain meaningful information beyond what its name provides or be removed.',
7370
$stackPtr,
74-
'InvalidDescription'
71+
'InvalidDescription',
72+
[
73+
ucfirst($tokens[$stackPtr]['content']),
74+
]
7575
);
7676
}
7777

@@ -108,9 +108,12 @@ private function validateTags(File $phpcsFile, $commentStartPtr, $tokens)
108108

109109
if (in_array($tokens[$i]['content'], $this->forbiddenTags) === true) {
110110
$phpcsFile->addWarning(
111-
sprintf('Tag %s MUST NOT be used.', $tokens[$i]['content']),
111+
'Tag %s MUST NOT be used.',
112112
$i,
113-
'ForbiddenTags'
113+
'ForbiddenTags',
114+
[
115+
$tokens[$i]['content'],
116+
]
114117
);
115118
}
116119
}

Magento2/Sniffs/Functions/FunctionsDeprecatedWithoutArgumentSniff.php

+10-4
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,23 @@ public function process(File $phpcsFile, $stackPtr): void
7373

7474
if (self::DEPRECATED_FUNCTIONS_AND_FIXES[$functionName] === false) {
7575
$phpcsFile->addWarning(
76-
sprintf(self::WARNING_MESSAGE, $functionName),
76+
self::WARNING_MESSAGE,
7777
$stackPtr,
78-
self::WARNING_CODE
78+
self::WARNING_CODE,
79+
[
80+
$functionName,
81+
]
7982
);
8083
return;
8184
}
8285

8386
$fix = $phpcsFile->addFixableWarning(
84-
sprintf(self::WARNING_MESSAGE, $functionName),
87+
self::WARNING_MESSAGE,
8588
$stackPtr,
86-
self::WARNING_CODE
89+
self::WARNING_CODE,
90+
[
91+
$functionName,
92+
]
8793
);
8894

8995
if ($fix === true) {

Magento2/Sniffs/Html/HtmlClosingVoidTagsSniff.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,12 @@ public function process(File $phpcsFile, $stackPtr): void
8888
foreach ($matches as $match) {
8989
if (in_array($match[1], self::HTML_VOID_ELEMENTS)) {
9090
$phpcsFile->addWarning(
91-
sprintf(self::WARNING_MESSAGE, $match[0]),
91+
self::WARNING_MESSAGE,
9292
null,
93-
self::WARNING_CODE
93+
self::WARNING_CODE,
94+
[
95+
$match[0],
96+
]
9497
);
9598
}
9699
}

Magento2/Sniffs/Legacy/ClassReferencesInConfigurationFilesSniff.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ public function process(File $phpcsFile, $stackPtr)
4646
$xml = simplexml_load_string($this->getFormattedXML($phpcsFile));
4747
if ($xml === false) {
4848
$phpcsFile->addError(
49-
sprintf(
50-
"Couldn't parse contents of '%s', check that they are in valid XML format",
51-
$phpcsFile->getFilename(),
52-
),
49+
"Couldn't parse contents of '%s', check that they are in valid XML format",
5350
$stackPtr,
54-
self::ERROR_CODE_CONFIG
51+
self::ERROR_CODE_CONFIG,
52+
[
53+
$phpcsFile->getFilename(),
54+
]
5555
);
5656
}
5757

Magento2/Sniffs/Legacy/InstallUpgradeSniff.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,15 @@ public function process(File $phpcsFile, $stackPtr)
101101

102102
if ($folderName === 'data' || $folderName === 'sql') {
103103
$phpcsFile->addError(
104-
$fileInfo->getFilename()." is in an invalid directory ".$fileInfo->getPath().":\n"
104+
"%s is in an invalid directory %s:\n"
105105
. "- Create a data patch within module's Setup/Patch/Data folder for data upgrades.\n"
106106
. "- Use declarative schema approach in module's etc/db_schema.xml file for schema changes.",
107107
0,
108-
self::INVALID_DIRECTORIES_ERROR_CODES[$folderName]
108+
self::INVALID_DIRECTORIES_ERROR_CODES[$folderName],
109+
[
110+
$fileInfo->getFilename(),
111+
$fileInfo->getPath(),
112+
]
109113
);
110114
}
111115
}

Magento2/Sniffs/Legacy/LayoutSniff.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,12 @@ public function process(File $phpcsFile, $stackPtr)
220220

221221
if ($layout === false) {
222222
$phpcsFile->addError(
223-
sprintf(
224-
"Couldn't parse contents of '%s', check that they are in valid XML format",
225-
$phpcsFile->getFilename(),
226-
),
223+
"Couldn't parse contents of '%s', check that they are in valid XML format",
227224
$stackPtr,
228-
self::ERROR_CODE_XML
225+
self::ERROR_CODE_XML,
226+
[
227+
$phpcsFile->getFilename(),
228+
]
229229
);
230230
return;
231231
}
@@ -368,12 +368,12 @@ private function testActionNodeMethods(SimpleXMLElement $layout, File $phpcsFile
368368
foreach ($layout->xpath('//action[' . $methodFilter . ']') as $node) {
369369
$attributes = $node->attributes();
370370
$phpcsFile->addError(
371-
sprintf(
372-
'Call of method "%s" via layout instruction <action> is not allowed.',
373-
$attributes['method']
374-
),
371+
'Call of method "%s" via layout instruction <action> is not allowed.',
375372
dom_import_simplexml($node)->getLineNo() - 1,
376-
self::ERROR_CODE_METHOD_NOT_ALLOWED
373+
self::ERROR_CODE_METHOD_NOT_ALLOWED,
374+
[
375+
$attributes['method'],
376+
]
377377
);
378378
}
379379
}

Magento2/Sniffs/Legacy/ModuleXMLSniff.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ public function process(File $phpcsFile, $stackPtr)
4545
$xml = simplexml_load_string($this->getFormattedXML($phpcsFile));
4646
if ($xml === false) {
4747
$phpcsFile->addError(
48-
sprintf(
49-
"Couldn't parse contents of '%s', check that they are in valid XML format",
50-
$phpcsFile->getFilename(),
51-
),
48+
"Couldn't parse contents of '%s', check that they are in valid XML format",
5249
$stackPtr,
53-
self::ERROR_CODE
50+
self::ERROR_CODE,
51+
[
52+
$phpcsFile->getFilename(),
53+
]
5454
);
5555
return;
5656
}

Magento2/Sniffs/Legacy/ObsoleteConfigNodesSniff.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ public function process(File $phpcsFile, $stackPtr)
4141
$xml = simplexml_load_string($this->getFormattedXML($phpcsFile));
4242
if ($xml === false) {
4343
$phpcsFile->addError(
44-
sprintf(
45-
"Couldn't parse contents of '%s', check that they are in valid XML format",
46-
$phpcsFile->getFilename(),
47-
),
44+
"Couldn't parse contents of '%s', check that they are in valid XML format",
4845
$stackPtr,
49-
self::ERROR_CODE_CONFIG
46+
self::ERROR_CODE_CONFIG,
47+
[
48+
$phpcsFile->getFilename(),
49+
]
5050
);
5151
}
5252

@@ -58,13 +58,13 @@ public function process(File $phpcsFile, $stackPtr)
5858

5959
foreach ($matches as $match) {
6060
$phpcsFile->addError(
61-
sprintf(
62-
self::ERROR_MESSAGE_CONFIG,
63-
$xpath,
64-
$suggestion
65-
),
61+
self::ERROR_MESSAGE_CONFIG,
6662
dom_import_simplexml($match)->getLineNo() - 1,
67-
self::ERROR_CODE_CONFIG
63+
self::ERROR_CODE_CONFIG,
64+
[
65+
$xpath,
66+
$suggestion,
67+
]
6868
);
6969
}
7070
}

Magento2/Sniffs/Legacy/ObsoleteConnectionSniff.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,12 @@ private function validateObsoleteMethod(File $phpcsFile, int $stackPtr)
6363
foreach ($this->obsoleteMethods as $method) {
6464
if ($tokens[$stringPos]['content'] === $method) {
6565
$phpcsFile->addWarning(
66-
sprintf("Contains obsolete method: %s. Please use getConnection method instead.", $method),
66+
"Contains obsolete method: %s. Please use getConnection method instead.",
6767
$stackPtr,
68-
self::OBSOLETE_METHOD_ERROR_CODE
68+
self::OBSOLETE_METHOD_ERROR_CODE,
69+
[
70+
$method,
71+
]
6972
);
7073
}
7174
}

Magento2/Sniffs/Legacy/ObsoleteSystemConfigurationSniff.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ public function process(File $phpcsFile, $stackPtr)
6666
private function invalidXML(File $phpcsFile, int $stackPtr): void
6767
{
6868
$phpcsFile->addError(
69-
sprintf(
70-
"Couldn't parse contents of '%s', check that they are in valid XML format.",
71-
$phpcsFile->getFilename(),
72-
),
69+
"Couldn't parse contents of '%s', check that they are in valid XML format.",
7370
$stackPtr,
74-
self::ERROR_CODE_XML
71+
self::ERROR_CODE_XML,
72+
[
73+
$phpcsFile->getFilename(),
74+
]
7575
);
7676
}
7777

Magento2/Sniffs/Legacy/RestrictedCodeSniff.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ public function process(File $phpcsFile, $stackPtr)
7171
}
7272

7373
$phpcsFile->addError(
74-
sprintf(
75-
self::ERROR_MESSAGE,
76-
$token,
77-
$phpcsFile->getFilename(),
78-
$this->classes[$token]['replacement']
79-
),
74+
self::ERROR_MESSAGE,
8075
$stackPtr,
8176
$this->classes[$token]['warning_code'],
77+
[
78+
$token,
79+
$phpcsFile->getFilename(),
80+
$this->classes[$token]['replacement'],
81+
]
8282
);
8383
}
8484
}

Magento2/Sniffs/Legacy/TableNameSniff.php

+20-20
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,12 @@ private function checkOccurrencesInMethods(File $phpcsFile, int $stackPtr, array
124124

125125
if (strpos($tokens[$paramPos]['content'], '/') !== false) {
126126
$phpcsFile->addError(
127-
sprintf(
128-
self::ERROR_MESSAGE,
129-
$tokens[$paramPos]['content'],
130-
),
127+
self::ERROR_MESSAGE,
131128
$paramPos,
132-
self::ERROR_CODE
129+
self::ERROR_CODE,
130+
[
131+
$tokens[$paramPos]['content'],
132+
]
133133
);
134134
}
135135
}
@@ -142,12 +142,12 @@ private function checkOccurrencesInMethods(File $phpcsFile, int $stackPtr, array
142142
$paramPos = $phpcsFile->findNext(T_PARAM_NAME, $stackPtr + 1);
143143
if (strpos($tokens[$paramPos]['content'], '/') !== false) {
144144
$phpcsFile->addError(
145-
sprintf(
146-
self::ERROR_MESSAGE,
147-
$tokens[$paramPos]['content'],
148-
),
145+
self::ERROR_MESSAGE,
149146
$paramPos,
150-
self::ERROR_CODE
147+
self::ERROR_CODE,
148+
[
149+
$tokens[$paramPos]['content'],
150+
]
151151
);
152152
}
153153
}
@@ -174,12 +174,12 @@ private function checkOccurrencesInProperty(File $phpcsFile, int $stackPtr, arra
174174

175175
if (strpos($tokens[$tableNamePos]['content'], '/') !== false) {
176176
$phpcsFile->addError(
177-
sprintf(
178-
self::ERROR_MESSAGE,
179-
$tokens[$tableNamePos]['content'],
180-
),
177+
self::ERROR_MESSAGE,
181178
$tableNamePos,
182-
self::ERROR_CODE
179+
self::ERROR_CODE,
180+
[
181+
$tokens[$tableNamePos]['content'],
182+
]
183183
);
184184
}
185185
}
@@ -213,12 +213,12 @@ private function checkOccurrencesInArray(File $phpcsFile, int $stackPtr, array $
213213

214214
if (strpos($tokens[$tableNamePos]['content'], '/') !== false) {
215215
$phpcsFile->addError(
216-
sprintf(
217-
self::ERROR_MESSAGE,
218-
$tokens[$tableNamePos]['content'],
219-
),
216+
self::ERROR_MESSAGE,
220217
$tableNamePos,
221-
self::ERROR_CODE
218+
self::ERROR_CODE,
219+
[
220+
$tokens[$tableNamePos]['content'],
221+
]
222222
);
223223
}
224224
}

Magento2/Sniffs/Legacy/WidgetXMLSniff.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ public function process(File $phpcsFile, $stackPtr)
9292
protected function invalidXML(File $phpcsFile, int $stackPtr): void
9393
{
9494
$phpcsFile->addError(
95-
sprintf(
96-
"Couldn't parse contents of '%s', check that they are in valid XML format",
97-
$phpcsFile->getFilename(),
98-
),
95+
"Couldn't parse contents of '%s', check that they are in valid XML format",
9996
$stackPtr,
100-
self::ERROR_CODE_XML
97+
self::ERROR_CODE_XML,
98+
[
99+
$phpcsFile->getFilename(),
100+
]
101101
);
102102
}
103103

Magento2/Sniffs/Less/ColonSpacingSniff.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,14 @@ private function validateSpaces(File $phpcsFile, $stackPtr, array $tokens)
108108
if (false !== strpos($content, ' ')) {
109109
$length = strlen($content);
110110
if ($length !== 1) {
111-
$error = sprintf('Expected 1 space after colon in style definition; %s found', $length);
112-
$phpcsFile->addError($error, $stackPtr, 'After');
111+
$phpcsFile->addError(
112+
'Expected 1 space after colon in style definition; %s found',
113+
$stackPtr,
114+
'After',
115+
[
116+
$length,
117+
]
118+
);
113119
}
114120
}
115121
}

Magento2/Sniffs/Methods/DeprecatedModelMethodSniff.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,12 @@ public function process(File $phpcsFile, $stackPtr)
7070
$methodPosition = $phpcsFile->findNext([T_STRING, T_VARIABLE], $resourcePosition + 1, $endOfStatement);
7171
if ($methodPosition !== false && in_array($tokens[$methodPosition]['content'], $this->methods, true)) {
7272
$phpcsFile->addWarning(
73-
sprintf($this->warningMessage, $tokens[$methodPosition]['content']),
73+
$this->warningMessage,
7474
$stackPtr,
75-
$this->warningCode
75+
$this->warningCode,
76+
[
77+
$tokens[$methodPosition]['content'],
78+
]
7679
);
7780
}
7881
}

Magento2/Sniffs/PHP/AutogeneratedClassNotInConstructorSniff.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ private function validateRequestedClass(File $phpcsFile, int $arrowPosition): vo
9090
}
9191

9292
$phpcsFile->addError(
93-
sprintf(
94-
'Class %s needs to be requested in constructor, ' .
93+
'Class %s needs to be requested in constructor, ' .
9594
'otherwise compiler will not be able to find and generate this class',
96-
$requestedClass
97-
),
9895
$arrowPosition,
99-
self::ERROR_CODE
96+
self::ERROR_CODE,
97+
[
98+
$requestedClass,
99+
]
100100
);
101101
}
102102

0 commit comments

Comments
 (0)