Accepts an array of diff lines & returns a Changeset instance.

@param string[] $lines
@param string $vcsType

@return Changeset
498188
public function parseLines(array $lines, string $vcsType = ''): Changeset
    {
        $parser = $this->getParser($vcsType);

        return $parser->parse($lines);
    }
515178
public function delete($line, $lines)
    {
        foreach (range(0, $lines-1) as $offset) {
            $this->lines[$line+$offset-1] = null;
        }
        return $this;
    }
436668
function docBlock($lines) {
    if (!is_array($lines)) {
      $lines = array($lines);
    }

    $lines = array_merge(
      array("/**"),
      array_map(function ($line) {
        if (empty($line)) {
          return ' *';
        }
        return " * $line";
      }, $lines),
      array(" */")
    );

    return $lines;
  }
1334333
function applyStyle($text, $styles = [])
    {
        if (!self::$supported)
            return $text;

        if (is_string($styles))
        {
            $styles = [$styles];
        }

        $output = $text;
        foreach ($styles as $style) {
            if (isset(self::$theme[$style])) {
                $output = $this->applyStyle($output, self::$theme[$style]);
            } else {
                if (isset(self::$styles[$style])) {
                    $pre  = $this->escSequence(self::$styles[$style]);
                    $post = $this->escSequence(0);
                } else {
                    $pre = $post = '';
                }

                $output = $pre . $output . $post;
            }
        }

        return $output;
    }
681824
protected function makeReplacements($line, array $replace)
    {
        $replace = (new Collection($replace))->sortBy(function ($value, $key) {
            return mb_strlen($key) * -1;
        });

        foreach ($replace as $key => $value) {
            $line = str_replace(':'.$key, $value, $line);
        }

        return $line;
    }
123043
public function changeAction(ChangeCollection $changes)
    {
        try {
            $count = $changes->count();
            $changes->apply();

            $success = new Info();
            $success->setMessage(sprintf('%d change(s) successfully applied.', $count));

            $this->feedbackCollection->add($success);
            $this->persistenceManager->persistAll();
        } catch (\Exception $e) {
            $error = new Error();
            $error->setMessage($e->getMessage());

            $this->feedbackCollection->add($error);
        }

        $this->view->assign('value', $this->feedbackCollection);
    }
1085195
public function tokenize(array $diffLineList)
    {
        $tokenList = [];
        $hasStarted = false;

        $lineCount = count($diffLineList);
        for ($i = 0; $i < $lineCount; $i++) {
            // First line of a file
            if ($this->isFileStart($diffLineList, $i)) {
                $hasStarted = true;

                $tokenList = array_merge(
                    $tokenList,
                    $this->getFilenameTokens($diffLineList, $i)
                );

                $i++;   // Skip next line - we know this is safe due to check for is file start

            // Only proceed once a file beginning has been found
            } elseif ($hasStarted) {
                $tokenList = array_merge(
                    $tokenList,
                    $this->getHunkTokens($diffLineList, $i)
                );
            }
        }

        return $tokenList;
    }
115545
protected function proceedSubmitRecords(array $changeSet)
    {
        if (is_array($changeSet['submitRecords'] === false)) {
            return;
        }

        foreach ($changeSet['submitRecords'] as $submitRecord) {
            $submitRecordData = array(
                'changeset' => $changeSet['id'],
                'status' => $submitRecord['status'],
            );

            $wherePart = array('changeset' => $changeSet['id']);
            $submitRecordRow = $this->getLookupTableValues(Database::TABLE_SUBMIT_RECORDS, array('id'), $wherePart);
            if ($submitRecordRow === false) {
                $id = $this->getDatabase()->insertRecord(Database::TABLE_SUBMIT_RECORDS, $submitRecordData);

            } else {
                $id = $submitRecordRow['id'];
                $this->getDatabase()->updateRecord(Database::TABLE_SUBMIT_RECORDS, $submitRecordData, $submitRecordRow['id']);
            }

            $submitRecord = $this->unsetKeys($submitRecord, array('status'));

            if (is_array($submitRecord['labels']) === true) {
                $this->proceedSubmitRecordLabels($id, $submitRecord['labels']);
                $submitRecord = $this->unsetKeys($submitRecord, array('labels'));
            }

            $this->checkIfAllValuesWereProceeded($submitRecord, 'Submit record');
        }
    }
