Skip to content

Commit

Permalink
[5.2] sprintf as compiler optimized function (#44037)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkuschel authored Sep 11, 2024
1 parent 203500f commit 689cde9
Show file tree
Hide file tree
Showing 164 changed files with 383 additions and 383 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static function getCsvData($data): \Generator
{
if (!is_iterable($data)) {
throw new \InvalidArgumentException(
sprintf(
\sprintf(
'%s() requires an array or object implementing the Traversable interface, a %s was given.',
__METHOD__,
\is_object($data) ? \get_class($data) : \gettype($data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ActionlogModel extends BaseDatabaseModel implements UserFactoryAwareInterf
public function addLog($messages, $messageLanguageKey, $context, $userId = 0)
{
if (!is_numeric($userId)) {
@trigger_error(sprintf('User ID must be an integer in %s.', __METHOD__), E_USER_DEPRECATED);
@trigger_error(\sprintf('User ID must be an integer in %s.', __METHOD__), E_USER_DEPRECATED);
}

$user = $userId ? $this->getUserFactory()->loadUserById($userId) : $this->getCurrentUser();
Expand Down
6 changes: 3 additions & 3 deletions administrator/components/com_admin/script.php
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ protected function updateManifestCaches()
if (!$installer->refreshManifestCache($extension->extension_id)) {
$this->collectError(
__METHOD__,
new \Exception(sprintf(
new \Exception(\sprintf(
'Error on updating manifest cache: (type, element, folder, client) = (%s, %s, %s, %s)',
$extension->type,
$extension->element,
Expand Down Expand Up @@ -2636,7 +2636,7 @@ public function deleteUnexistingFiles($dryRun = false, $suppressOutput = false)
if (File::delete(JPATH_ROOT . $file)) {
$status['files_deleted'][] = $file;
} else {
$status['files_errors'][] = sprintf('Error on deleting file or folder %s', $file);
$status['files_errors'][] = \sprintf('Error on deleting file or folder %s', $file);
}
}
}
Expand All @@ -2650,7 +2650,7 @@ public function deleteUnexistingFiles($dryRun = false, $suppressOutput = false)
if (Folder::delete(JPATH_ROOT . $folder)) {
$status['folders_deleted'][] = $folder;
} else {
$status['folders_errors'][] = sprintf('Error on deleting file or folder %s', $folder);
$status['folders_errors'][] = \sprintf('Error on deleting file or folder %s', $folder);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ private function checkDefaultValue($data)
try {
$rule->setDatabase($this->getDatabase());
} catch (DatabaseNotFoundException $e) {
@trigger_error(sprintf('Database must be set, this will not be caught anymore in 5.0.'), E_USER_DEPRECATED);
@trigger_error(\sprintf('Database must be set, this will not be caught anymore in 5.0.'), E_USER_DEPRECATED);
$rule->setDatabase(Factory::getContainer()->get(DatabaseInterface::class));
}
}
Expand Down
4 changes: 2 additions & 2 deletions administrator/components/com_finder/src/Indexer/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class Indexer
public function __construct(?DatabaseInterface $db = null)
{
if ($db === null) {
@trigger_error(sprintf('Database will be mandatory in 5.0.'), E_USER_DEPRECATED);
@trigger_error(\sprintf('Database will be mandatory in 5.0.'), E_USER_DEPRECATED);
$db = Factory::getContainer()->get(DatabaseInterface::class);
}

Expand Down Expand Up @@ -506,7 +506,7 @@ public function index($item, $format = 'html')
// Iterate through the contexts and aggregate the tokens per context.
foreach ($state->weights as $context => $multiplier) {
// Run the query to aggregate the tokens for this context..
$db->setQuery(sprintf($query, $multiplier, $context, $context));
$db->setQuery(\sprintf($query, $multiplier, $context, $context));
$db->execute();
}

Expand Down
2 changes: 1 addition & 1 deletion administrator/components/com_finder/src/Indexer/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class Query
public function __construct($options, ?DatabaseInterface $db = null)
{
if ($db === null) {
@trigger_error(sprintf('Database will be mandatory in 5.0.'), E_USER_DEPRECATED);
@trigger_error(\sprintf('Database will be mandatory in 5.0.'), E_USER_DEPRECATED);
$db = Factory::getContainer()->get(DatabaseInterface::class);
}

Expand Down
32 changes: 16 additions & 16 deletions administrator/components/com_joomlaupdate/extract.php
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ public function setIgnoreDirectories(array $ignoreDirectories): void
*/
public function initialize(): void
{
$this->debugMsg(sprintf('Initializing extraction. Filepath: %s', $this->filename));
$this->debugMsg(\sprintf('Initializing extraction. Filepath: %s', $this->filename));
$this->totalSize = @filesize($this->filename) ?: 0;
$this->archiveFileIsBeingRead = false;
$this->currentOffset = 0;
Expand All @@ -639,7 +639,7 @@ public function initialize(): void
$this->readArchiveHeader();

if (!empty($this->getError())) {
$this->debugMsg(sprintf('Error: %s', $this->getError()), self::LOG_ERROR);
$this->debugMsg(\sprintf('Error: %s', $this->getError()), self::LOG_ERROR);

return;
}
Expand Down Expand Up @@ -688,15 +688,15 @@ public function step(): bool
case self::AK_STATE_HEADER:
case self::AK_STATE_DATA:
$runStateHuman = $this->runState === self::AK_STATE_HEADER ? 'HEADER' : 'DATA';
$this->debugMsg(sprintf('Current run state: %s', $runStateHuman), self::LOG_DEBUG);
$this->debugMsg(\sprintf('Current run state: %s', $runStateHuman), self::LOG_DEBUG);

$status = $this->processFileData();
break;

case self::AK_STATE_DATAREAD:
case self::AK_STATE_POSTPROC:
$runStateHuman = $this->runState === self::AK_STATE_DATAREAD ? 'DATAREAD' : 'POSTPROC';
$this->debugMsg(sprintf('Current run state: %s', $runStateHuman), self::LOG_DEBUG);
$this->debugMsg(\sprintf('Current run state: %s', $runStateHuman), self::LOG_DEBUG);

$this->setLastExtractedFileTimestamp($this->fileHeader->timestamp);
$this->processLastExtractedFile();
Expand Down Expand Up @@ -728,7 +728,7 @@ public function step(): bool
$error = $this->getError();

if (!empty($error)) {
$this->debugMsg(sprintf('Step failed with error: %s', $error), self::LOG_ERROR);
$this->debugMsg(\sprintf('Step failed with error: %s', $error), self::LOG_ERROR);
}

// Did we just finish or run into an error?
Expand Down Expand Up @@ -790,7 +790,7 @@ private function getRunningTime(): float
*/
private function processLastExtractedFile(): void
{
$this->debugMsg(sprintf('Processing last extracted entity: %s', $this->lastExtractedFilename), self::LOG_DEBUG);
$this->debugMsg(\sprintf('Processing last extracted entity: %s', $this->lastExtractedFilename), self::LOG_DEBUG);

if (@is_file($this->lastExtractedFilename)) {
@chmod($this->lastExtractedFilename, 0644);
Expand Down Expand Up @@ -1076,7 +1076,7 @@ private function readFileHeader(): bool
default:
$messageTemplate = 'This script cannot handle ZIP compression method %d. '
. 'Only 0 (no compression) and 8 (DEFLATE, gzip) can be handled.';
$actualMessage = sprintf($messageTemplate, $headerData['compmethod']);
$actualMessage = \sprintf($messageTemplate, $headerData['compmethod']);
$this->setError($actualMessage);

return false;
Expand All @@ -1094,7 +1094,7 @@ private function readFileHeader(): bool

// If we have a banned file, let's skip it
if ($isBannedFile) {
$debugMessage = sprintf('Current entity (%s) is banned from extraction and will be skipped over.', $this->fileHeader->file);
$debugMessage = \sprintf('Current entity (%s) is banned from extraction and will be skipped over.', $this->fileHeader->file);
$this->debugMsg($debugMessage, self::LOG_DEBUG);

// Advance the file pointer, skipping exactly the size of the compressed data
Expand Down Expand Up @@ -1178,7 +1178,7 @@ private function createDirectory(): void
}

if ((@mkdir($dirName, $perms, true) === false) && (!$ignore)) {
$this->setError(sprintf('Could not create %s folder', $dirName));
$this->setError(\sprintf('Could not create %s folder', $dirName));
}
}

Expand Down Expand Up @@ -1216,14 +1216,14 @@ private function processFileData(): bool
return $this->processTypeFileCompressed();

case 'default':
$this->setError(sprintf('Unknown compression type %s.', $this->fileHeader->compression));
$this->setError(\sprintf('Unknown compression type %s.', $this->fileHeader->compression));

return false;
}
break;
}

$this->setError(sprintf('Unknown entry type %s.', $this->fileHeader->type));
$this->setError(\sprintf('Unknown entry type %s.', $this->fileHeader->type));

return false;
}
Expand Down Expand Up @@ -1414,7 +1414,7 @@ private function processTypeFileUncompressed(): bool
// Can we write to the file?
if (($outfp === false) && (!$ignore)) {
// An error occurred
$this->setError(sprintf('Could not open %s for writing.', $this->fileHeader->realFile));
$this->setError(\sprintf('Could not open %s for writing.', $this->fileHeader->realFile));

return false;
}
Expand Down Expand Up @@ -1470,7 +1470,7 @@ private function processTypeFileUncompressed(): bool

// Was this a pre-timeout bail out?
if ($leftBytes > 0) {
$this->debugMsg(sprintf('We have %d bytes left to extract in the next step', $leftBytes), self::LOG_DEBUG);
$this->debugMsg(\sprintf('We have %d bytes left to extract in the next step', $leftBytes), self::LOG_DEBUG);
$this->runState = self::AK_STATE_DATA;

return true;
Expand Down Expand Up @@ -1505,7 +1505,7 @@ private function processTypeFileCompressed(): bool

if (($outfp === false) && (!$ignore)) {
// An error occurred
$this->setError(sprintf('Could not open %s for writing.', $this->fileHeader->realFile));
$this->setError(\sprintf('Could not open %s for writing.', $this->fileHeader->realFile));

return false;
}
Expand Down Expand Up @@ -1550,7 +1550,7 @@ private function processTypeFileCompressed(): bool
break;

default:
$this->setError(sprintf('Unknown compression method %s', $this->fileHeader->compression));
$this->setError(\sprintf('Unknown compression method %s', $this->fileHeader->compression));

return false;
}
Expand Down Expand Up @@ -1656,7 +1656,7 @@ private function debugMsg(string $message, int $priority = self::LOG_INFO): void
break;
}

fwrite(self::$logFP, sprintf('%s | %7s | %s' . "\r\n", gmdate('Y-m-d H:i:s'), $priorityString, $message));
fwrite(self::$logFP, \sprintf('%s | %7s | %s' . "\r\n", gmdate('Y-m-d H:i:s'), $priorityString, $message));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions administrator/components/com_joomlaupdate/finalisation.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
* - Also unlike other files, the normal constant defined checks must be within the global namespace declaration and can't be outside of it
*/

namespace
{
namespace {

// Require the restoration environment or fail cold. Prevents direct web access.
\defined('_JOOMLA_UPDATE') or die();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1795,7 +1795,7 @@ public function collectError(string $context, \Throwable $error)

// Log it
Log::add(
sprintf(
\sprintf(
'An error has occurred while running "%s". Code: %s. Message: %s.',
$context,
$error->getCode(),
Expand All @@ -1807,7 +1807,7 @@ public function collectError(string $context, \Throwable $error)

if (JDEBUG) {
$trace = $error->getFile() . ':' . $error->getLine() . PHP_EOL . $error->getTraceAsString();
Log::add(sprintf('An error trace: %s.', $trace), Log::DEBUG, 'Update');
Log::add(\sprintf('An error trace: %s.', $trace), Log::DEBUG, 'Update');
}
}

Expand Down Expand Up @@ -2081,7 +2081,7 @@ public function resetUpdateSource()
$db->execute();
} catch (\Exception $e) {
Log::add(
sprintf(
\sprintf(
'An error has occurred while running "resetUpdateSource". Code: %s. Message: %s.',
$e->getCode(),
$e->getMessage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function __get($name)
$newName = $map[$name];

@trigger_error(
sprintf(
\sprintf(
'MenuField::__get property "%s" is deprecated, and will not work in Joomla 6. Use "%s" property instead.',
$name,
$newName
Expand Down Expand Up @@ -110,7 +110,7 @@ public function __set($name, $value)
$newName = $map[$name];

@trigger_error(
sprintf(
\sprintf(
'MenuField::__set property "%s" is deprecated, and will not work in Joomla 6. Use "%s" property instead.',
$name,
$newName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public function getItem($pk = null)
}

if (!empty($item->id)) {
$item->tags = new TagsHelper();
$item->tags = new TagsHelper();
$item->tags->getTagIds($item->id, 'com_newsfeeds.newsfeed');

// @todo: We probably don't need this in any client - but needs careful validation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ private function processExecutionRules(array $unprocessedRules): array
*/
private function buildExecutionRules(array $executionRules): array
{
// Maps interval strings, use with sprintf($map[intType], $interval)
// Maps interval strings, use with \sprintf($map[intType], $interval)
$intervalStringMap = [
'minutes' => 'PT%dM',
'hours' => 'PT%dH',
Expand All @@ -640,7 +640,7 @@ private function buildExecutionRules(array $executionRules): array
// Rule type for intervals interval-<minute/hours/...>
$intervalType = explode('-', $ruleType)[1];
$interval = $executionRules["interval-$intervalType"];
$buildExpression = sprintf($intervalStringMap[$intervalType], $interval);
$buildExpression = \sprintf($intervalStringMap[$intervalType], $interval);
}

if ($ruleClass === 'cron-expression') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ static function (TaskOption $taskOption): string {
if (is_numeric($locked) && $locked != 0) {
$now = Factory::getDate('now', 'GMT');
$timeout = ComponentHelper::getParams('com_scheduler')->get('timeout', 300);
$timeout = new \DateInterval(sprintf('PT%dS', $timeout));
$timeout = new \DateInterval(\sprintf('PT%dS', $timeout));
$timeoutThreshold = (clone $now)->sub($timeout)->toSql();
$now = $now->toSql();

Expand Down
2 changes: 1 addition & 1 deletion administrator/components/com_scheduler/src/Task/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public function acquireLock(): bool
$now = Factory::getDate('now', 'GMT');

$timeout = ComponentHelper::getParams('com_scheduler')->get('timeout', 300);
$timeout = new \DateInterval(sprintf('PT%dS', $timeout));
$timeout = new \DateInterval(\sprintf('PT%dS', $timeout));
$timeoutThreshold = (clone $now)->sub($timeout)->toSql();
$now = $now->toSql();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function __get(string $name)
if ($name === 'type') {
try {
Log::add(
sprintf(
\sprintf(
'The %1$s property is deprecated. Use %2$s instead.',
$name,
'id'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function enhanceTaskItemForm($context, $data = null): bool
$form = $context;
} else {
throw new \InvalidArgumentException(
sprintf(
\sprintf(
'Argument 0 of %1$s must be an instance of %2$s or %3$s',
__METHOD__,
EventInterface::class,
Expand Down Expand Up @@ -284,7 +284,7 @@ public function standardRoutineHandler(ExecuteTaskEvent $event): void
|| $method->getReturnType()->getName() !== 'int'
) {
$this->logTask(
sprintf(
\sprintf(
'Incorrect routine method signature for %1$s(). See checks in %2$s()',
$method->getName(),
__METHOD__
Expand All @@ -306,7 +306,7 @@ public function standardRoutineHandler(ExecuteTaskEvent $event): void
}
} else {
$this->logTask(
sprintf(
\sprintf(
'Incorrectly configured TASKS_MAP in class %s. Missing valid method for `routine_id` %s',
static::class,
$routineId
Expand Down
Loading

0 comments on commit 689cde9

Please sign in to comment.