This searches the file we pass through for both the count of the lines in the file, and the lines of code surrounding that which broke.
@param $file
@param $lineNumber
@param int $currentLine
@return array
349744
protected function getTheCodeFromTheFile(string $file, int $lineNumber, int $currentLine = 0): array
    {
        $handle = fopen($file, "r");

        $linesOfCode = [];

        while (!feof($handle)) {
            $currentLine++;

            $line = fgets($handle);

            if ($line === false) {
                break;
            }

            if (($currentLine - $lineNumber) > -static::NUMBER_OF_LINES_TO_DISPLAY && ($currentLine - $lineNumber) < static::NUMBER_OF_LINES_TO_DISPLAY) {
                $linesOfCode[$currentLine] = $line;
            }
        }

        fclose($handle);

        return $linesOfCode;
    }
630033
protected function checkIfLineNumberIsValid($lineNumber, $throw = true)
    {
        if (!is_int($lineNumber)) {
            $e = new InvalidLineNumberException($lineNumber, $this, 'The line number should be an integer');
        } elseif ($lineNumber < 0) {
            $e = new InvalidLineNumberException($lineNumber, $this, 'The line number should be positive');
        } elseif ($lineNumber >= $this->length) {
            $e = new InvalidLineNumberException($lineNumber, $this, 'The line number should be strictly lower than the number of lines');
        }

        if (isset($e)) {
            if ($throw) {
                throw $e;
            }

            return false;
        }

        return true;
    }
862811
public function headersSent(&$file, &$line)
    {
        $file = $this->headers_sent_file;
        $line = $this->headers_sent_line;
        return $this->headers_sent;
    }
181291
public function getFileCode($file, $line, $range = 20)
    {
        $code = file($file);
        $half = (int)($range / 2);

        $start = $line - $half;
        0 > $start && $start = 0;

        $total = count($code);
        $end = $line + $half;
        $total < $end && $end = $total;

        $len = strlen($end);

        array_unshift($code, null);
        $content = '';
        for ($i = $start; $i < $end; $i++) {
            $temp = str_pad($i, $len, 0, STR_PAD_LEFT) . ':  ' . $code[$i];
            if ($line != $i) {
                $content .= htmlspecialchars($temp, ENT_QUOTES);
            } else {
                $content .= '<strong class="text-danger">' . htmlspecialchars($temp, ENT_QUOTES) . '</strong>';
            }
        }

        return $content;
    }
730124
protected function getFileContents($file, $markLine = null)
    {
        if (is_readable($file) === false) {
            return "Unable to read “{$file}”.";
        }

        $raw = file($file, FILE_IGNORE_NEW_LINES);

        foreach ($raw as $index => &$line) {
            $line = htmlspecialchars($line);

            if ($index + 1 === $markLine) {
                $line = sprintf('<mark class="highlight-line">%s</mark>', $line);
            }

            $line .= "\n";
        }

        if ($this->isExcerptOnly() === true) {
            $raw = array_slice(
                $raw,
                $this->getExcerptStart($markLine) - 1,
                $this->getExcerptSize(),
                true
            );
        }

        return join('', $raw);
    }
1026276
def get_lines_from_file(filename, lineno, context_lines):
    

    def get_lines(start, end):
        return [linecache.getline(filename, l).rstrip() for l in range(start, end)]

    lower_bound = max(1, lineno - context_lines)
    upper_bound = lineno + context_lines
    linecache.checkcache(filename)
    pre_context = get_lines(lower_bound, lineno)
    context_line = linecache.getline(filename, lineno).rstrip()
    post_context = get_lines(lineno + 1, upper_bound)
    return lower_bound, pre_context, context_line, post_context
4238
public function scan (FileContext $file) 
	{
		$filename = $file->getName();

		$code = file_get_contents ($filename);

		try 
		{
		    $stmts = $this->parser->parse ($code);
			$traverser = $this->factory->createTraverser ($file);
		    $traverser->traverse ($stmts);
		} 
		catch (PhpParser\Error $e)
		{
		    echo "\n\nParse Error: " . $e->getMessage() . " ({$filename})\n";
		}
		catch (\Exception $e)
		{
		    echo "\n\n" . $e->getMessage() . " (in {$filename})\n";
		}
		catch (\Throwable $e)
		{
		    echo "\n\n" . $e->getMessage() . " (while analysing {$filename})\n";
		}
	}
192531
protected function consumeCode($lines, $current)
	{
		// consume until }}}
		$content = [];
		for ($i = $current + 1, $count = count($lines); $i < $count; $i++) {
			$line = rtrim($lines[$i]);
			if (strcmp($line, '}}}') !== 0) {
				$content[] = $line;
			} else {
				break;
			}
		}
		$block = [
			'code',
			'content' => implode("\n", $content),
		];
		return [$block, $i];
	}
169677
public static function getLines($file)
    {
        return !is_file($file) || !is_readable($file) || !($lines = @file($file, FILE_SKIP_EMPTY_LINES)) ? [] : $lines;
    }
239565
public static function findCallPos(\Throwable $t, string &$filePath = null, int &$lineNo = null) {
		if (!($t instanceof \TypeError || $t instanceof  WarningError || $t instanceof  RecoverableError)) {
			return;
		}

		$message = $t->getMessage();
		if (false !== strpos($message, '{closure}')) {
			return;
		}
	
		$fmatches = array();
		$lmatches = array();
		if (preg_match('/(?<=called in )[^ \(]+/', $message, $fmatches)
				&& preg_match('/((?<=on line )|(?<=\())[0-9]+/', $message, $lmatches)) {
			$filePath = $fmatches[0];
			$lineNo = $lmatches[0];
		}
		
		$fmatches = array();
		$lmatches = array();
		if (preg_match('/(?<=passed in )[^ \(]+/', $message, $fmatches)
				&& preg_match('/((?<=on line )|(?<=\())[0-9]+/', $message, $lmatches)) {
			$filePath = $fmatches[0];
			$lineNo = $lmatches[0];
		}
	}
