Skip to content

Commit 9ab8480

Browse files
staabmondrejmirtes
authored andcommitted
Fix sprintf() types and placeholders
1 parent cbae9b7 commit 9ab8480

File tree

12 files changed

+29
-12
lines changed

12 files changed

+29
-12
lines changed

src/Cache/Cache.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public function __construct(
1717
}
1818

1919
/**
20+
* @param non-empty-string $key
21+
*
2022
* @return mixed|null
2123
*/
2224
public function load(string $key, string $variableKey)
@@ -25,6 +27,8 @@ public function load(string $key, string $variableKey)
2527
}
2628

2729
/**
30+
* @param non-empty-string $key
31+
*
2832
* @param mixed $data
2933
*/
3034
public function save(string $key, string $variableKey, $data): void

src/Cache/CacheStorage.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ interface CacheStorage
66
{
77

88
/**
9+
* @param non-empty-string $key
10+
*
911
* @return mixed|null
1012
*/
1113
public function load(string $key, string $variableKey);
1214

1315
/**
16+
* @param non-empty-string $key
17+
*
1418
* @param mixed $data
1519
*/
1620
public function save(string $key, string $variableKey, $data): void;

src/Cache/FileCacheStorage.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ public function save(string $key, string $variableKey, $data): void
101101
}
102102

103103
/**
104+
* @param non-empty-string $key
105+
*
104106
* @return array{string, string, string}
105107
*/
106108
private function getFilePaths(string $key): array

