Issue Feature Closed

#88754Codesmell GeneralUtility::trimExplode()

Dieter Porth 07/15/19, 09:53 updated 07/22/19, 15:52

Description

Optimize Coding of GeneralUtility:trimExplode. The Foreach-loop and the slice-Operation seems not good in the current method.

I guess, the following-code is faster.

public static function trimExplode($delim, $string, $removeEmptyValues = false, $limit = 0) {
    if ($limit>0)  {
        $result = array_map('trim',
            explode($delim, $string,$limit));
    } else  {
        $result = array_map('trim',
            explode($delim, $string));
    }  
    if ($removeEmptyValues === true) {
        $result = array_filter($result, function($k){
             return  $k !== ''
        });
    }
    return $result;
 }

The code-example and the performance is not tested yet.

Perhaps: If the $removeEmptyValues ist related to the php-Function empty(), then the filter-function is obsolete.
@ $result = array_filter($result) @

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.