Adjust the array of lines if necessary

@param array $lines
@param string $direction

@return array
434490
protected function adjustLines(array $lines, $direction)
    {
        $adjust_method = 'adjust' . ucwords(strtolower($direction))  . 'Lines';

        if (method_exists($this, $adjust_method)) {
            return $this->$adjust_method($lines);
        }

        return $lines;
    }
1094085
public static function fromHeaderLines(array $lines)
    {
        $bag = new static;

        foreach ($lines as $line)
        {
            preg_match('/^([^:]++)(?|(?:[:][ ]?+)(.*+)|())/', $line, $matches);
            array_shift($matches);

            list($name, $value) = $matches;

            $bag->add($name, $value);
        }

        return $bag;
    }
281998
public function getSortableDirection($direction = null)
    {
        if ( ! is_null($direction))
        {
            return $this->validateSortableDirection($direction);
        }

        return $this->getDefaultSortableDirection();
    }
428270
def clear_lines(n, direction = :up)
      n.times.reduce([]) do |acc, i|
        dir = direction == :up ? up : down
        acc << clear_line + ((i == n - 1) ? '' : dir)
      end.join
    end
1171992
public function sort($field, $direction = self::SORT_DESC) {
		if(empty($this->data['sorts'])) {
			$this->data['sorts'] = array();
		}
		$this->data['sorts'][] = array(
			'field' => $field,
			'direction' => $direction
		);
		return $this;
	}
159659
protected static function fixLastLine(array $lines, array $all): array
    {
        $last = end($all);
        $lastLine = end($lines);
        if ($lastLine !== false && $last !== $lastLine && rtrim($lastLine) === $last) {
            $lines[key($lines)] = $last;
        }
        return $lines;
    }
111503
public function OrderBy($Fields, $Direction = 'asc') {
      if (!$Fields)
         return $this;
         
      if ($Direction && $Direction != 'asc')
         $Direction = 'desc';
      else
         $Direction = 'asc';

      $this->_OrderBys[] = $this->EscapeIdentifier($Fields, TRUE).' '.$Direction;
      return $this;
   }
74648
public function withDirection(Direction $direction)
    {
        return new static($direction, $this->forced, $this->dryRun, $this->exceptionOnSkip, $this->custom);
    }
634872
public function lines(array $lines): Writer
    {
        foreach ($lines as $line) {
            $this->line($line);
        }

        return $this;
    }
170163
public function line(Array $settings = []) : GD
    {
        $x1   = $settings['x1']    ?? $this->x1    ?? 0;
        $y1   = $settings['y1']    ?? $this->y1    ?? 0;
        $x2   = $settings['x2']    ?? $this->x2    ?? 0;
        $y2   = $settings['y2']    ?? $this->y2    ?? 0;
        $rgb  = $settings['color'] ?? $this->color ?? '0|0|0';
        $type = $settings['type']  ?? $this->type  ?? 'solid';
        
        if( $type === 'solid' )
        {
            imageline($this->canvas, $x1, $y1, $x2, $y2, $this->allocate($rgb));
        }
        elseif( $type === 'dashed' )
        {
            imagedashedline($this->canvas, $x1, $y1, $x2, $y2, $this->allocate($rgb));
        }

        $this->defaultRevolvingVariables();

        return $this;
    }
452245
public function adjacentSibling($path, $direction = 1)
    {
        $values = array_keys($this->items);
        $keys = array_flip($values);

        if (array_key_exists($path, $keys)) {
            $index = $keys[$path] - $direction;

            return isset($values[$index]) ? $this->offsetGet($values[$index]) : $this;
        }

        return $this;

    }
1100146
public static function trimEmptyLines(array $lines) : array
    {
        for ($last = count($lines) - 1; $last > -1; $last--) {
            if (!empty($lines[$last])) {
                return $lines;
            }
            unset($lines[$last]);
        }
        return $lines;
    }
456469
public function orderBy($fields, string $direction = 'ASC'): IQueryBuilderHandler
    {
        if (\is_array($fields) === false) {
            $fields = [$fields];
        }

        foreach ((array)$fields as $key => $value) {
            $field = $key;
            $type = $value;

            if (\is_int($key) === true) {
                $field = $value;
                $type = $direction;
            }

            if (($field instanceof Raw) === false) {
                $field = $this->addTablePrefix($field);
            }

            $this->statements['orderBys'][] = compact('field', 'type');
        }

        return $this;
    }
672751
public function orderBy($fields, $direction = false)
    {
        $this->orderBy->addFields($fields, $direction);

        return $this;
    }
1017147
public static function sortKeys(array $array, string $direction = 'ASC')
    {
        $direction = (strtolower($direction) === 'desc') ? SORT_DESC : SORT_ASC;
        if ($direction === SORT_ASC) {
            ksort($array);
        } else {
            krsort($array);
        }

        return $array;
    }
1108976
public function changeOrdering($direction)
    {
        $allowedDirections = array('asc', 'desc');
        $direction = strtolower($direction);
        $isInArray = in_array($direction, $allowedDirections, true);
        if (!empty($direction) && $isInArray) {
            if ($direction == 'asc') {
                $direction = 'desc';
            } else {
                $direction = 'asc';
            }
        }
        return $direction;
    }
1011378
protected function exitHorizontalFrames(array $lines, $line_method)
    {
        $keyframes = [];
        $length    = mb_strlen($lines[0]);

        for ($i = $length; $i > 0; $i--) {
            $keyframes[] = $this->getHorizontalKeyframe($lines, $i, $line_method, $length);
        }

        return $keyframes;
    }