Commit d3f6c5f0 authored by Wouter Wolters's avatar Wouter Wolters Committed by Andreas Fernandez
Browse files

[TASK] Use a static closure call if possible for better scoping

In some cases it can improve performance too.

Resolves: #95210
Releases: master
Change-Id: I4915bb1391ec99ff891248545080640965c8f62a
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/70204

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: Simon Schaufelberger's avatarSimon Schaufelberger <simonschaufi+typo3@gmail.com>
Tested-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Simon Schaufelberger's avatarSimon Schaufelberger <simonschaufi+typo3@gmail.com>
Reviewed-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
parent 6e6b4ee4
......@@ -85,7 +85,7 @@ class NodeVisitor extends NodeVisitorAbstract
);
if (!empty($matches['annotations'])) {
$this->matches[$node->getLine()] = array_map(function ($value) {
$this->matches[$node->getLine()] = array_map(static function ($value) {
return '@' . $value;
}, $matches['annotations']);
}
......
......@@ -178,7 +178,7 @@ class checkIntegrityCsvFixtures
// Extend / reduce to needed size
$csvLine = array_slice(array_pad($csvLine, $neededColumns, ''), 0, $neededColumns);
$isComment = false;
$line = array_reduce($csvLine, function ($carry, $column) use (&$isComment) {
$line = array_reduce($csvLine, static function ($carry, $column) use (&$isComment) {
if ($carry === null && substr($column, 0, 2) === '# ') {
$isComment = true;
$carry .= $column;
......
......@@ -89,7 +89,7 @@ class ExtensionScannerRstFileReferencesChecker
->notName(['Changelog-*.rst', 'Index.rst', 'Master.rst'])
->in(__DIR__ . '/../../typo3/sysext/core/Documentation/Changelog');
$fileNames = array_map(
function (SplFileInfo $file) {
static function (SplFileInfo $file) {
return $file->getFilename();
},
iterator_to_array($finder)
......
......@@ -102,5 +102,6 @@ return (new \PhpCsFixer\Config())
'single_trait_insert_per_statement' => true,
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
'whitespace_after_comma_in_array' => true,
'static_lambda' => true,
])
->setFinder($finder);
......@@ -16,7 +16,7 @@
* This file is defined in FunctionalTests.xml and called by phpunit
* before instantiating the test suites.
*/
call_user_func(function () {
call_user_func(static function () {
$testbase = new \TYPO3\TestingFramework\Core\Testbase();
$testbase->defineOriginalRootPath();
$testbase->createDirectory(ORIGINAL_ROOT . 'typo3temp/var/tests');
......
......@@ -133,12 +133,12 @@ class MainController implements SingletonInterface
$requestId = $request->getAttribute('adminPanelRequestId');
$data = $cache->get($requestId);
$moduleResources = ResourceUtility::getAdditionalResourcesForModules($this->modules);
$settingsModules = array_filter($this->modules, function (ModuleInterface $module) {
$settingsModules = array_filter($this->modules, static function (ModuleInterface $module) {
return $module instanceof PageSettingsProviderInterface;
});
$parentModules = array_filter(
$this->modules,
function (ModuleInterface $module) {
static function (ModuleInterface $module) {
return $module instanceof SubmoduleProviderInterface && $module instanceof ShortInfoProviderInterface;
}
);
......
......@@ -57,7 +57,7 @@ class DebugModule extends AbstractModule implements ShortInfoProviderInterface
public function getShortInfo(): string
{
$errorsAndWarnings = array_filter(InMemoryLogWriter::$log, function (LogRecord $entry) {
$errorsAndWarnings = array_filter(InMemoryLogWriter::$log, static function (LogRecord $entry) {
return LogLevel::normalizeLevel($entry->getLevel()) <= 4;
});
return sprintf($this->getLanguageService()->sL(
......
......@@ -495,7 +495,7 @@ class NewContentElementController
{
if (isset($wizardGroup[$key])) {
$wizardGroup[$key] = GeneralUtility::trimExplode(',', $wizardGroup[$key]);
$wizardGroup[$key] = array_map(function ($s) {
$wizardGroup[$key] = array_map(static function ($s) {
return $s . '.';
}, $wizardGroup[$key]);
}
......
......@@ -128,14 +128,14 @@ class TreeController
foreach ($items as $item) {
$stateIdentifier = $item['stateIdentifier'];
$parentIdentifier = $item['parentIdentifier'];
$siblings = array_filter($items, function ($itemInArray) use ($parentIdentifier) {
$siblings = array_filter($items, static function ($itemInArray) use ($parentIdentifier) {
if ($itemInArray['parentIdentifier'] === $parentIdentifier) {
return true;
}
return false;
});
$positionFound = false;
$siblingsBeforeInSameDepth = array_filter($siblings, function ($itemInArray) use ($stateIdentifier, &$positionFound): bool {
$siblingsBeforeInSameDepth = array_filter($siblings, static function ($itemInArray) use ($stateIdentifier, &$positionFound): bool {
if ($itemInArray['stateIdentifier'] === $stateIdentifier) {
$positionFound = true;
return false;
......
......@@ -113,7 +113,7 @@ class LocalizationController
}
// Language "All" should not appear as a source of translations (see bug 92757) and keys should be sequential
$availableLanguages = array_values(
array_filter($availableLanguages, function (array $languageRecord): bool {
array_filter($availableLanguages, static function (array $languageRecord): bool {
return (int)$languageRecord['uid'] !== -1;
})
);
......
......@@ -442,7 +442,7 @@ abstract class AbstractItemProvider
return ArrayUtility::keepItemsInArray(
$items,
$result['pageTsConfig']['TCEFORM.'][$table . '.'][$fieldName . '.']['keepItems'],
function ($value) {
static function ($value) {
return $value[1];
}
);
......@@ -590,7 +590,7 @@ abstract class AbstractItemProvider
}
$allowedStorageIds = array_map(
function (ResourceStorage $storage) {
static function (ResourceStorage $storage) {
return $storage->getUid();
},
$this->getBackendUser()->getFileStorages()
......@@ -598,7 +598,7 @@ abstract class AbstractItemProvider
return array_filter(
$items,
function (array $item) use ($allowedStorageIds) {
static function (array $item) use ($allowedStorageIds) {
$itemValue = $item[1] ?? null;
return empty($itemValue)
|| in_array((int)$itemValue, $allowedStorageIds, true);
......
......@@ -293,7 +293,7 @@ class TcaSelectItems extends AbstractItemProvider implements FormDataProviderInt
$direction = strtolower($direction);
@usort(
$items,
function ($item1, $item2) use ($direction) {
static function ($item1, $item2) use ($direction) {
if ($direction === 'desc') {
return (strcasecmp($item1[0], $item2[0]) <= 0) ? 1 : 0;
}
......@@ -305,7 +305,7 @@ class TcaSelectItems extends AbstractItemProvider implements FormDataProviderInt
$direction = strtolower($direction);
@usort(
$items,
function ($item1, $item2) use ($direction) {
static function ($item1, $item2) use ($direction) {
if ($direction === 'desc') {
return (strcasecmp($item1[1], $item2[1]) <= 0) ? 1 : 0;
}
......
......@@ -311,7 +311,7 @@ class PreviewUriBuilder
protected function prefixAttributeNames(string $prefix, array $attributes): array
{
$attributeNames = array_map(
function (string $name) use ($prefix): string {
static function (string $name) use ($prefix): string {
return $prefix . $name;
},
array_keys($attributes)
......
......@@ -151,7 +151,7 @@ class ServiceProvider extends AbstractServiceProvider
public static function getBackendRoutesWarmer(ContainerInterface $container): \Closure
{
return function (CacheWarmupEvent $event) use ($container) {
return static function (CacheWarmupEvent $event) use ($container) {
if ($event->hasGroup('system')) {
$cache = $container->get('cache.core');
$cacheIdentifier = 'BackendRoutes_' . sha1((string)(new Typo3Version()) . Environment::getProjectPath() . 'BackendRoutes');
......
......@@ -143,12 +143,12 @@ class FileStorageTreeProvider
$storages = $user->getFileStorages();
foreach ($storages as $resourceStorage) {
$processingFolders = $resourceStorage->getProcessingFolders();
$processingFolderIdentifiers = array_map(function ($folder) {
$processingFolderIdentifiers = array_map(static function ($folder) {
return $folder->getIdentifier();
}, $processingFolders);
$resourceStorage->addFileAndFolderNameFilter(function ($itemName, $itemIdentifier, $parentIdentifier, array $additionalInformation, DriverInterface $driver) use ($resourceStorage, $search, $processingFolderIdentifiers) {
$resourceStorage->addFileAndFolderNameFilter(static function ($itemName, $itemIdentifier, $parentIdentifier, array $additionalInformation, DriverInterface $driver) use ($resourceStorage, $search, $processingFolderIdentifiers) {
// Skip items in processing folders
$isInProcessingFolder = array_filter($processingFolderIdentifiers, function ($processingFolderIdentifier) use ($parentIdentifier) {
$isInProcessingFolder = array_filter($processingFolderIdentifiers, static function ($processingFolderIdentifier) use ($parentIdentifier) {
return stripos($parentIdentifier, $processingFolderIdentifier) !== false;
});
if (!empty($isInProcessingFolder)) {
......@@ -238,7 +238,7 @@ class FileStorageTreeProvider
{
$fileMounts = $resourceStorage->getFileMounts();
if (!empty($fileMounts)) {
return array_map(function ($fileMountInfo) {
return array_map(static function ($fileMountInfo) {
return [
'folder' => $fileMountInfo['folder'],
'name' => $fileMountInfo['title'],
......
......@@ -175,7 +175,7 @@ class BackendUtility
{
return array_filter(
$record,
function (string $propertyName): bool {
static function (string $propertyName): bool {
return $propertyName[0] !== '_';
},
ARRAY_FILTER_USE_KEY
......@@ -193,7 +193,7 @@ class BackendUtility
{
return array_filter(
$propertyNames,
function (string $propertyName): bool {
static function (string $propertyName): bool {
return $propertyName[0] !== '_';
}
);
......
......@@ -739,7 +739,7 @@ class PageLayoutView implements LoggerAwareInterface
}
$defaultLanguageElements = [];
array_walk($defaultLanguageElementsByColumn, function (array $columnContent) use (&$defaultLanguageElements) {
array_walk($defaultLanguageElementsByColumn, static function (array $columnContent) use (&$defaultLanguageElements) {
$defaultLanguageElements = array_merge($defaultLanguageElements, $columnContent);
});
......
......@@ -7,6 +7,6 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use TYPO3\CMS\Core\DependencyInjection\PublicServicePass;
return function (ContainerConfigurator $container, ContainerBuilder $containerBuilder) {
return static function (ContainerConfigurator $container, ContainerBuilder $containerBuilder) {
$containerBuilder->addCompilerPass(new PublicServicePass('backend.controller'));
};
......@@ -14,7 +14,7 @@
*/
// Set up the application for the backend
call_user_func(function () {
call_user_func(static function () {
$classLoader = require __DIR__ . '/../../../../../../vendor/autoload.php';
\TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::run(1, \TYPO3\CMS\Core\Core\SystemEnvironmentBuilder::REQUESTTYPE_BE);
\TYPO3\CMS\Core\Core\Bootstrap::init($classLoader)->get(\TYPO3\CMS\Backend\Http\Application::class)->run();
......
......@@ -132,7 +132,7 @@ class FormDataCompilerTest extends UnitTestCase
*/
public function compileReturnsResultArrayWithAdditionalDataFormFormDataGroup(): void
{
$this->formDataGroupProphecy->compile(Argument::cetera())->will(function ($arguments) {
$this->formDataGroupProphecy->compile(Argument::cetera())->will(static function ($arguments) {
$result = $arguments[0];
$result['databaseRow'] = 'newData';
return $result;
......@@ -170,7 +170,7 @@ class FormDataCompilerTest extends UnitTestCase
*/
public function compileThrowsExceptionIfFormDataGroupRemovedKeysFromResultArray(): void
{
$this->formDataGroupProphecy->compile(Argument::cetera())->will(function ($arguments) {
$this->formDataGroupProphecy->compile(Argument::cetera())->will(static function ($arguments) {
$result = $arguments[0];
unset($result['tableName']);
return $result;
......@@ -185,7 +185,7 @@ class FormDataCompilerTest extends UnitTestCase
*/
public function compileThrowsExceptionIfFormDataGroupAddedKeysToResultArray(): void
{
$this->formDataGroupProphecy->compile(Argument::cetera())->will(function ($arguments) {
$this->formDataGroupProphecy->compile(Argument::cetera())->will(static function ($arguments) {
$result = $arguments[0];
$result['newKey'] = 'newData';
return $result;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment