private function findSibling(Collection $elements, SortableInterface $current, $next = false)
    {
        if ($next) {
            $sibling = $elements->filter(function (SortableInterface $s) use ($current) {
                return $s->getPosition() > $current->getPosition();
            })->first();
        } else {
            $sibling = $elements->filter(function (SortableInterface $s) use ($current) {
                return $s->getPosition() < $current->getPosition();
            })->last();
        }

        return $sibling ?: null;
    }
private function findSibling(Collection $elements, SortableInterface $current, $next = false)
    {
        if ($next) {
            $sibling = $elements->filter(function (SortableInterface $s) use ($current) {
                return $s->getPosition() > $current->getPosition();
            })->first();
        } else {
            $sibling = $elements->filter(function (SortableInterface $s) use ($current) {
                return $s->getPosition() < $current->getPosition();
            })->last();
        }

        return $sibling ?: null;
    }
private function findSibling ( Collection $ elements , SortableInterface $ current , $ next = false ) { if ( $ next ) { $ sibling = $ elements -> filter ( function ( SortableInterface $ s ) use ( $ current ) { return $ s -> getPosition ( ) > $ current -> getPosition ( ) ; } ) -> first ( ) ; } else { $ sibling = $ elements -> filter ( function ( SortableInterface $ s ) use ( $ current ) { return $ s -> getPosition ( ) < $ current -> getPosition ( ) ; } ) -> last ( ) ; } return $ sibling ? : null ; }
Finds the previous element based on position.

@param Collection        $elements
@param SortableInterface $current
@param bool              $next Whether to look for the next or the previous

@return mixed
Finds the previous element based on position .