src/Command/ErrorFormatter/BaselinePhpErrorFormatter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function formatErrors(
8787
if (count($identifiers) > 0) {
8888
foreach ($identifiers as $identifier => $identifierCount) {
8989
$php .= sprintf(
90-
"\$ignoreErrors[] = [\n\t%s => %s,\n\t'identifier' => %s,\n\t'count' => %d,\n\t'path' => __DIR__ . %s,\n];\n",
90+
"\$ignoreErrors[] = [\n\t%s => %s,\n\t'identifier' => %s,\n\t'count' => %s,\n\t'path' => __DIR__ . %s,\n];\n",
9191
var_export($messageKey, true),
9292
var_export(Helpers::escape($message), true),
9393
var_export(Helpers::escape($identifier), true),
@@ -97,7 +97,7 @@ public function formatErrors(
9797
}
9898
} else {
9999
$php .= sprintf(
100-
"\$ignoreErrors[] = [\n\t%s => %s,\n\t'count' => %d,\n\t'path' => __DIR__ . %s,\n];\n",
100+
"\$ignoreErrors[] = [\n\t%s => %s,\n\t'count' => %s,\n\t'path' => __DIR__ . %s,\n];\n",
101101
var_export($messageKey, true),
102102
var_export(Helpers::escape($message), true),
103103
var_export($totalCount, true),

src/Command/ErrorFormatter/CheckstyleErrorFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function formatErrors(
4444

4545
foreach ($errors as $error) {
4646
$output->writeRaw(sprintf(
47-
' <error line="%d" column="1" severity="error" message="%s"%s />',
47+
' <error line="%s" column="1" severity="error" message="%s"%s />',
4848
$this->escape((string) $error->getLine()),
4949
$this->escape($error->getMessage()),
5050
$error->getIdentifier() !== null ? sprintf(' source="%s"', $this->escape($error->getIdentifier())) : '',

src/Command/ErrorFormatter/RawErrorFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function formatErrors(
3030

3131
$output->writeRaw(
3232
sprintf(
33-
'%s:%d:%s%s',
33+
'%s:%s:%s%s',
3434
$fileSpecificError->getFile(),
3535
$fileSpecificError->getLine() ?? '?',
3636
$fileSpecificError->getMessage(),

src/Command/ErrorFormatter/TableErrorFormatter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ public function formatErrors(
6464
$output->writeLineFormatted('💡 Tip of the Day:');
6565
$output->writeLineFormatted(sprintf(
6666
"PHPStan is performing only the most basic checks.\nYou can pass a higher rule level through the <fg=cyan>--%s</> option\n(the default and current level is %d) to analyse code more thoroughly.",
67-
AnalyseCommand::OPTION_LEVEL,
68-
AnalyseCommand::DEFAULT_LEVEL,
67+
(int) AnalyseCommand::OPTION_LEVEL,
68+
(int) AnalyseCommand::DEFAULT_LEVEL,
6969
));
7070
$output->writeLineFormatted('');
7171
}
@@ -111,7 +111,7 @@ public function formatErrors(
111111

112112
if (getenv('TERMINAL_EMULATOR') === 'JetBrains-JediTerm') {
113113
$title = $this->relativePathHelper->getRelativePath($filePath);
114-
$message .= sprintf("\nat %s:%d", $title, $error->getLine());
114+
$message .= sprintf("\nat %s:%d", $title, $error->getLine() ?? 0);
115115

116116
} elseif (is_string($this->editorUrl)) {
117117
$url = str_replace(

src/Command/FixerWorkerCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
130130

131131
$loop = new StreamSelectLoop();
132132
$tcpConnector = new TcpConnector($loop);
133-
$tcpConnector->connect(sprintf('127.0.0.1:%d', $serverPort))->then(function (ConnectionInterface $connection) use ($container, $inceptionResult, $configuration, $input, $ignoredErrorHelperResult, $loop): void {
133+
$tcpConnector->connect(sprintf('127.0.0.1:%d', (int) $serverPort))->then(function (ConnectionInterface $connection) use ($container, $inceptionResult, $configuration, $input, $ignoredErrorHelperResult, $loop): void {
134134
// phpcs:disable SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
135135
$jsonInvalidUtf8Ignore = defined('JSON_INVALID_UTF8_IGNORE') ? JSON_INVALID_UTF8_IGNORE : 0;
136136
// phpcs:enable

src/Command/WorkerCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
142142
$analysedFiles = array_fill_keys($analysedFiles, true);
143143

144144
$tcpConnector = new TcpConnector($loop);
145-
$tcpConnector->connect(sprintf('127.0.0.1:%d', $port))->then(function (ConnectionInterface $connection) use ($container, $identifier, $output, $analysedFiles, $tmpFile, $insteadOfFile): void {
145+
$tcpConnector->connect(sprintf('127.0.0.1:%d', (int) $port))->then(function (ConnectionInterface $connection) use ($container, $identifier, $output, $analysedFiles, $tmpFile, $insteadOfFile): void {
146146
// phpcs:disable SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
147147
$jsonInvalidUtf8Ignore = defined('JSON_INVALID_UTF8_IGNORE') ? JSON_INVALID_UTF8_IGNORE : 0;
148148
// phpcs:enable

src/Reflection/Php/PhpMethodReflection.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,14 @@ private function isVariadic(): bool
255255

256256
$className = $declaringClass->getName();
257257
if ($declaringClass->isAnonymous()) {
258-
$className = sprintf('%s:%s:%s', VariadicMethodsVisitor::ANONYMOUS_CLASS_PREFIX, $declaringClass->getNativeReflection()->getStartLine(), $declaringClass->getNativeReflection()->getEndLine());
258+
$startLine = $declaringClass->getNativeReflection()->getStartLine();
259+
$endLine = $declaringClass->getNativeReflection()->getEndLine();
260+
261+
if ($endLine === false) {
262+
$endLine = 0;
263+
}
264+
265+
$className = sprintf('%s:%s:%s', VariadicMethodsVisitor::ANONYMOUS_CLASS_PREFIX, $startLine, $endLine);
259266
}
260267
if (array_key_exists($className, VariadicMethodsVisitor::$cache)) {
261268
if (array_key_exists($this->reflection->getName(), VariadicMethodsVisitor::$cache[$className])) {

0 commit comments

Comments
 (0)