original_string: protected function sortItemList(&$itemList, $sortSettings)
      {
          $files = [];
          $folders = [];
  
          // Convert string $sortBy to array
          if (is_string($sortSettings)) {
              $sortSettings = [
                  'by' => $sortSettings,
                  'direction' => self::SORT_DIRECTION_ASC,
              ];
          }
  
          usort($itemList, function ($a, $b) use ($sortSettings) {
              $result = 0;
  
              switch ($sortSettings['by']) {
                  case self::SORT_BY_TITLE:
                      $result = strcasecmp($a->path, $b->path);
                      break;
                  case self::SORT_BY_SIZE:
                      if ($a->size < $b->size) {
                          $result = -1;
                      } else {
                          $result = $a->size > $b->size ? 1 : 0;
                      }
                      break;
                  case self::SORT_BY_MODIFIED:
                      if ($a->lastModified < $b->lastModified) {
                          $result = -1;
                      } else {
                          $result = $a->lastModified > $b->lastModified ? 1 : 0;
                      }
                      break;
              }
  
              // Reverse the polarity of the result to direct sorting in a descending order instead
              if ($sortSettings['direction'] === self::SORT_DIRECTION_DESC) {
                  $result = 0 - $result;
              }
  
              return $result;
          });
      }
code: protected function sortItemList(&$itemList, $sortSettings)
      {
          $files = [];
          $folders = [];
  
          // Convert string $sortBy to array
          if (is_string($sortSettings)) {
              $sortSettings = [
                  'by' => $sortSettings,
                  'direction' => self::SORT_DIRECTION_ASC,
              ];
          }
  
          usort($itemList, function ($a, $b) use ($sortSettings) {
              $result = 0;
  
              switch ($sortSettings['by']) {
                  case self::SORT_BY_TITLE:
                      $result = strcasecmp($a->path, $b->path);
                      break;
                  case self::SORT_BY_SIZE:
                      if ($a->size < $b->size) {
                          $result = -1;
                      } else {
                          $result = $a->size > $b->size ? 1 : 0;
                      }
                      break;
                  case self::SORT_BY_MODIFIED:
                      if ($a->lastModified < $b->lastModified) {
                          $result = -1;
                      } else {
                          $result = $a->lastModified > $b->lastModified ? 1 : 0;
                      }
                      break;
              }
  
              // Reverse the polarity of the result to direct sorting in a descending order instead
              if ($sortSettings['direction'] === self::SORT_DIRECTION_DESC) {
                  $result = 0 - $result;
              }
  
              return $result;
          });
      }
code_tokens: protected function sortItemList ( & $ itemList , $ sortSettings ) { $ files = [ ] ; $ folders = [ ] ; // Convert string $sortBy to array if ( is_string ( $ sortSettings ) ) { $ sortSettings = [ 'by' => $ sortSettings , 'direction' => self :: SORT_DIRECTION_ASC , ] ; } usort ( $ itemList , function ( $ a , $ b ) use ( $ sortSettings ) { $ result = 0 ; switch ( $ sortSettings [ 'by' ] ) { case self :: SORT_BY_TITLE : $ result = strcasecmp ( $ a -> path , $ b -> path ) ; break ; case self :: SORT_BY_SIZE : if ( $ a -> size < $ b -> size ) { $ result = - 1 ; } else { $ result = $ a -> size > $ b -> size ? 1 : 0 ; } break ; case self :: SORT_BY_MODIFIED : if ( $ a -> lastModified < $ b -> lastModified ) { $ result = - 1 ; } else { $ result = $ a -> lastModified > $ b -> lastModified ? 1 : 0 ; } break ; } // Reverse the polarity of the result to direct sorting in a descending order instead if ( $ sortSettings [ 'direction' ] === self :: SORT_DIRECTION_DESC ) { $ result = 0 - $ result ; } return $ result ; } ) ; }
docstring: Sorts the item list by title, size or last modified date.
  @param array $itemList Specifies the item list to sort.
  @param mixed $sortSettings Determines the sorting preference.
  Supported values are 'title', 'size', 'lastModified' (see SORT_BY_XXX class constants) or an associative array with a 'by' key and a 'direction' key: ['by' => SORT_BY_XXX, 'direction' => SORT_DIRECTION_XXX].
docstring_tokens: Sorts the item list by title size or last modified date .