Skip to content

Commit

Permalink
Merge pull request #186 from simonschaufi/static-functions
Browse files Browse the repository at this point in the history
  • Loading branch information
IchHabRecht authored Apr 19, 2022
2 parents a46b7b7 + 0cd56b4 commit 30e48d7
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Classes/Aggregate/AbstractAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected function removeHiddenContentElements()

$this->maskConfiguration['tt_content']['elements'] = array_filter(
$this->maskConfiguration['tt_content']['elements'],
function (array $element) {
static function (array $element) {
return empty($element['hidden']);
}
);
Expand All @@ -93,7 +93,7 @@ protected function removeCoreFields()
}
$this->maskConfiguration[$table]['tca'] = array_filter(
$this->maskConfiguration[$table]['tca'],
function ($field) {
static function ($field) {
return empty($field['coreField']);
}
);
Expand Down
8 changes: 4 additions & 4 deletions Classes/Aggregate/ContentRenderingAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,12 @@ protected function addDatabaseQueryProcessorForField($table, $columnName, $index
$overrideColumns = $GLOBALS['TCA'][$table]['columns'][$columnName]['config']['foreign_record_defaults'];
} elseif (!empty($GLOBALS['TCA'][$table]['columns'][$columnName]['config']['overrideChildTca']['columns'])) {
$overrideColumns = array_map(
function ($value) {
static function ($value) {
return $value['config']['default'];
},
array_filter(
$GLOBALS['TCA'][$table]['columns'][$columnName]['config']['overrideChildTca']['columns'],
function ($item) {
static function ($item) {
return isset($item['config']['default']);
}
)
Expand All @@ -267,7 +267,7 @@ function ($item) {
if (!empty($this->maskConfiguration[$table]['tca'][$columnName]['cTypes'])) {
$types = array_combine(
array_map(
function ($value) {
static function ($value) {
return 'CType' . $value;
},
range(1, count($this->maskConfiguration[$table]['tca'][$columnName]['cTypes']))
Expand All @@ -285,7 +285,7 @@ function ($value) {

uksort($markerArray, 'strnatcasecmp');
$markers = implode("\n ", array_map(
function ($key, $value) {
static function ($key, $value) {
return 'markers.' . $key . (strpos($key, '.') === false ? '.value' : '') . ' = ' . $value;
},
array_keys($markerArray),
Expand Down
2 changes: 1 addition & 1 deletion Classes/Aggregate/InlineContentCTypeAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function addData(array \$result)
\$result['processedTca']['columns']['CType']['config']['items'] = array_filter(
\$result['processedTca']['columns']['CType']['config']['items'],
function (\$item) use (\$cTypes) {
static function (\$item) use (\$cTypes) {
return in_array(\$item[1], \$cTypes);
}
);
Expand Down
2 changes: 1 addition & 1 deletion Classes/Aggregate/InlineContentColPosAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function process()
);

$flattenedInlineFields = [];
array_walk_recursive($inlineFields, function ($field) use (&$flattenedInlineFields) {
array_walk_recursive($inlineFields, static function ($field) use (&$flattenedInlineFields) {
$flattenedInlineFields[] = $field . '_parent';
});
sort($flattenedInlineFields);
Expand Down
2 changes: 1 addition & 1 deletion Classes/Aggregate/TtContentOverridesAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected function addTableTypes(array $tableConfiguration)
$newTypeFields = array_intersect_key(
$tableConfiguration['types'],
array_combine(
array_map(function ($value) {
array_map(static function ($value) {
return 'mask_' . $value;
}, $types),
$types
Expand Down
12 changes: 8 additions & 4 deletions Classes/Controller/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ protected function prepareConfiguration(string $vendorName, string $extensionNam
// Find all used fields in elements and foreign tables
$columns = [];
$closure = null;
$closure = function ($value) use ($aggregatedConfiguration, &$columns, &$closure) {
$closure = static function ($value) use ($aggregatedConfiguration, &$columns, &$closure) {
foreach (($value['columns'] ?? []) as $field) {
$columns[] = $field;
if (!empty($aggregatedConfiguration[$field]['tca'])) {
Expand Down Expand Up @@ -510,17 +510,21 @@ protected function replaceExtensionKey($vendorName, $extensionKey, $string)
*/
protected function sortFiles(array $files)
{
uksort($files, function ($a, $b) {
uksort($files, static function ($a, $b) {
if (substr_count($a, '/') === 0 && substr_count($b, '/') > 0) {
return -1;
} elseif (substr_count($a, '/') > 0 && substr_count($b, '/') === 0) {
}

if (substr_count($a, '/') > 0 && substr_count($b, '/') === 0) {
return 1;
}

if (strpos($b, dirname($a)) === 0 || strpos($a, dirname($b)) === 0) {
if (substr_count($a, '/') > substr_count($b, '/')) {
return 1;
} elseif (substr_count($a, '/') < substr_count($b, '/')) {
}

if (substr_count($a, '/') < substr_count($b, '/')) {
return -1;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/FileCollection/SqlFileCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected function processAggregateCollection()
unset($aggregatedFields['KEY ' . $index]);
}

array_walk($aggregatedFields, function (&$definition, $field) {
array_walk($aggregatedFields, static function (&$definition, $field) {
$definition = sprintf(' %s %s', $field, $definition);
});
$fieldDefinitions = implode(',' . PHP_EOL, $aggregatedFields);
Expand Down
2 changes: 1 addition & 1 deletion Classes/FlagResolver/AbstractFlagResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(DependencyOrderingService $dependencyOrderingService
public function resolveFlags(array $fileInformation)
{
$files = array_map(
function ($information) {
static function ($information) {
return $information['content'];
},
$fileInformation
Expand Down
2 changes: 1 addition & 1 deletion Classes/FlagResolver/PhpFileFlag/ClosureFunctionFlag.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function isEnabled($flags)
public function execute($content)
{
return <<<EOS
call_user_func(function () {
call_user_func(static function () {
{$content}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function validateProcessedRowDataFromPageLayoutViewDrawItem()
$subject->preProcess($pageLayoutView, $drawItem, $headerContent, $itemContent, $row);

// Get variable container
$closure = \Closure::bind(function () use ($viewMock) {
$closure = \Closure::bind(static function () use ($viewMock) {
return $viewMock->baseRenderingContext;
}, null, StandaloneView::class);
$renderingContext = $closure();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function closureFunctionIsApplied($filePattern)
$this->assertNotEmpty($files);

foreach ($files as $file => $fileContent) {
$this->assertStringContainsString('call_user_func(function () {', $fileContent);
$this->assertStringContainsString('call_user_func(static function () {', $fileContent);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/FileCollection/PhpFileCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ public function getFilesCombinesPhpFileFlags()

$this->assertArrayHasKey('ext_tables.php', $files);
$this->assertContains('defined(\'TYPO3_MODE\') || die();', $files['ext_tables.php']);
$this->assertContains('call_user_func(function () {', $files['ext_tables.php']);
$this->assertContains('call_user_func(static function () {', $files['ext_tables.php']);
}
}
6 changes: 3 additions & 3 deletions ext_tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

defined('TYPO3_MODE') || die();

call_user_func(function () {
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerModule(
call_user_func(static function () {
TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerModule(
'IchHabRecht.mask_export',
'tools',
'mask_export',
Expand All @@ -20,7 +20,7 @@

$maskElements = array_filter(
$GLOBALS['TCA']['tt_content']['types'] ?? [],
function ($key) {
static function ($key) {
return strpos((string)$key, 'mask_') === 0;
},
ARRAY_FILTER_USE_KEY
Expand Down

0 comments on commit 30e48d7

Please sign in to comment.