composer update
This commit is contained in:
Vendored
+50
-1
@@ -2,7 +2,51 @@
|
||||
|
||||
All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
|
||||
|
||||
## [5.0.0] - 2022-02-03
|
||||
## [5.1.1] - 2024-03-02
|
||||
|
||||
### Changed
|
||||
|
||||
* Do not use implicitly nullable parameters
|
||||
|
||||
## [5.1.0] - 2023-12-22
|
||||
|
||||
### Added
|
||||
|
||||
* `SebastianBergmann\Diff\Chunk::start()`, `SebastianBergmann\Diff\Chunk::startRange()`, `SebastianBergmann\Diff\Chunk::end()`, `SebastianBergmann\Diff\Chunk::endRange()`, and `SebastianBergmann\Diff\Chunk::lines()`
|
||||
* `SebastianBergmann\Diff\Diff::from()`, `SebastianBergmann\Diff\Diff::to()`, and `SebastianBergmann\Diff\Diff::chunks()`
|
||||
* `SebastianBergmann\Diff\Line::content()` and `SebastianBergmann\Diff\Diff::type()`
|
||||
* `SebastianBergmann\Diff\Line::isAdded()`,`SebastianBergmann\Diff\Line::isRemoved()`, and `SebastianBergmann\Diff\Line::isUnchanged()`
|
||||
|
||||
### Changed
|
||||
|
||||
* `SebastianBergmann\Diff\Diff` now implements `IteratorAggregate`, iterating over it yields the aggregated `SebastianBergmann\Diff\Chunk` objects
|
||||
* `SebastianBergmann\Diff\Chunk` now implements `IteratorAggregate`, iterating over it yields the aggregated `SebastianBergmann\Diff\Line` objects
|
||||
|
||||
### Deprecated
|
||||
|
||||
* `SebastianBergmann\Diff\Chunk::getStart()`, `SebastianBergmann\Diff\Chunk::getStartRange()`, `SebastianBergmann\Diff\Chunk::getEnd()`, `SebastianBergmann\Diff\Chunk::getEndRange()`, and `SebastianBergmann\Diff\Chunk::getLines()`
|
||||
* `SebastianBergmann\Diff\Diff::getFrom()`, `SebastianBergmann\Diff\Diff::getTo()`, and `SebastianBergmann\Diff\Diff::getChunks()`
|
||||
* `SebastianBergmann\Diff\Line::getContent()` and `SebastianBergmann\Diff\Diff::getType()`
|
||||
|
||||
## [5.0.3] - 2023-05-01
|
||||
|
||||
### Changed
|
||||
|
||||
* [#119](https://github.com/sebastianbergmann/diff/pull/119): Improve performance of `TimeEfficientLongestCommonSubsequenceCalculator`
|
||||
|
||||
## [5.0.2] - 2023-05-01
|
||||
|
||||
### Changed
|
||||
|
||||
* [#118](https://github.com/sebastianbergmann/diff/pull/118): Improve performance of `MemoryEfficientLongestCommonSubsequenceCalculator`
|
||||
|
||||
## [5.0.1] - 2023-03-23
|
||||
|
||||
### Fixed
|
||||
|
||||
* [#115](https://github.com/sebastianbergmann/diff/pull/115): `Parser::parseFileDiff()` does not handle diffs correctly that only add lines or only remove lines
|
||||
|
||||
## [5.0.0] - 2023-02-03
|
||||
|
||||
### Changed
|
||||
|
||||
@@ -86,6 +130,11 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
|
||||
|
||||
* This component is no longer supported on PHP 5.6
|
||||
|
||||
[5.1.1]: https://github.com/sebastianbergmann/diff/compare/5.1.0...5.1.1
|
||||
[5.1.0]: https://github.com/sebastianbergmann/diff/compare/5.0.3...5.1.0
|
||||
[5.0.3]: https://github.com/sebastianbergmann/diff/compare/5.0.2...5.0.3
|
||||
[5.0.2]: https://github.com/sebastianbergmann/diff/compare/5.0.1...5.0.2
|
||||
[5.0.1]: https://github.com/sebastianbergmann/diff/compare/5.0.0...5.0.1
|
||||
[5.0.0]: https://github.com/sebastianbergmann/diff/compare/4.0.4...5.0.0
|
||||
[4.0.4]: https://github.com/sebastianbergmann/diff/compare/4.0.3...4.0.4
|
||||
[4.0.3]: https://github.com/sebastianbergmann/diff/compare/4.0.2...4.0.3
|
||||
|
||||
Vendored
+1
-1
@@ -1,6 +1,6 @@
|
||||
BSD 3-Clause License
|
||||
|
||||
Copyright (c) 2002-2023, Sebastian Bergmann
|
||||
Copyright (c) 2002-2024, Sebastian Bergmann
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
|
||||
Vendored
+2
@@ -202,3 +202,5 @@ The code above yields the output below:
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
Note: If the chunk size is 0 lines, i.e., `getStartRange()` or `getEndRange()` return 0, the number of line returned by `getStart()` or `getEnd()` is one lower than one would expect. It is the line number after which the chunk should be inserted or deleted; in all other cases, it gives the first line number of the replaced range of lines.
|
||||
|
||||
Vendored
+25
-4
@@ -1,9 +1,30 @@
|
||||
# Security Policy
|
||||
|
||||
This library is intended to be used in development environments only. For instance, it is used by the testing framework PHPUnit. There is no reason why this library should be installed on a webserver.
|
||||
If you believe you have found a security vulnerability in the library that is developed in this repository, please report it to us through coordinated disclosure.
|
||||
|
||||
**If you upload this library to a webserver then your deployment process is broken. On a more general note, if your `vendor` directory is publicly accessible on your webserver then your deployment process is also broken.**
|
||||
**Please do not report security vulnerabilities through public GitHub issues, discussions, or pull requests.**
|
||||
|
||||
## Security Contact Information
|
||||
Instead, please email `sebastian@phpunit.de`.
|
||||
|
||||
Please include as much of the information listed below as you can to help us better understand and resolve the issue:
|
||||
|
||||
* The type of issue
|
||||
* Full paths of source file(s) related to the manifestation of the issue
|
||||
* The location of the affected source code (tag/branch/commit or direct URL)
|
||||
* Any special configuration required to reproduce the issue
|
||||
* Step-by-step instructions to reproduce the issue
|
||||
* Proof-of-concept or exploit code (if possible)
|
||||
* Impact of the issue, including how an attacker might exploit the issue
|
||||
|
||||
This information will help us triage your report more quickly.
|
||||
|
||||
## Web Context
|
||||
|
||||
The library that is developed in this repository was either extracted from [PHPUnit](https://github.com/sebastianbergmann/phpunit) or developed specifically as a dependency for PHPUnit.
|
||||
|
||||
The library is developed with a focus on development environments and the command-line. No specific testing or hardening with regard to using the library in an HTTP or web context or with untrusted input data is performed. The library might also contain functionality that intentionally exposes internal application data for debugging purposes.
|
||||
|
||||
If the library is used in a web application, the application developer is responsible for filtering inputs or escaping outputs as necessary and for verifying that the used functionality is safe for use within the intended context.
|
||||
|
||||
Vulnerabilities specific to the use outside a development context will be fixed as applicable, provided that the fix does not have an averse effect on the primary use case for development purposes.
|
||||
|
||||
After the above, if you still would like to report a security vulnerability, please email `sebastian@phpunit.de`.
|
||||
|
||||
Vendored
+6
-2
@@ -14,6 +14,10 @@
|
||||
"email": "mail@kore-nordmann.de"
|
||||
}
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/sebastianbergmann/diff/issues",
|
||||
"security": "https://github.com/sebastianbergmann/diff/security/policy"
|
||||
},
|
||||
"prefer-stable": true,
|
||||
"config": {
|
||||
"platform": {
|
||||
@@ -27,7 +31,7 @@
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^10.0",
|
||||
"symfony/process": "^4.2 || ^5"
|
||||
"symfony/process": "^6.4"
|
||||
},
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
@@ -41,7 +45,7 @@
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "5.0-dev"
|
||||
"dev-main": "5.1-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+60
-6
@@ -9,7 +9,14 @@
|
||||
*/
|
||||
namespace SebastianBergmann\Diff;
|
||||
|
||||
final class Chunk
|
||||
use ArrayIterator;
|
||||
use IteratorAggregate;
|
||||
use Traversable;
|
||||
|
||||
/**
|
||||
* @template-implements IteratorAggregate<int, Line>
|
||||
*/
|
||||
final class Chunk implements IteratorAggregate
|
||||
{
|
||||
private int $start;
|
||||
private int $startRange;
|
||||
@@ -26,22 +33,22 @@ final class Chunk
|
||||
$this->lines = $lines;
|
||||
}
|
||||
|
||||
public function getStart(): int
|
||||
public function start(): int
|
||||
{
|
||||
return $this->start;
|
||||
}
|
||||
|
||||
public function getStartRange(): int
|
||||
public function startRange(): int
|
||||
{
|
||||
return $this->startRange;
|
||||
}
|
||||
|
||||
public function getEnd(): int
|
||||
public function end(): int
|
||||
{
|
||||
return $this->end;
|
||||
}
|
||||
|
||||
public function getEndRange(): int
|
||||
public function endRange(): int
|
||||
{
|
||||
return $this->endRange;
|
||||
}
|
||||
@@ -49,7 +56,7 @@ final class Chunk
|
||||
/**
|
||||
* @psalm-return list<Line>
|
||||
*/
|
||||
public function getLines(): array
|
||||
public function lines(): array
|
||||
{
|
||||
return $this->lines;
|
||||
}
|
||||
@@ -67,4 +74,51 @@ final class Chunk
|
||||
|
||||
$this->lines = $lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use start() instead
|
||||
*/
|
||||
public function getStart(): int
|
||||
{
|
||||
return $this->start;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use startRange() instead
|
||||
*/
|
||||
public function getStartRange(): int
|
||||
{
|
||||
return $this->startRange;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use end() instead
|
||||
*/
|
||||
public function getEnd(): int
|
||||
{
|
||||
return $this->end;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use endRange() instead
|
||||
*/
|
||||
public function getEndRange(): int
|
||||
{
|
||||
return $this->endRange;
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-return list<Line>
|
||||
*
|
||||
* @deprecated Use lines() instead
|
||||
*/
|
||||
public function getLines(): array
|
||||
{
|
||||
return $this->lines;
|
||||
}
|
||||
|
||||
public function getIterator(): Traversable
|
||||
{
|
||||
return new ArrayIterator($this->lines);
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+61
-4
@@ -9,9 +9,23 @@
|
||||
*/
|
||||
namespace SebastianBergmann\Diff;
|
||||
|
||||
final class Diff
|
||||
use ArrayIterator;
|
||||
use IteratorAggregate;
|
||||
use Traversable;
|
||||
|
||||
/**
|
||||
* @template-implements IteratorAggregate<int, Chunk>
|
||||
*/
|
||||
final class Diff implements IteratorAggregate
|
||||
{
|
||||
/**
|
||||
* @psalm-var non-empty-string
|
||||
*/
|
||||
private string $from;
|
||||
|
||||
/**
|
||||
* @psalm-var non-empty-string
|
||||
*/
|
||||
private string $to;
|
||||
|
||||
/**
|
||||
@@ -20,6 +34,8 @@ final class Diff
|
||||
private array $chunks;
|
||||
|
||||
/**
|
||||
* @psalm-param non-empty-string $from
|
||||
* @psalm-param non-empty-string $to
|
||||
* @psalm-param list<Chunk> $chunks
|
||||
*/
|
||||
public function __construct(string $from, string $to, array $chunks = [])
|
||||
@@ -29,12 +45,18 @@ final class Diff
|
||||
$this->chunks = $chunks;
|
||||
}
|
||||
|
||||
public function getFrom(): string
|
||||
/**
|
||||
* @psalm-return non-empty-string
|
||||
*/
|
||||
public function from(): string
|
||||
{
|
||||
return $this->from;
|
||||
}
|
||||
|
||||
public function getTo(): string
|
||||
/**
|
||||
* @psalm-return non-empty-string
|
||||
*/
|
||||
public function to(): string
|
||||
{
|
||||
return $this->to;
|
||||
}
|
||||
@@ -42,7 +64,7 @@ final class Diff
|
||||
/**
|
||||
* @psalm-return list<Chunk>
|
||||
*/
|
||||
public function getChunks(): array
|
||||
public function chunks(): array
|
||||
{
|
||||
return $this->chunks;
|
||||
}
|
||||
@@ -54,4 +76,39 @@ final class Diff
|
||||
{
|
||||
$this->chunks = $chunks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-return non-empty-string
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public function getFrom(): string
|
||||
{
|
||||
return $this->from;
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-return non-empty-string
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public function getTo(): string
|
||||
{
|
||||
return $this->to;
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-return list<Chunk>
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public function getChunks(): array
|
||||
{
|
||||
return $this->chunks;
|
||||
}
|
||||
|
||||
public function getIterator(): Traversable
|
||||
{
|
||||
return new ArrayIterator($this->chunks);
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+6
-10
@@ -30,14 +30,10 @@ use SebastianBergmann\Diff\Output\DiffOutputBuilderInterface;
|
||||
|
||||
final class Differ
|
||||
{
|
||||
public const OLD = 0;
|
||||
|
||||
public const ADDED = 1;
|
||||
|
||||
public const REMOVED = 2;
|
||||
|
||||
public const DIFF_LINE_END_WARNING = 3;
|
||||
|
||||
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;
|
||||
private DiffOutputBuilderInterface $outputBuilder;
|
||||
|
||||
@@ -46,14 +42,14 @@ final class Differ
|
||||
$this->outputBuilder = $outputBuilder;
|
||||
}
|
||||
|
||||
public function diff(array|string $from, array|string $to, LongestCommonSubsequenceCalculator $lcs = null): string
|
||||
public function diff(array|string $from, array|string $to, ?LongestCommonSubsequenceCalculator $lcs = null): string
|
||||
{
|
||||
$diff = $this->diffToArray($from, $to, $lcs);
|
||||
|
||||
return $this->outputBuilder->getDiff($diff);
|
||||
}
|
||||
|
||||
public function diffToArray(array|string $from, array|string $to, LongestCommonSubsequenceCalculator $lcs = null): array
|
||||
public function diffToArray(array|string $from, array|string $to, ?LongestCommonSubsequenceCalculator $lcs = null): array
|
||||
{
|
||||
if (is_string($from)) {
|
||||
$from = $this->splitStringByLines($from);
|
||||
|
||||
@@ -21,17 +21,17 @@ final class ConfigurationException extends InvalidArgumentException
|
||||
string $expected,
|
||||
$value,
|
||||
int $code = 0,
|
||||
Exception $previous = null
|
||||
?Exception $previous = null
|
||||
) {
|
||||
parent::__construct(
|
||||
sprintf(
|
||||
'Option "%s" must be %s, got "%s".',
|
||||
$option,
|
||||
$expected,
|
||||
is_object($value) ? $value::class : (null === $value ? '<null>' : gettype($value) . '#' . $value)
|
||||
is_object($value) ? $value::class : (null === $value ? '<null>' : gettype($value) . '#' . $value),
|
||||
),
|
||||
$code,
|
||||
$previous
|
||||
$previous,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+33
-4
@@ -11,10 +11,8 @@ namespace SebastianBergmann\Diff;
|
||||
|
||||
final class Line
|
||||
{
|
||||
public const ADDED = 1;
|
||||
|
||||
public const REMOVED = 2;
|
||||
|
||||
public const ADDED = 1;
|
||||
public const REMOVED = 2;
|
||||
public const UNCHANGED = 3;
|
||||
private int $type;
|
||||
private string $content;
|
||||
@@ -25,11 +23,42 @@ final class Line
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
public function content(): string
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
public function type(): int
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function isAdded(): bool
|
||||
{
|
||||
return $this->type === self::ADDED;
|
||||
}
|
||||
|
||||
public function isRemoved(): bool
|
||||
{
|
||||
return $this->type === self::REMOVED;
|
||||
}
|
||||
|
||||
public function isUnchanged(): bool
|
||||
{
|
||||
return $this->type === self::UNCHANGED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
public function getContent(): string
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
public function getType(): int
|
||||
{
|
||||
return $this->type;
|
||||
|
||||
+11
-2
@@ -61,7 +61,7 @@ final class MemoryEfficientLongestCommonSubsequenceCalculator implements Longest
|
||||
|
||||
return array_merge(
|
||||
$this->calculate($fromStart, $toStart),
|
||||
$this->calculate($fromEnd, $toEnd)
|
||||
$this->calculate($fromEnd, $toEnd),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -78,7 +78,16 @@ final class MemoryEfficientLongestCommonSubsequenceCalculator implements Longest
|
||||
if ($from[$i] === $to[$j]) {
|
||||
$current[$j + 1] = $prev[$j] + 1;
|
||||
} else {
|
||||
$current[$j + 1] = max($current[$j], $prev[$j + 1]);
|
||||
/**
|
||||
* @noinspection PhpConditionCanBeReplacedWithMinMaxCallInspection
|
||||
*
|
||||
* We do not use max() here to avoid the function call overhead
|
||||
*/
|
||||
if ($current[$j] > $prev[$j + 1]) {
|
||||
$current[$j + 1] = $current[$j];
|
||||
} else {
|
||||
$current[$j + 1] = $prev[$j + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ final class StrictUnifiedDiffOutputBuilder implements DiffOutputBuilderInterface
|
||||
$options['fromFile'],
|
||||
null === $options['fromFileDate'] ? '' : "\t" . $options['fromFileDate'],
|
||||
$options['toFile'],
|
||||
null === $options['toFileDate'] ? '' : "\t" . $options['toFileDate']
|
||||
null === $options['toFileDate'] ? '' : "\t" . $options['toFileDate'],
|
||||
);
|
||||
|
||||
$this->collapseRanges = $options['collapseRanges'];
|
||||
@@ -201,11 +201,11 @@ final class StrictUnifiedDiffOutputBuilder implements DiffOutputBuilderInterface
|
||||
$fromRange - $cutOff + $contextStartOffset + $this->contextLines,
|
||||
$toStart - $contextStartOffset,
|
||||
$toRange - $cutOff + $contextStartOffset + $this->contextLines,
|
||||
$output
|
||||
$output,
|
||||
);
|
||||
|
||||
$fromStart += $fromRange;
|
||||
$toStart += $toRange;
|
||||
$toStart += $toRange;
|
||||
|
||||
$hunkCapture = false;
|
||||
$sameCount = $toRange = $fromRange = 0;
|
||||
@@ -251,7 +251,7 @@ final class StrictUnifiedDiffOutputBuilder implements DiffOutputBuilderInterface
|
||||
$contextEndOffset = min($sameCount, $this->contextLines);
|
||||
|
||||
$fromRange -= $sameCount;
|
||||
$toRange -= $sameCount;
|
||||
$toRange -= $sameCount;
|
||||
|
||||
$this->writeHunk(
|
||||
$diff,
|
||||
@@ -261,7 +261,7 @@ final class StrictUnifiedDiffOutputBuilder implements DiffOutputBuilderInterface
|
||||
$fromRange + $contextStartOffset + $contextEndOffset,
|
||||
$toStart - $contextStartOffset,
|
||||
$toRange + $contextStartOffset + $contextEndOffset,
|
||||
$output
|
||||
$output,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -302,11 +302,11 @@ final class StrictUnifiedDiffOutputBuilder implements DiffOutputBuilderInterface
|
||||
$this->changed = true;
|
||||
fwrite($output, $diff[$i][0]);
|
||||
}
|
||||
//} elseif ($diff[$i][1] === Differ::DIFF_LINE_END_WARNING) { // custom comment inserted by PHPUnit/diff package
|
||||
// } elseif ($diff[$i][1] === Differ::DIFF_LINE_END_WARNING) { // custom comment inserted by PHPUnit/diff package
|
||||
// skip
|
||||
//} else {
|
||||
// } else {
|
||||
// unknown/invalid
|
||||
//}
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ use function max;
|
||||
use function min;
|
||||
use function str_ends_with;
|
||||
use function stream_get_contents;
|
||||
use function strlen;
|
||||
use function substr;
|
||||
use SebastianBergmann\Diff\Differ;
|
||||
|
||||
@@ -67,7 +66,7 @@ final class UnifiedDiffOutputBuilder extends AbstractChunkOutputBuilder
|
||||
// This might happen when both the `from` and `to` do not have a trailing linebreak
|
||||
$last = substr($diff, -1);
|
||||
|
||||
return 0 !== strlen($diff) && "\n" !== $last && "\r" !== $last
|
||||
return '' !== $diff && "\n" !== $last && "\r" !== $last
|
||||
? $diff . "\n"
|
||||
: $diff;
|
||||
}
|
||||
@@ -151,11 +150,11 @@ final class UnifiedDiffOutputBuilder extends AbstractChunkOutputBuilder
|
||||
$fromRange - $cutOff + $contextStartOffset + $this->contextLines,
|
||||
$toStart - $contextStartOffset,
|
||||
$toRange - $cutOff + $contextStartOffset + $this->contextLines,
|
||||
$output
|
||||
$output,
|
||||
);
|
||||
|
||||
$fromStart += $fromRange;
|
||||
$toStart += $toRange;
|
||||
$toStart += $toRange;
|
||||
|
||||
$hunkCapture = false;
|
||||
$sameCount = $toRange = $fromRange = 0;
|
||||
@@ -199,7 +198,7 @@ final class UnifiedDiffOutputBuilder extends AbstractChunkOutputBuilder
|
||||
$contextEndOffset = min($sameCount, $this->contextLines);
|
||||
|
||||
$fromRange -= $sameCount;
|
||||
$toRange -= $sameCount;
|
||||
$toRange -= $sameCount;
|
||||
|
||||
$this->writeHunk(
|
||||
$diff,
|
||||
@@ -209,7 +208,7 @@ final class UnifiedDiffOutputBuilder extends AbstractChunkOutputBuilder
|
||||
$fromRange + $contextStartOffset + $contextEndOffset,
|
||||
$toStart - $contextStartOffset,
|
||||
$toRange + $contextStartOffset + $contextEndOffset,
|
||||
$output
|
||||
$output,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Vendored
+7
-3
@@ -10,6 +10,7 @@
|
||||
namespace SebastianBergmann\Diff;
|
||||
|
||||
use function array_pop;
|
||||
use function assert;
|
||||
use function count;
|
||||
use function max;
|
||||
use function preg_match;
|
||||
@@ -46,6 +47,9 @@ final class Parser
|
||||
$collected = [];
|
||||
}
|
||||
|
||||
assert(!empty($fromMatch['file']));
|
||||
assert(!empty($toMatch['file']));
|
||||
|
||||
$diff = new Diff($fromMatch['file'], $toMatch['file']);
|
||||
|
||||
$i++;
|
||||
@@ -74,12 +78,12 @@ final class Parser
|
||||
$diffLines = [];
|
||||
|
||||
foreach ($lines as $line) {
|
||||
if (preg_match('/^@@\s+-(?P<start>\d+)(?:,\s*(?P<startrange>\d+))?\s+\+(?P<end>\d+)(?:,\s*(?P<endrange>\d+))?\s+@@/', $line, $match)) {
|
||||
if (preg_match('/^@@\s+-(?P<start>\d+)(?:,\s*(?P<startrange>\d+))?\s+\+(?P<end>\d+)(?:,\s*(?P<endrange>\d+))?\s+@@/', $line, $match, PREG_UNMATCHED_AS_NULL)) {
|
||||
$chunk = new Chunk(
|
||||
(int) $match['start'],
|
||||
isset($match['startrange']) ? max(1, (int) $match['startrange']) : 1,
|
||||
isset($match['startrange']) ? max(0, (int) $match['startrange']) : 1,
|
||||
(int) $match['end'],
|
||||
isset($match['endrange']) ? max(1, (int) $match['endrange']) : 1
|
||||
isset($match['endrange']) ? max(0, (int) $match['endrange']) : 1,
|
||||
);
|
||||
|
||||
$chunks[] = $chunk;
|
||||
|
||||
+18
-6
@@ -37,12 +37,24 @@ final class TimeEfficientLongestCommonSubsequenceCalculator implements LongestCo
|
||||
|
||||
for ($i = 1; $i <= $fromLength; $i++) {
|
||||
for ($j = 1; $j <= $toLength; $j++) {
|
||||
$o = ($j * $width) + $i;
|
||||
$matrix[$o] = max(
|
||||
$matrix[$o - 1],
|
||||
$matrix[$o - $width],
|
||||
$from[$i - 1] === $to[$j - 1] ? $matrix[$o - $width - 1] + 1 : 0
|
||||
);
|
||||
$o = ($j * $width) + $i;
|
||||
|
||||
// don't use max() to avoid function call overhead
|
||||
$firstOrLast = $from[$i - 1] === $to[$j - 1] ? $matrix[$o - $width - 1] + 1 : 0;
|
||||
|
||||
if ($matrix[$o - 1] > $matrix[$o - $width]) {
|
||||
if ($firstOrLast > $matrix[$o - 1]) {
|
||||
$matrix[$o] = $firstOrLast;
|
||||
} else {
|
||||
$matrix[$o] = $matrix[$o - 1];
|
||||
}
|
||||
} else {
|
||||
if ($firstOrLast > $matrix[$o - $width]) {
|
||||
$matrix[$o] = $firstOrLast;
|
||||
} else {
|
||||
$matrix[$o] = $matrix[$o - $width];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user