Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public function __construct(
}

/**
* @param non-empty-string $key
*
* @return mixed|null
*/
public function load(string $key, string $variableKey)
Expand All @@ -25,6 +27,8 @@ public function load(string $key, string $variableKey)
}

/**
* @param non-empty-string $key
*
* @param mixed $data
*/
public function save(string $key, string $variableKey, $data): void
Expand Down
4 changes: 4 additions & 0 deletions src/Cache/CacheStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ interface CacheStorage
{

/**
* @param non-empty-string $key
*
* @return mixed|null
*/
public function load(string $key, string $variableKey);

/**
* @param non-empty-string $key
*
* @param mixed $data
*/
public function save(string $key, string $variableKey, $data): void;
Expand Down
2 changes: 2 additions & 0 deletions src/Cache/FileCacheStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ public function save(string $key, string $variableKey, $data): void
}

/**
* @param non-empty-string $key
*
* @return array{string, string, string}
*/
private function getFilePaths(string $key): array
Expand Down
4 changes: 2 additions & 2 deletions src/Command/ErrorFormatter/BaselinePhpErrorFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function formatErrors(
if (count($identifiers) > 0) {
foreach ($identifiers as $identifier => $identifierCount) {
$php .= sprintf(
"\$ignoreErrors[] = [\n\t%s => %s,\n\t'identifier' => %s,\n\t'count' => %d,\n\t'path' => __DIR__ . %s,\n];\n",
"\$ignoreErrors[] = [\n\t%s => %s,\n\t'identifier' => %s,\n\t'count' => %s,\n\t'path' => __DIR__ . %s,\n];\n",
var_export($messageKey, true),
var_export(Helpers::escape($message), true),
var_export(Helpers::escape($identifier), true),
Expand All @@ -97,7 +97,7 @@ public function formatErrors(
}
} else {
$php .= sprintf(
"\$ignoreErrors[] = [\n\t%s => %s,\n\t'count' => %d,\n\t'path' => __DIR__ . %s,\n];\n",
"\$ignoreErrors[] = [\n\t%s => %s,\n\t'count' => %s,\n\t'path' => __DIR__ . %s,\n];\n",
var_export($messageKey, true),
var_export(Helpers::escape($message), true),
var_export($totalCount, true),
Expand Down
2 changes: 1 addition & 1 deletion src/Command/ErrorFormatter/CheckstyleErrorFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function formatErrors(

foreach ($errors as $error) {
$output->writeRaw(sprintf(
' <error line="%d" column="1" severity="error" message="%s"%s />',
' <error line="%s" column="1" severity="error" message="%s"%s />',
$this->escape((string) $error->getLine()),
$this->escape($error->getMessage()),
$error->getIdentifier() !== null ? sprintf(' source="%s"', $this->escape($error->getIdentifier())) : '',
Expand Down
2 changes: 1 addition & 1 deletion src/Command/ErrorFormatter/RawErrorFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function formatErrors(

$output->writeRaw(
sprintf(
'%s:%d:%s%s',
'%s:%s:%s%s',
$fileSpecificError->getFile(),
$fileSpecificError->getLine() ?? '?',
$fileSpecificError->getMessage(),
Expand Down
6 changes: 3 additions & 3 deletions src/Command/ErrorFormatter/TableErrorFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public function formatErrors(
$output->writeLineFormatted('💡 Tip of the Day:');
$output->writeLineFormatted(sprintf(
"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.",
AnalyseCommand::OPTION_LEVEL,
AnalyseCommand::DEFAULT_LEVEL,
(int) AnalyseCommand::OPTION_LEVEL,
(int) AnalyseCommand::DEFAULT_LEVEL,
));
$output->writeLineFormatted('');
}
Expand Down Expand Up @@ -111,7 +111,7 @@ public function formatErrors(

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

} elseif (is_string($this->editorUrl)) {
$url = str_replace(
Expand Down
2 changes: 1 addition & 1 deletion src/Command/FixerWorkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$loop = new StreamSelectLoop();
$tcpConnector = new TcpConnector($loop);
$tcpConnector->connect(sprintf('127.0.0.1:%d', $serverPort))->then(function (ConnectionInterface $connection) use ($container, $inceptionResult, $configuration, $input, $ignoredErrorHelperResult, $loop): void {
$tcpConnector->connect(sprintf('127.0.0.1:%d', (int) $serverPort))->then(function (ConnectionInterface $connection) use ($container, $inceptionResult, $configuration, $input, $ignoredErrorHelperResult, $loop): void {
// phpcs:disable SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
$jsonInvalidUtf8Ignore = defined('JSON_INVALID_UTF8_IGNORE') ? JSON_INVALID_UTF8_IGNORE : 0;
// phpcs:enable
Expand Down
2 changes: 1 addition & 1 deletion src/Command/WorkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$analysedFiles = array_fill_keys($analysedFiles, true);

$tcpConnector = new TcpConnector($loop);
$tcpConnector->connect(sprintf('127.0.0.1:%d', $port))->then(function (ConnectionInterface $connection) use ($container, $identifier, $output, $analysedFiles, $tmpFile, $insteadOfFile): void {
$tcpConnector->connect(sprintf('127.0.0.1:%d', (int) $port))->then(function (ConnectionInterface $connection) use ($container, $identifier, $output, $analysedFiles, $tmpFile, $insteadOfFile): void {
// phpcs:disable SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly
$jsonInvalidUtf8Ignore = defined('JSON_INVALID_UTF8_IGNORE') ? JSON_INVALID_UTF8_IGNORE : 0;
// phpcs:enable
Expand Down
9 changes: 8 additions & 1 deletion src/Reflection/Php/PhpMethodReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,14 @@ private function isVariadic(): bool

$className = $declaringClass->getName();
if ($declaringClass->isAnonymous()) {
$className = sprintf('%s:%s:%s', VariadicMethodsVisitor::ANONYMOUS_CLASS_PREFIX, $declaringClass->getNativeReflection()->getStartLine(), $declaringClass->getNativeReflection()->getEndLine());
$startLine = $declaringClass->getNativeReflection()->getStartLine();
$endLine = $declaringClass->getNativeReflection()->getEndLine();

if ($endLine === false) {
$endLine = 0;
}

$className = sprintf('%s:%s:%s', VariadicMethodsVisitor::ANONYMOUS_CLASS_PREFIX, $startLine, $endLine);
}
if (array_key_exists($className, VariadicMethodsVisitor::$cache)) {
if (array_key_exists($this->reflection->getName(), VariadicMethodsVisitor::$cache[$className])) {
Expand Down
2 changes: 1 addition & 1 deletion src/Testing/PHPStanTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ protected function assertNoErrors(array $errors): void
$messages = [];
foreach ($errors as $error) {
if ($error instanceof Error) {
$messages[] = sprintf("- %s\n in %s on line %d\n", rtrim($error->getMessage(), '.'), $error->getFile(), $error->getLine());
$messages[] = sprintf("- %s\n in %s on line %d\n", rtrim($error->getMessage(), '.'), $error->getFile(), $error->getLine() ?? 0);
} else {
$messages[] = $error;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Testing/RuleTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ private function gatherAnalyserErrorsWithDelayedErrors(array $files): array

if ($this->shouldFailOnPhpErrors() && count($analyserResult->getAllPhpErrors()) > 0) {
$this->fail(implode("\n", array_map(
static fn (Error $error): string => sprintf('%s on %s:%d', $error->getMessage(), $error->getFile(), $error->getLine()),
static fn (Error $error): string => sprintf('%s on %s:%d', $error->getMessage(), $error->getFile(), $error->getLine() ?? 0),
$analyserResult->getAllPhpErrors(),
)));
}
Expand Down
Loading