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

Lines changed: 10 additions & 7 deletions
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

Lines changed: 10 additions & 4 deletions
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

Lines changed: 5 additions & 2 deletions
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 6 additions & 2 deletions
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

Lines changed: 10 additions & 10 deletions
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 11 additions & 11 deletions
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

Lines changed: 5 additions & 2 deletions
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

Lines changed: 5 additions & 5 deletions
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

0 commit comments

Comments
 (0)