Laravel version update
Laravel version update
This commit is contained in:
56
vendor/sebastian/diff/src/Output/AbstractChunkOutputBuilder.php
vendored
Normal file
56
vendor/sebastian/diff/src/Output/AbstractChunkOutputBuilder.php
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/diff.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\Diff\Output;
|
||||
|
||||
abstract class AbstractChunkOutputBuilder implements DiffOutputBuilderInterface
|
||||
{
|
||||
/**
|
||||
* Takes input of the diff array and returns the common parts.
|
||||
* Iterates through diff line by line.
|
||||
*
|
||||
* @param array $diff
|
||||
* @param int $lineThreshold
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getCommonChunks(array $diff, int $lineThreshold = 5): array
|
||||
{
|
||||
$diffSize = \count($diff);
|
||||
$capturing = false;
|
||||
$chunkStart = 0;
|
||||
$chunkSize = 0;
|
||||
$commonChunks = [];
|
||||
|
||||
for ($i = 0; $i < $diffSize; ++$i) {
|
||||
if ($diff[$i][1] === 0 /* OLD */) {
|
||||
if ($capturing === false) {
|
||||
$capturing = true;
|
||||
$chunkStart = $i;
|
||||
$chunkSize = 0;
|
||||
} else {
|
||||
++$chunkSize;
|
||||
}
|
||||
} elseif ($capturing !== false) {
|
||||
if ($chunkSize >= $lineThreshold) {
|
||||
$commonChunks[$chunkStart] = $chunkStart + $chunkSize;
|
||||
}
|
||||
|
||||
$capturing = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($capturing !== false && $chunkSize >= $lineThreshold) {
|
||||
$commonChunks[$chunkStart] = $chunkStart + $chunkSize;
|
||||
}
|
||||
|
||||
return $commonChunks;
|
||||
}
|
||||
}
|
63
vendor/sebastian/diff/src/Output/DiffOnlyOutputBuilder.php
vendored
Normal file
63
vendor/sebastian/diff/src/Output/DiffOnlyOutputBuilder.php
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/diff.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\Diff\Output;
|
||||
|
||||
/**
|
||||
* Builds a diff string representation in a loose unified diff format
|
||||
* listing only changes lines. Does not include line numbers.
|
||||
*/
|
||||
final class DiffOnlyOutputBuilder implements DiffOutputBuilderInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $header;
|
||||
|
||||
public function __construct(string $header = "--- Original\n+++ New\n")
|
||||
{
|
||||
$this->header = $header;
|
||||
}
|
||||
|
||||
public function getDiff(array $diff): string
|
||||
{
|
||||
$buffer = \fopen('php://memory', 'r+b');
|
||||
|
||||
if ('' !== $this->header) {
|
||||
\fwrite($buffer, $this->header);
|
||||
if ("\n" !== \substr($this->header, -1, 1)) {
|
||||
\fwrite($buffer, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($diff as $diffEntry) {
|
||||
if ($diffEntry[1] === 1 /* ADDED */) {
|
||||
\fwrite($buffer, '+' . $diffEntry[0]);
|
||||
} elseif ($diffEntry[1] === 2 /* REMOVED */) {
|
||||
\fwrite($buffer, '-' . $diffEntry[0]);
|
||||
} elseif ($diffEntry[1] === 3 /* WARNING */) {
|
||||
\fwrite($buffer, ' ' . $diffEntry[0]);
|
||||
|
||||
continue; // Warnings should not be tested for line break, it will always be there
|
||||
} else { /* Not changed (old) 0 */
|
||||
continue; // we didn't write the non changs line, so do not add a line break either
|
||||
}
|
||||
|
||||
$lc = \substr($diffEntry[0], -1);
|
||||
if ($lc !== "\n" && $lc !== "\r") {
|
||||
\fwrite($buffer, "\n"); // \No newline at end of file
|
||||
}
|
||||
}
|
||||
|
||||
$diff = \stream_get_contents($buffer, -1, 0);
|
||||
\fclose($buffer);
|
||||
|
||||
return $diff;
|
||||
}
|
||||
}
|
19
vendor/sebastian/diff/src/Output/DiffOutputBuilderInterface.php
vendored
Normal file
19
vendor/sebastian/diff/src/Output/DiffOutputBuilderInterface.php
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/diff.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\Diff\Output;
|
||||
|
||||
/**
|
||||
* Defines how an output builder should take a generated
|
||||
* diff array and return a string representation of that diff.
|
||||
*/
|
||||
interface DiffOutputBuilderInterface
|
||||
{
|
||||
public function getDiff(array $diff): string;
|
||||
}
|
165
vendor/sebastian/diff/src/Output/UnifiedDiffOutputBuilder.php
vendored
Normal file
165
vendor/sebastian/diff/src/Output/UnifiedDiffOutputBuilder.php
vendored
Normal file
@@ -0,0 +1,165 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of sebastian/diff.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\Diff\Output;
|
||||
|
||||
/**
|
||||
* Builds a diff string representation in unified diff format in chunks.
|
||||
*/
|
||||
final class UnifiedDiffOutputBuilder extends AbstractChunkOutputBuilder
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $header;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $addLineNumbers;
|
||||
|
||||
public function __construct(string $header = "--- Original\n+++ New\n", bool $addLineNumbers = false)
|
||||
{
|
||||
$this->header = $header;
|
||||
$this->addLineNumbers = $addLineNumbers;
|
||||
}
|
||||
|
||||
public function getDiff(array $diff): string
|
||||
{
|
||||
$buffer = \fopen('php://memory', 'r+b');
|
||||
|
||||
if ('' !== $this->header) {
|
||||
\fwrite($buffer, $this->header);
|
||||
if ("\n" !== \substr($this->header, -1, 1)) {
|
||||
\fwrite($buffer, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
$this->writeDiffChunked($buffer, $diff, $this->getCommonChunks($diff));
|
||||
|
||||
$diff = \stream_get_contents($buffer, -1, 0);
|
||||
|
||||
\fclose($buffer);
|
||||
|
||||
return $diff;
|
||||
}
|
||||
|
||||
// `old` is an array with key => value pairs . Each pair represents a start and end index of `diff`
|
||||
// of a list of elements all containing `same` (0) entries.
|
||||
private function writeDiffChunked($output, array $diff, array $old)
|
||||
{
|
||||
$upperLimit = \count($diff);
|
||||
$start = 0;
|
||||
$fromStart = 0;
|
||||
$toStart = 0;
|
||||
|
||||
if (\count($old)) { // no common parts, list all diff entries
|
||||
\reset($old);
|
||||
|
||||
// iterate the diff, go from chunk to chunk skipping common chunk of lines between those
|
||||
do {
|
||||
$commonStart = \key($old);
|
||||
$commonEnd = \current($old);
|
||||
|
||||
if ($commonStart !== $start) {
|
||||
list($fromRange, $toRange) = $this->getChunkRange($diff, $start, $commonStart);
|
||||
$this->writeChunk($output, $diff, $start, $commonStart, $fromStart, $fromRange, $toStart, $toRange);
|
||||
|
||||
$fromStart += $fromRange;
|
||||
$toStart += $toRange;
|
||||
}
|
||||
|
||||
$start = $commonEnd + 1;
|
||||
$commonLength = $commonEnd - $commonStart + 1; // calculate number of non-change lines in the common part
|
||||
$fromStart += $commonLength;
|
||||
$toStart += $commonLength;
|
||||
} while (false !== \next($old));
|
||||
|
||||
\end($old); // short cut for finding possible last `change entry`
|
||||
$tmp = \key($old);
|
||||
\reset($old);
|
||||
if ($old[$tmp] === $upperLimit - 1) {
|
||||
$upperLimit = $tmp;
|
||||
}
|
||||
}
|
||||
|
||||
if ($start < $upperLimit - 1) { // check for trailing (non) diff entries
|
||||
do {
|
||||
--$upperLimit;
|
||||
} while (isset($diff[$upperLimit][1]) && $diff[$upperLimit][1] === 0);
|
||||
++$upperLimit;
|
||||
|
||||
list($fromRange, $toRange) = $this->getChunkRange($diff, $start, $upperLimit);
|
||||
$this->writeChunk($output, $diff, $start, $upperLimit, $fromStart, $fromRange, $toStart, $toRange);
|
||||
}
|
||||
}
|
||||
|
||||
private function writeChunk(
|
||||
$output,
|
||||
array $diff,
|
||||
int $diffStartIndex,
|
||||
int $diffEndIndex,
|
||||
int $fromStart,
|
||||
int $fromRange,
|
||||
int $toStart,
|
||||
int $toRange
|
||||
) {
|
||||
if ($this->addLineNumbers) {
|
||||
\fwrite($output, '@@ -' . (1 + $fromStart));
|
||||
|
||||
if ($fromRange > 1) {
|
||||
\fwrite($output, ',' . $fromRange);
|
||||
}
|
||||
|
||||
\fwrite($output, ' +' . (1 + $toStart));
|
||||
if ($toRange > 1) {
|
||||
\fwrite($output, ',' . $toRange);
|
||||
}
|
||||
|
||||
\fwrite($output, " @@\n");
|
||||
} else {
|
||||
\fwrite($output, "@@ @@\n");
|
||||
}
|
||||
|
||||
for ($i = $diffStartIndex; $i < $diffEndIndex; ++$i) {
|
||||
if ($diff[$i][1] === 1 /* ADDED */) {
|
||||
\fwrite($output, '+' . $diff[$i][0]);
|
||||
} elseif ($diff[$i][1] === 2 /* REMOVED */) {
|
||||
\fwrite($output, '-' . $diff[$i][0]);
|
||||
} else { /* Not changed (old) 0 or Warning 3 */
|
||||
\fwrite($output, ' ' . $diff[$i][0]);
|
||||
}
|
||||
|
||||
$lc = \substr($diff[$i][0], -1);
|
||||
if ($lc !== "\n" && $lc !== "\r") {
|
||||
\fwrite($output, "\n"); // \No newline at end of file
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getChunkRange(array $diff, int $diffStartIndex, int $diffEndIndex): array
|
||||
{
|
||||
$toRange = 0;
|
||||
$fromRange = 0;
|
||||
|
||||
for ($i = $diffStartIndex; $i < $diffEndIndex; ++$i) {
|
||||
if ($diff[$i][1] === 1) { // added
|
||||
++$toRange;
|
||||
} elseif ($diff[$i][1] === 2) { // removed
|
||||
++$fromRange;
|
||||
} elseif ($diff[$i][1] === 0) { // same
|
||||
++$fromRange;
|
||||
++$toRange;
|
||||
}
|
||||
}
|
||||
|
||||
return [$fromRange, $toRange];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user