upgrade to laravel 8.x

This commit is contained in:
2021-05-30 08:20:41 +00:00
parent 41b78a0599
commit 3ad6ed8bfa
2333 changed files with 113904 additions and 59058 deletions
+61 -64
View File
@@ -7,21 +7,42 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\Diff;
use const PHP_INT_SIZE;
use const PREG_SPLIT_DELIM_CAPTURE;
use const PREG_SPLIT_NO_EMPTY;
use function array_shift;
use function array_unshift;
use function array_values;
use function count;
use function current;
use function end;
use function get_class;
use function gettype;
use function is_array;
use function is_object;
use function is_string;
use function key;
use function min;
use function preg_split;
use function prev;
use function reset;
use function sprintf;
use function substr;
use SebastianBergmann\Diff\Output\DiffOutputBuilderInterface;
use SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder;
/**
* Diff implementation.
*/
final class Differ
{
public const OLD = 0;
public const ADDED = 1;
public const REMOVED = 2;
public const DIFF_LINE_END_WARNING = 3;
public const NO_LINE_END_EOF_WARNING = 4;
/**
@@ -40,16 +61,16 @@ final class Differ
$this->outputBuilder = $outputBuilder;
} elseif (null === $outputBuilder) {
$this->outputBuilder = new UnifiedDiffOutputBuilder;
} elseif (\is_string($outputBuilder)) {
} elseif (is_string($outputBuilder)) {
// PHPUnit 6.1.4, 6.2.0, 6.2.1, 6.2.2, and 6.2.3 support
// @see https://github.com/sebastianbergmann/phpunit/issues/2734#issuecomment-314514056
// @deprecated
$this->outputBuilder = new UnifiedDiffOutputBuilder($outputBuilder);
} else {
throw new InvalidArgumentException(
\sprintf(
sprintf(
'Expected builder to be an instance of DiffOutputBuilderInterface, <null> or a string, got %s.',
\is_object($outputBuilder) ? 'instance of "' . \get_class($outputBuilder) . '"' : \gettype($outputBuilder) . ' "' . $outputBuilder . '"'
is_object($outputBuilder) ? 'instance of "' . get_class($outputBuilder) . '"' : gettype($outputBuilder) . ' "' . $outputBuilder . '"'
)
);
}
@@ -58,11 +79,8 @@ final class Differ
/**
* Returns the diff between two arrays or strings as string.
*
* @param array|string $from
* @param array|string $to
* @param null|LongestCommonSubsequenceCalculator $lcs
*
* @return string
* @param array|string $from
* @param array|string $to
*/
public function diff($from, $to, LongestCommonSubsequenceCalculator $lcs = null): string
{
@@ -89,20 +107,18 @@ final class Differ
* @param array|string $from
* @param array|string $to
* @param LongestCommonSubsequenceCalculator $lcs
*
* @return array
*/
public function diffToArray($from, $to, LongestCommonSubsequenceCalculator $lcs = null): array
{
if (\is_string($from)) {
if (is_string($from)) {
$from = $this->splitStringByLines($from);
} elseif (!\is_array($from)) {
} elseif (!is_array($from)) {
throw new InvalidArgumentException('"from" must be an array or string.');
}
if (\is_string($to)) {
if (is_string($to)) {
$to = $this->splitStringByLines($to);
} elseif (!\is_array($to)) {
} elseif (!is_array($to)) {
throw new InvalidArgumentException('"to" must be an array or string.');
}
@@ -112,36 +128,36 @@ final class Differ
$lcs = $this->selectLcsImplementation($from, $to);
}
$common = $lcs->calculate(\array_values($from), \array_values($to));
$common = $lcs->calculate(array_values($from), array_values($to));
$diff = [];
foreach ($start as $token) {
$diff[] = [$token, self::OLD];
}
\reset($from);
\reset($to);
reset($from);
reset($to);
foreach ($common as $token) {
while (($fromToken = \reset($from)) !== $token) {
$diff[] = [\array_shift($from), self::REMOVED];
while (($fromToken = reset($from)) !== $token) {
$diff[] = [array_shift($from), self::REMOVED];
}
while (($toToken = \reset($to)) !== $token) {
$diff[] = [\array_shift($to), self::ADDED];
while (($toToken = reset($to)) !== $token) {
$diff[] = [array_shift($to), self::ADDED];
}
$diff[] = [$token, self::OLD];
\array_shift($from);
\array_shift($to);
array_shift($from);
array_shift($to);
}
while (($token = \array_shift($from)) !== null) {
while (($token = array_shift($from)) !== null) {
$diff[] = [$token, self::REMOVED];
}
while (($token = \array_shift($to)) !== null) {
while (($token = array_shift($to)) !== null) {
$diff[] = [$token, self::ADDED];
}
@@ -150,7 +166,7 @@ final class Differ
}
if ($this->detectUnmatchedLineEndings($diff)) {
\array_unshift($diff, ["#Warning: Strings contain different line endings!\n", self::DIFF_LINE_END_WARNING]);
array_unshift($diff, ["#Warning: Strings contain different line endings!\n", self::DIFF_LINE_END_WARNING]);
}
return $diff;
@@ -159,13 +175,11 @@ final class Differ
/**
* Casts variable to string if it is not a string or array.
*
* @param mixed $input
*
* @return array|string
*/
private function normalizeDiffInput($input)
{
if (!\is_array($input) && !\is_string($input)) {
if (!is_array($input) && !is_string($input)) {
return (string) $input;
}
@@ -174,22 +188,12 @@ final class Differ
/**
* Checks if input is string, if so it will split it line-by-line.
*
* @param string $input
*
* @return array
*/
private function splitStringByLines(string $input): array
{
return \preg_split('/(.*\R)/', $input, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
return preg_split('/(.*\R)/', $input, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
}
/**
* @param array $from
* @param array $to
*
* @return LongestCommonSubsequenceCalculator
*/
private function selectLcsImplementation(array $from, array $to): LongestCommonSubsequenceCalculator
{
// We do not want to use the time-efficient implementation if its memory
@@ -208,24 +212,17 @@ final class Differ
/**
* Calculates the estimated memory footprint for the DP-based method.
*
* @param array $from
* @param array $to
*
* @return float|int
*/
private function calculateEstimatedFootprint(array $from, array $to)
{
$itemSize = PHP_INT_SIZE === 4 ? 76 : 144;
return $itemSize * \min(\count($from), \count($to)) ** 2;
return $itemSize * min(count($from), count($to)) ** 2;
}
/**
* Returns true if line ends don't match in a diff.
*
* @param array $diff
*
* @return bool
*/
private function detectUnmatchedLineEndings(array $diff): bool
{
@@ -267,11 +264,11 @@ final class Differ
private function getLinebreak($line): string
{
if (!\is_string($line)) {
if (!is_string($line)) {
return '';
}
$lc = \substr($line, -1);
$lc = substr($line, -1);
if ("\r" === $lc) {
return "\r";
@@ -281,7 +278,7 @@ final class Differ
return '';
}
if ("\r\n" === \substr($line, -2)) {
if ("\r\n" === substr($line, -2)) {
return "\r\n";
}
@@ -293,10 +290,10 @@ final class Differ
$start = [];
$end = [];
\reset($to);
reset($to);
foreach ($from as $k => $v) {
$toK = \key($to);
$toK = key($to);
if ($toK === $k && $v === $to[$k]) {
$start[$k] = $v;
@@ -307,19 +304,19 @@ final class Differ
}
}
\end($from);
\end($to);
end($from);
end($to);
do {
$fromK = \key($from);
$toK = \key($to);
$fromK = key($from);
$toK = key($to);
if (null === $fromK || null === $toK || \current($from) !== \current($to)) {
if (null === $fromK || null === $toK || current($from) !== current($to)) {
break;
}
\prev($from);
\prev($to);
prev($from);
prev($to);
$end = [$fromK => $from[$fromK]] + $end;
unset($from[$fromK], $to[$toK]);