1150857
private function parseOutputLines(array $lines)
    {
        foreach ($lines as $line) {
            preg_match('/([MADRCU\? ])?([MADRCU\? ])?\ "?(\S+)"? ?( -> )?(\S+)?/', $line, $matches);
            $x = isset($matches[1]) ? $matches[1] : null;
            $y = isset($matches[2]) ? $matches[2] : null;
            $file = isset($matches[3]) ? $matches[3] : null;
            $renamedFile = isset($matches[4]) ? $matches[4] : null;
            $this->files[] = StatusFile::create($x, $y, $file, $renamedFile);
        }
    }
1058877
public function diff( \PhpSets\Set $set ) {
        $entries = $this->entries();
        $iterator = $set->entries();
        $intersect = new \PhpSets\Set;

        // check $set values
        while ( $entries->valid() ) {
            if ( ! $set->has( $entries->current() ) ) {
                $intersect->add( $entries->current() );
            }

            $entries->next();
        }

        // check $additionalSet values
        while ( $iterator->valid() ) {
            if ( ! $this->has( $iterator->current() ) ) {
                $intersect->add( $iterator->current() );
            }

            $iterator->next();
        }

        return $intersect;
    }
561227
protected function loadNamespaceOverrides(array $lines, $locale, $group, $namespace)
	{
		$file = "{$this->path}/packages/{$locale}/{$namespace}/{$group}.php";

		if ($this->files->exists($file))
		{
			return array_replace_recursive($lines, $this->files->getRequire($file));
		}

		return $lines;
	}
936597
protected function parseDocBlock( $lines )
	{
		$data		= array();
		$descLines	= array();
		foreach( $lines as $line )
		{
			if( preg_match( $this->regexDocParam, $line, $matches ) )
			{
				$data['param'][$matches[4]]	= $this->parseDocParameter( $matches );
			}
			else if( preg_match( "@\*\s+\@return\s+(\w+)\s*(.+)?$@i", $line, $matches ) )
			{
				$data['return']	= $this->parseDocReturn( $matches );
			}
			else if( preg_match( "@\*\s+\@throws\s+(\w+)\s*(.+)?$@i", $line, $matches ) )
			{
				$data['throws'][]	= $this->parseDocThrows( $matches );
			}
			else if( preg_match( "@\*\s+\@trigger\s+(\w+)\s*(.+)?$@i", $line, $matches ) )
			{
				$data['trigger'][]	= $this->parseDocTrigger( $matches );
			}
			else if( preg_match( "@\*\s+\@author\s+(.+)\s*(<(.+)>)?$@iU", $line, $matches ) )
			{
				$author	= new ADT_PHP_Author( trim( $matches[1] ) );
				if( isset( $matches[3] ) )
					$author->setEmail( trim( $matches[3] ) );
				$data['author'][]	= $author;
			}
			else if( preg_match( "@\*\s+\@license\s+(\S+)( .+)?$@i", $line, $matches ) )
			{
				$data['license'][]	= $this->parseDocLicense( $matches );
			}
			else if( preg_match( "/^\*\s+@(\w+)\s*(.*)$/", $line, $matches ) )
			{
				switch( $matches[1] )
				{
					case 'implements':
					case 'deprecated':
					case 'todo':
					case 'copyright':
					case 'see':
					case 'uses':
					case 'link':
						$data[$matches[1]][]	= $matches[2];			
						break;
					case 'since':
					case 'version':
					case 'access':
					case 'category':
					case 'package':
					case 'subpackage':
						$data[$matches[1]]	= $matches[2];			
						break;
					default:
						break;
				}
			}
			else if( !$data && preg_match( "/^\*\s*([^@].+)?$/", $line, $matches ) )
				$descLines[]	= isset( $matches[1] ) ? trim( $matches[1] ) : "";
		}
		$data['description']	= trim( implode( "\n", $descLines ) );

		if( !isset( $data['throws'] ) )
			$data['throws']	= array();
		return $data;
	}
