<?php

namespace App\Component\Sorter;

use App\Component\Sorter\FileSortType;

/**
 * Description of FileSorter
 *
 * @author c9mos
 */
class FileSorter {
    static public function sortTypeAsc(array $element1,array $element2): int
    {
        if ($element1['dir'] === $element2['dir']) {
            return strcmp($element1['name'], $element2['name']);
        } elseif ($element1['dir']) {
            return -1;
        }
        return 1;
    }
    
    static public function sortTypeDesc(array $element1,array $element2): int
    {
        if ($element1['dir'] === $element2['dir']) {
            return (strcmp($element2['name'],$element1['name']));
        } elseif ($element1['dir']) {
            return 1;
        }
        return -1;
    }
    
    static public function sortNameAsc($element1,$element2): int
    {
        return strcmp($element1['name'],$element2['name']);
    }
    
    static public function sortNameDesc($element1,$element2): int
    {
        return strcmp($element2['name'],$element1['name']);
    }
    
    static public function sortSizeAsc($element1,$element2): int
    {
        return ($element1['size'] - $element2['size']);
    }
    
    static public function sortSizeDesc($element1,$element2): int
    {
        return ($element2['size'] - $element1['size']);
    }
    
    static public function sortDateAsc($element1,$element2): int
    {
        return ($element1['mtime'] - $element2['mtime']);
    }
    
    static public function sortDateDesc($element1,$element2): int
    {
        return ($element2['mtime'] - $element1['mtime']);
    }
}