30781
protected function lint($file)
    {
        $command = $this->interpreter == ''
            ? 'php'
            : $this->interpreter;

        if (strpos($command, 'hhvm') !== false) {
            $command .= ' --no-config -l';
        } else {
            if ($this->deprecatedAsError) {
                $command .= ' -d error_reporting=32767 ';
            }

            $command .= ' -n -l ';
        }

        if (!file_exists($file)) {
            throw new BuildException('File not found: ' . $file);
        }

        if (!is_readable($file)) {
            throw new BuildException('Permission denied: ' . $file);
        }

        if ($this->cache) {
            $lastmtime = $this->cache->get($file);

            if ($lastmtime >= filemtime($file)) {
                $this->log("Not linting '" . $file . "' due to cache", Project::MSG_DEBUG);

                return false;
            }
        }

        $messages = [];
        $errorCount = 0;

        exec($command . '"' . $file . '" 2>&1', $messages);

        for ($i = 0, $messagesCount = count($messages); $i < $messagesCount; $i++) {
            $message = $messages[$i];
            if (trim($message) == '') {
                continue;
            }

            if ((!preg_match('/^(.*)Deprecated:/', $message) || $this->deprecatedAsError) && !preg_match(
                '/^No syntax errors detected/',
                $message
            )
            ) {
                $this->log($message, Project::MSG_ERR);

                if (!isset($this->badFiles[$file])) {
                    $this->badFiles[$file] = [];
                }

                $this->badFiles[$file][] = $message;

                $this->hasErrors = true;
                $errorCount++;
            }
        }

        if (!$errorCount) {
            $this->log($file . ': No syntax errors detected', $this->logLevel);

            if ($this->cache) {
                $this->cache->put($file, filemtime($file));
            }
        }
    }
1203397
public function readLine(int $line = 1) : string
    {
        $lines = file($this->_path);

        if($line > count($lines)) {
            throw new LineNumberAboveFileLines($this->_path, $line, count($lines));
        }

        if($line <= 0) {
            $line = 1;
        }

        return $lines[($line - 1)];
    }
1373873
protected function currentTopLine($lines, $total_lines, $current)
    {
        $keyframe = array_slice($lines, -$current, $current);

        return array_merge($keyframe, array_fill(0, $total_lines - $current, ''));
    }
814024
protected function _getMethods(File $file) {
		$methods = [];
		$currentIndex = 0;
		while (true) {
			$methodIndex = $file->findNext(T_FUNCTION, $currentIndex);
			if (!$methodIndex) {
				break;
			}
			$methods[$methodIndex] = $this->_parseMethod($file, $methodIndex);

			$currentIndex = $methodIndex + 1;
		}

		return $methods;
	}
524526
protected function lint($file)
    {
        if (file_exists($file)) {
            if (is_readable($file)) {
                $dom = new DOMDocument();
                if ($dom->load($file) === false) {
                    $error = libxml_get_last_error();
                    $this->logError($file . ' is not well-formed (See messages above)');
                } else {
                    if (isset($this->schema)) {
                        if ($this->useRNG) {
                            if ($dom->relaxNGValidate($this->schema->getPath())) {
                                $this->log($file . ' validated with RNG grammar', Project::MSG_INFO);
                            } else {
                                $this->logError($file . ' fails to validate (See messages above)');
                            }
                        } else {
                            if ($dom->schemaValidate($this->schema->getPath())) {
                                $this->log($file . ' validated with schema', Project::MSG_INFO);
                            } else {
                                $this->logError($file . ' fails to validate (See messages above)');
                            }
                        }
                    } else {
                        $this->log(
                            $file . ' is well-formed (not validated due to missing schema specification)',
                            Project::MSG_INFO
                        );
                    }
                }
            } else {
                $this->logError('Permission denied to read file: ' . $file);
            }
        } else {
            $this->logError('File not found: ' . $file);
        }
    }
1231665
public function checkFile($file)
    {
        $result = $this->execute(new Process([$this->getCli(), '-l', $file]));

        if (0 === $result['code']) {
            return [
                'validity' => true,
                'errors' => null
            ];
        }

        $fullMessage = \preg_replace('/ in (?:.+) on line (?:[0-9]+)$/', '', $result['output']);
        \preg_match('/ on line ([0-9]+)$/', $result['output'], $matchLine);
        $line = isset($matchLine[1]) ? \intval($matchLine[1]) : null;

        list($type, $message) = \explode(': ', $fullMessage);

        return [
            'validity' => false,
            'errors' => [
                [
                    'file' => $file,
                    'code' => $result['code'],
                    'line' => $line,
                    'type' => $type,
                    'message' => $this->convertMessage($message)
                ],
            ],
        ];
    }
464261
protected function parseLine(&$lineNumber, array $linesStr)
    {
        $entry = $this->createM3uEntry();

        for ($l = \count($linesStr); $lineNumber < $l; ++$lineNumber) {
            $nextLineStr = $linesStr[$lineNumber];
            $nextLineStr = \trim($nextLineStr);

            if ('' === $nextLineStr || $this->isComment($nextLineStr) || $this->isExtM3u($nextLineStr)) {
                continue;
            }

            $matched = false;
            foreach ($this->getTags() as $availableTag) {
                if ($availableTag::isMatch($nextLineStr)) {
                    $matched = true;
                    $entry->addExtTag(new $availableTag($nextLineStr));
                    break;
                }
            }

            if (!$matched) {
                $entry->setPath($nextLineStr);
                break;
            }
        }

        return $entry;
    }