857186
public function lines(array $old, array $new)
    {
        $diff = parent::lines($old, $new);

        $len = count($new);
        for ($i = 0; $i < $len; $i++) {
            if (isset($diff[$i]) && !is_null($new[$i]) && $diff[$i]['col'] > 0) {
                $styling = $this->cursor->getCurrentFormatting(mb_substr($new[$i], 0, $diff[$i]['col']));
                $diff[$i]['col'] = mb_strlen($this->cursor->filter(mb_substr($new[$i], 0, $diff[$i]['col'])));
                if (mb_strlen($styling) > 0) {
                    $diff[$i]['str'] = $styling . $diff[$i]['str'];
                }
            }
        }

        return $diff;
    }
352251
public static function headersFromLines($lines)
    {
        $headers = [];

        foreach ($lines as $line) {
            $parts = explode(':', $line, 2);
            $headers[trim($parts[0])][] = isset($parts[1])
                ? trim($parts[1])
                : null;
        }

        return $headers;
    }
244230
protected function box(array $lines)
    {
        if (count($lines) > 0) {
            $width = strlen($lines[0]);
        } else {
            $width = 0;
        }
        $head = $this->options['boxTopLeftChar']
                . str_pad('', $width, $this->options['boxHorizChar'])
                . $this->options['boxTopRightChar']
                . $this->options['lineEnd'];
        $tail = $this->options['boxBotLeftChar']
                . str_pad('', $width, $this->options['boxHorizChar'])
                . $this->options['boxBotRightChar']
                . $this->options['lineEnd'];
        $output = '';
        foreach ($lines as $line) {
            $output .= $this->options['boxVertChar']
                    . $line
                    . $this->options['boxVertChar']
                    . $this->options['lineEnd'];
        }

        return $head . $output . $tail;
    }
368423
public static function createArray($lines)
    {
        $op = Line::UNCHANGED;
        $hunks = [];
        /** @var Hunk $current */
        $current = null;
        foreach ($lines as $line) {
            switch ($line->getType()) {
                case Line::REMOVED:
                    if ($op != Line::REMOVED) {
                        // The last line was not removed so we start a new hunk.
                        $current = new Hunk($line, Hunk::REMOVED, $line->getIndex());
                    } else {
                        // continue adding the line to the hunk.
                        $current->addLine($line);
                    }
                    break;
                case Line::ADDED:
                    switch ($op) {
                        case Line::REMOVED:
                            // The hunk is a replacement.
                            $current->setType(Hunk::REPLACED);
                            $current->addLine($line);
                            break;
                        case Line::ADDED:
                            $current->addLine($line);
                            break;
                        case Line::UNCHANGED:
                            // Add a new hunk with the added type.
                            $current = new Hunk($line, Hunk::ADDED, $line->getIndex());
                            break;
                    }
                    break;
                case Line::UNCHANGED:
                    if ($current) {
                        // The hunk exists so add it to the array.
                        $hunks[] = $current;
                        $current = null;
                    }
                    break;
            }
            $op = $line->getType();
        }
        if ($current) {
            // The last line was part of a hunk, so add it.
            $hunks[] = $current;
        }

        return $hunks;
    }
1334872
public function getTail($lines = 10){
		$this->blockStart = $this->fileSize;
		$buff1 = Array();
		$lastLines = array();
		
		while($this->blockStart){
			$buff = $this->readChunk();
			if(!$buff)break;
			
			$lines -= substr_count($buff, "\n");
			
			if($lines <= 0)
			{
				$buff1[] = $this->cutHead($buff, "\n", abs($lines)+1);
				break;
			}
			$buff1[] = $buff;
		}
		
		for($i = count($buff1); $i >= 0; $i--){
			$lastLines = array_merge($lastLines, explode("\n", $buff1[$i]));
		}
		
		return $lastLines;
	}