Updated Rector to commit c3ff0fd4328b603df30c7e7bb833cb1e641f410c

c3ff0fd432 Upgrade to PHPUnit 10 🥳️ (#3332)
This commit is contained in:
Tomas Votruba 2023-02-03 17:47:50 +00:00
parent 84eb4a5d0c
commit 5a533a3702
34 changed files with 311 additions and 216 deletions

View File

@ -45,7 +45,6 @@ use Rector\PhpDocParser\PhpParser\SmartPhpParserFactory;
use Rector\PSR4\Composer\PSR4NamespaceMatcher;
use Rector\PSR4\Contract\PSR4AutoloadNamespaceMatcherInterface;
use Rector\Utils\Command\MissingInSetCommand;
use RectorPrefix202302\SebastianBergmann\Diff\Differ;
use RectorPrefix202302\Symfony\Component\Console\Application;
use RectorPrefix202302\Symfony\Component\Console\Style\SymfonyStyle;
use function RectorPrefix202302\Symfony\Component\DependencyInjection\Loader\Configurator\service;
@ -144,6 +143,4 @@ return static function (RectorConfig $rectorConfig) : void {
$services->set(\PHPStan\PhpDocParser\Lexer\Lexer::class);
$services->set(TypeParser::class);
$services->set(ConstExprParser::class);
// console color diff
$services->set(Differ::class);
};

View File

@ -20,9 +20,9 @@ final class RenameSimpleRectorTest extends AbstractRectorTestCase
/**
* @return Iterator<array<string>>
*/
public function provideData(): Iterator
public static function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
public function provideConfigFilePath(): string

View File

@ -80,7 +80,7 @@ abstract class AbstractRectorTestCase extends \Rector\Testing\PHPUnit\AbstractTe
/**
* @return Iterator<<string>>
*/
protected function yieldFilesFromDirectory(string $directory, string $suffix = '*.php.inc') : Iterator
protected static function yieldFilesFromDirectory(string $directory, string $suffix = '*.php.inc') : Iterator
{
return FixtureFileFinder::yieldDirectory($directory, $suffix);
}
@ -105,7 +105,7 @@ abstract class AbstractRectorTestCase extends \Rector\Testing\PHPUnit\AbstractTe
$this->originalTempFilePath = $inputFilePath;
$this->doTestFileMatchesExpectedContent($inputFilePath, $expectedFilePath, $fixtureFilePath);
}
protected function getFixtureTempDirectory() : string
protected static function getFixtureTempDirectory() : string
{
return FixtureTempFileDumper::getTempDirectory();
}

View File

@ -41,7 +41,7 @@ final class ImageBinaryTest extends TestCase
// ...
}
public function provideData(): array
public static function provideData(): array
{
return [['content', 8], ['content123', 11]];
}
@ -60,7 +60,7 @@ final class ImageBinaryTest extends TestCase
// ...
}
public function provideData(): array
public static function provideData(): array
{
return [
['content', 8],

View File

@ -69,7 +69,7 @@ final class SomeTest extends TestCase
{
}
public function provideData()
public static function provideData()
{
yield ['name'];
}
@ -87,7 +87,7 @@ final class SomeTest extends TestCase
{
}
public function provideData()
public static function provideData()
{
yield ['name'];
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '1fd38073d08dff31e7b6f5fecdfc0df8f6e897b0';
public const PACKAGE_VERSION = 'c3ff0fd4328b603df30c7e7bb833cb1e641f410c';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-02-02 17:49:56';
public const RELEASE_DATE = '2023-02-03 17:42:57';
/**
* @var int
*/

View File

@ -4,6 +4,8 @@ declare (strict_types=1);
namespace Rector\Core\Console\Formatter;
use RectorPrefix202302\SebastianBergmann\Diff\Differ;
use RectorPrefix202302\SebastianBergmann\Diff\Output\StrictUnifiedDiffOutputBuilder;
use RectorPrefix202302\SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder;
final class ConsoleDiffer
{
/**
@ -16,10 +18,13 @@ final class ConsoleDiffer
* @var \Rector\Core\Console\Formatter\ColorConsoleDiffFormatter
*/
private $colorConsoleDiffFormatter;
public function __construct(Differ $differ, \Rector\Core\Console\Formatter\ColorConsoleDiffFormatter $colorConsoleDiffFormatter)
public function __construct(\Rector\Core\Console\Formatter\ColorConsoleDiffFormatter $colorConsoleDiffFormatter)
{
$this->differ = $differ;
$this->colorConsoleDiffFormatter = $colorConsoleDiffFormatter;
// @see https://github.com/sebastianbergmann/diff#strictunifieddiffoutputbuilder
// @see https://github.com/sebastianbergmann/diff/compare/4.0.4...5.0.0#diff-251edf56a6344c03fa264a4926b06c2cee43c25f66192d5f39ebee912b7442dc for upgrade
$unifiedDiffOutputBuilder = new UnifiedDiffOutputBuilder();
$this->differ = new Differ($unifiedDiffOutputBuilder);
}
public function diff(string $old, string $new) : string
{

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInita47dd119f87e03c2c15debfad792ecd7::getLoader();
return ComposerAutoloaderInit3f38aa930f66abcbdeb033aa5b78a720::getLoader();

View File

@ -2047,6 +2047,7 @@ return array(
'Rector\\PHPUnit\\PhpDoc\\PhpDocValueToNodeMapper' => $vendorDir . '/rector/rector-phpunit/src/PhpDoc/PhpDocValueToNodeMapper.php',
'Rector\\PHPUnit\\Rector\\ClassMethod\\AddDoesNotPerformAssertionToNonAssertingTestRector' => $vendorDir . '/rector/rector-phpunit/src/Rector/ClassMethod/AddDoesNotPerformAssertionToNonAssertingTestRector.php',
'Rector\\PHPUnit\\Rector\\ClassMethod\\CreateMockToAnonymousClassRector' => $vendorDir . '/rector/rector-phpunit/src/Rector/ClassMethod/CreateMockToAnonymousClassRector.php',
'Rector\\PHPUnit\\Rector\\ClassMethod\\DataProviderAnnotationToAttributeRector' => $vendorDir . '/rector/rector-phpunit/src/Rector/ClassMethod/DataProviderAnnotationToAttributeRector.php',
'Rector\\PHPUnit\\Rector\\ClassMethod\\DependsAnnotationWithValueToAttributeRector' => $vendorDir . '/rector/rector-phpunit/src/Rector/ClassMethod/DependsAnnotationWithValueToAttributeRector.php',
'Rector\\PHPUnit\\Rector\\ClassMethod\\ExceptionAnnotationRector' => $vendorDir . '/rector/rector-phpunit/src/Rector/ClassMethod/ExceptionAnnotationRector.php',
'Rector\\PHPUnit\\Rector\\ClassMethod\\RemoveEmptyTestMethodRector' => $vendorDir . '/rector/rector-phpunit/src/Rector/ClassMethod/RemoveEmptyTestMethodRector.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInita47dd119f87e03c2c15debfad792ecd7
class ComposerAutoloaderInit3f38aa930f66abcbdeb033aa5b78a720
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInita47dd119f87e03c2c15debfad792ecd7
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInita47dd119f87e03c2c15debfad792ecd7', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit3f38aa930f66abcbdeb033aa5b78a720', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInita47dd119f87e03c2c15debfad792ecd7', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit3f38aa930f66abcbdeb033aa5b78a720', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInita47dd119f87e03c2c15debfad792ecd7::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit3f38aa930f66abcbdeb033aa5b78a720::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInita47dd119f87e03c2c15debfad792ecd7::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInit3f38aa930f66abcbdeb033aa5b78a720::$files;
$requireFile = static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInita47dd119f87e03c2c15debfad792ecd7
class ComposerStaticInit3f38aa930f66abcbdeb033aa5b78a720
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -2292,6 +2292,7 @@ class ComposerStaticInita47dd119f87e03c2c15debfad792ecd7
'Rector\\PHPUnit\\PhpDoc\\PhpDocValueToNodeMapper' => __DIR__ . '/..' . '/rector/rector-phpunit/src/PhpDoc/PhpDocValueToNodeMapper.php',
'Rector\\PHPUnit\\Rector\\ClassMethod\\AddDoesNotPerformAssertionToNonAssertingTestRector' => __DIR__ . '/..' . '/rector/rector-phpunit/src/Rector/ClassMethod/AddDoesNotPerformAssertionToNonAssertingTestRector.php',
'Rector\\PHPUnit\\Rector\\ClassMethod\\CreateMockToAnonymousClassRector' => __DIR__ . '/..' . '/rector/rector-phpunit/src/Rector/ClassMethod/CreateMockToAnonymousClassRector.php',
'Rector\\PHPUnit\\Rector\\ClassMethod\\DataProviderAnnotationToAttributeRector' => __DIR__ . '/..' . '/rector/rector-phpunit/src/Rector/ClassMethod/DataProviderAnnotationToAttributeRector.php',
'Rector\\PHPUnit\\Rector\\ClassMethod\\DependsAnnotationWithValueToAttributeRector' => __DIR__ . '/..' . '/rector/rector-phpunit/src/Rector/ClassMethod/DependsAnnotationWithValueToAttributeRector.php',
'Rector\\PHPUnit\\Rector\\ClassMethod\\ExceptionAnnotationRector' => __DIR__ . '/..' . '/rector/rector-phpunit/src/Rector/ClassMethod/ExceptionAnnotationRector.php',
'Rector\\PHPUnit\\Rector\\ClassMethod\\RemoveEmptyTestMethodRector' => __DIR__ . '/..' . '/rector/rector-phpunit/src/Rector/ClassMethod/RemoveEmptyTestMethodRector.php',
@ -3082,9 +3083,9 @@ class ComposerStaticInita47dd119f87e03c2c15debfad792ecd7
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInita47dd119f87e03c2c15debfad792ecd7::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInita47dd119f87e03c2c15debfad792ecd7::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInita47dd119f87e03c2c15debfad792ecd7::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit3f38aa930f66abcbdeb033aa5b78a720::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit3f38aa930f66abcbdeb033aa5b78a720::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit3f38aa930f66abcbdeb033aa5b78a720::$classMap;
}, null, ClassLoader::class);
}

View File

@ -1845,12 +1845,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-doctrine.git",
"reference": "8a181e93e7db975b064b673d5553c9c073a48387"
"reference": "a2e31426b9e93623e80486bf5e49cc165089915c"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/8a181e93e7db975b064b673d5553c9c073a48387",
"reference": "8a181e93e7db975b064b673d5553c9c073a48387",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/a2e31426b9e93623e80486bf5e49cc165089915c",
"reference": "a2e31426b9e93623e80486bf5e49cc165089915c",
"shasum": ""
},
"require": {
@ -1870,13 +1870,13 @@
"rector\/rector-debugging": "dev-main",
"rector\/rector-generator": "^0.6.10",
"rector\/rector-src": "dev-main",
"symplify\/easy-coding-standard": "^11.0",
"symplify\/easy-coding-standard": "^11.2",
"symplify\/phpstan-extensions": "^11.1",
"symplify\/phpstan-rules": "^11.1",
"symplify\/rule-doc-generator": "^11.1",
"symplify\/vendor-patches": "^11.1"
},
"time": "2023-02-02T12:34:32+00:00",
"time": "2023-02-03T15:23:29+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {
@ -1914,12 +1914,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-downgrade-php.git",
"reference": "2a182490b3bfe842d6720102ac75dc7bccae481d"
"reference": "a7c960fd8036e86df5e1446b9f61302452b60741"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-downgrade-php\/zipball\/2a182490b3bfe842d6720102ac75dc7bccae481d",
"reference": "2a182490b3bfe842d6720102ac75dc7bccae481d",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-downgrade-php\/zipball\/a7c960fd8036e86df5e1446b9f61302452b60741",
"reference": "a7c960fd8036e86df5e1446b9f61302452b60741",
"shasum": ""
},
"require": {
@ -1948,7 +1948,7 @@
"tomasvotruba\/type-coverage": "^0.0.9",
"tomasvotruba\/unused-public": "^0.0.34"
},
"time": "2023-02-02T12:34:59+00:00",
"time": "2023-02-03T16:00:40+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {
@ -1989,12 +1989,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-php-parser.git",
"reference": "9ea5f622c1ed47addb197ded25a6bac39c39c596"
"reference": "ed84d2bc08ce2eb8c8860b17d1d0dc4767be6f4f"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-php-parser\/zipball\/9ea5f622c1ed47addb197ded25a6bac39c39c596",
"reference": "9ea5f622c1ed47addb197ded25a6bac39c39c596",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-php-parser\/zipball\/ed84d2bc08ce2eb8c8860b17d1d0dc4767be6f4f",
"reference": "ed84d2bc08ce2eb8c8860b17d1d0dc4767be6f4f",
"shasum": ""
},
"require": {
@ -2019,7 +2019,7 @@
"symplify\/rule-doc-generator": "^11.1",
"symplify\/vendor-patches": "^11.1"
},
"time": "2022-11-14T14:42:43+00:00",
"time": "2023-02-03T15:56:36+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {
@ -2057,12 +2057,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-phpunit.git",
"reference": "3e9d821bd20e5385038788d26f00b29eea59209a"
"reference": "3d3f65dd46b15e14d819cb6ed9c70a7b73133875"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/3e9d821bd20e5385038788d26f00b29eea59209a",
"reference": "3e9d821bd20e5385038788d26f00b29eea59209a",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-phpunit\/zipball\/3d3f65dd46b15e14d819cb6ed9c70a7b73133875",
"reference": "3d3f65dd46b15e14d819cb6ed9c70a7b73133875",
"shasum": ""
},
"require": {
@ -2076,7 +2076,7 @@
"phpstan\/phpstan": "^1.9.2",
"phpstan\/phpstan-strict-rules": "^1.2",
"phpstan\/phpstan-webmozart-assert": "^1.1",
"phpunit\/phpunit": "^9.5",
"phpunit\/phpunit": "^9.6",
"rector\/phpstan-rules": "^0.6",
"rector\/rector-debugging": "dev-main",
"rector\/rector-generator": "^0.6",
@ -2088,7 +2088,7 @@
"symplify\/rule-doc-generator": "^11.1",
"symplify\/vendor-patches": "^11.1"
},
"time": "2023-02-02T12:33:42+00:00",
"time": "2023-02-03T15:21:57+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {
@ -2198,31 +2198,31 @@
},
{
"name": "sebastian\/diff",
"version": "4.0.4",
"version_normalized": "4.0.4.0",
"version": "5.0.0",
"version_normalized": "5.0.0.0",
"source": {
"type": "git",
"url": "https:\/\/github.com\/sebastianbergmann\/diff.git",
"reference": "3461e3fccc7cfdfc2720be910d3bd73c69be590d"
"reference": "70dd1b20bc198da394ad542e988381b44e64e39f"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/sebastianbergmann\/diff\/zipball\/3461e3fccc7cfdfc2720be910d3bd73c69be590d",
"reference": "3461e3fccc7cfdfc2720be910d3bd73c69be590d",
"url": "https:\/\/api.github.com\/repos\/sebastianbergmann\/diff\/zipball\/70dd1b20bc198da394ad542e988381b44e64e39f",
"reference": "70dd1b20bc198da394ad542e988381b44e64e39f",
"shasum": ""
},
"require": {
"php": ">=7.3"
"php": ">=8.1"
},
"require-dev": {
"phpunit\/phpunit": "^9.3",
"phpunit\/phpunit": "^10.0",
"symfony\/process": "^4.2 || ^5"
},
"time": "2020-10-26T13:10:38+00:00",
"time": "2023-02-03T07:00:31+00:00",
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "4.0-dev"
"dev-main": "5.0-dev"
}
},
"installation-source": "dist",
@ -2255,7 +2255,7 @@
],
"support": {
"issues": "https:\/\/github.com\/sebastianbergmann\/diff\/issues",
"source": "https:\/\/github.com\/sebastianbergmann\/diff\/tree\/4.0.4"
"source": "https:\/\/github.com\/sebastianbergmann\/diff\/tree\/5.0.0"
},
"funding": [
{

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
*/
final class GeneratedConfig
{
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 8a181e9'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 2a18249'), 'rector/rector-php-parser' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-php-parser', 'relative_install_path' => '../../rector-php-parser', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 9ea5f62'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 3e9d821'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 545a090'));
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main a2e3142'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main a7c960f'), 'rector/rector-php-parser' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-php-parser', 'relative_install_path' => '../../rector-php-parser', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main ed84d2b'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 3d3f65d'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 545a090'));
private function __construct()
{
}

View File

@ -13,7 +13,7 @@
"phpunit\/phpunit": "^9.5",
"symplify\/phpstan-rules": "^11.1",
"symplify\/phpstan-extensions": "^11.1",
"symplify\/easy-coding-standard": "^11.0",
"symplify\/easy-coding-standard": "^11.2",
"symplify\/rule-doc-generator": "^11.1",
"rector\/rector-src": "dev-main",
"doctrine\/orm": "^2.10",

View File

@ -8,7 +8,7 @@
},
"require-dev": {
"rector\/rector-src": "dev-main",
"phpunit\/phpunit": "^9.5",
"phpunit\/phpunit": "^9.6",
"phpstan\/phpstan": "^1.9.2",
"symplify\/phpstan-rules": "^11.1",
"symplify\/phpstan-extensions": "^11.1",

View File

@ -8,10 +8,12 @@ use Rector\Php80\Rector\Class_\AnnotationToAttributeRector;
use Rector\Php80\ValueObject\AnnotationToAttribute;
use Rector\PHPUnit\Rector\Class_\AnnotationWithValueToAttributeRector;
use Rector\PHPUnit\Rector\Class_\CoversAnnotationWithValueToAttributeRector;
use Rector\PHPUnit\Rector\ClassMethod\DataProviderAnnotationToAttributeRector;
use Rector\PHPUnit\Rector\ClassMethod\DependsAnnotationWithValueToAttributeRector;
use Rector\PHPUnit\ValueObject\AnnotationWithValueToAttribute;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->rules([
DataProviderAnnotationToAttributeRector::class,
CoversAnnotationWithValueToAttributeRector::class,
/**
* Currently handle:
@ -25,7 +27,7 @@ return static function (RectorConfig $rectorConfig) : void {
*/
DependsAnnotationWithValueToAttributeRector::class,
]);
$rectorConfig->ruleWithConfiguration(AnnotationWithValueToAttributeRector::class, [new AnnotationWithValueToAttribute('backupGlobals', 'PHPUnit\\Framework\\Attributes\\BackupGlobals', ['enabled' => \true, 'disabled' => \false]), new AnnotationWithValueToAttribute('backupStaticAttributes', 'PHPUnit\\Framework\\Attributes\\BackupStaticProperties', ['enabled' => \true, 'disabled' => \false]), new AnnotationWithValueToAttribute('preserveGlobalState', 'PHPUnit\\Framework\\Attributes\\PreserveGlobalState', ['enabled' => \true, 'disabled' => \false]), new AnnotationWithValueToAttribute('dataProvider', 'PHPUnit\\Framework\\Attributes\\DataProvider'), new AnnotationWithValueToAttribute('depends', 'PHPUnit\\Framework\\Attributes\\Depends'), new AnnotationWithValueToAttribute('group', 'PHPUnit\\Framework\\Attributes\\Group'), new AnnotationWithValueToAttribute('ticket', 'PHPUnit\\Framework\\Attributes\\Ticket'), new AnnotationWithValueToAttribute('uses', 'PHPUnit\\Framework\\Attributes\\UsesClass'), new AnnotationWithValueToAttribute('testWith', 'PHPUnit\\Framework\\Attributes\\TestWith'), new AnnotationWithValueToAttribute('testDox', 'PHPUnit\\Framework\\Attributes\\TestDox')]);
$rectorConfig->ruleWithConfiguration(AnnotationWithValueToAttributeRector::class, [new AnnotationWithValueToAttribute('backupGlobals', 'PHPUnit\\Framework\\Attributes\\BackupGlobals', ['enabled' => \true, 'disabled' => \false]), new AnnotationWithValueToAttribute('backupStaticAttributes', 'PHPUnit\\Framework\\Attributes\\BackupStaticProperties', ['enabled' => \true, 'disabled' => \false]), new AnnotationWithValueToAttribute('preserveGlobalState', 'PHPUnit\\Framework\\Attributes\\PreserveGlobalState', ['enabled' => \true, 'disabled' => \false]), new AnnotationWithValueToAttribute('depends', 'PHPUnit\\Framework\\Attributes\\Depends'), new AnnotationWithValueToAttribute('group', 'PHPUnit\\Framework\\Attributes\\Group'), new AnnotationWithValueToAttribute('ticket', 'PHPUnit\\Framework\\Attributes\\Ticket'), new AnnotationWithValueToAttribute('uses', 'PHPUnit\\Framework\\Attributes\\UsesClass'), new AnnotationWithValueToAttribute('testWith', 'PHPUnit\\Framework\\Attributes\\TestWith'), new AnnotationWithValueToAttribute('testDox', 'PHPUnit\\Framework\\Attributes\\TestDox')]);
$rectorConfig->ruleWithConfiguration(AnnotationToAttributeRector::class, [
// @see https://github.com/sebastianbergmann/phpunit/issues/4502
new AnnotationToAttribute('after', 'PHPUnit\\Framework\\Attributes\\After'),

View File

@ -0,0 +1,123 @@
<?php
declare (strict_types=1);
namespace Rector\PHPUnit\Rector\ClassMethod;
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\PhpAttribute\NodeFactory\PhpAttributeGroupFactory;
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\PHPUnit\Tests\Rector\ClassMethod\DataProviderAnnotationToAttributeRector\DataProviderAnnotationToAttributeRectorTest
*/
final class DataProviderAnnotationToAttributeRector extends AbstractRector implements MinPhpVersionInterface
{
/**
* @readonly
* @var \Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer
*/
private $testsNodeAnalyzer;
/**
* @readonly
* @var \Rector\PhpAttribute\NodeFactory\PhpAttributeGroupFactory
*/
private $phpAttributeGroupFactory;
/**
* @readonly
* @var \Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover
*/
private $phpDocTagRemover;
public function __construct(TestsNodeAnalyzer $testsNodeAnalyzer, PhpAttributeGroupFactory $phpAttributeGroupFactory, PhpDocTagRemover $phpDocTagRemover)
{
$this->testsNodeAnalyzer = $testsNodeAnalyzer;
$this->phpAttributeGroupFactory = $phpAttributeGroupFactory;
$this->phpDocTagRemover = $phpDocTagRemover;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Change dataProvider annotations to attribute', [new CodeSample(<<<'CODE_SAMPLE'
use PHPUnit\Framework\TestCase;
final class SomeTest extends TestCase
{
/**
* @dataProvider someMethod()
*/
public function test(): void
{
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
use PHPUnit\Framework\TestCase;
final class SomeTest extends TestCase
{
#[\PHPUnit\Framework\Attributes\DataProvider('test')]
public function test(): void
{
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [ClassMethod::class];
}
public function provideMinPhpVersion() : int
{
return PhpVersionFeature::ATTRIBUTES;
}
/**
* @param ClassMethod $node
*/
public function refactor(Node $node) : ?Node
{
if (!$this->testsNodeAnalyzer->isInTestClass($node)) {
return null;
}
$phpDocInfo = $this->phpDocInfoFactory->createFromNode($node);
if (!$phpDocInfo instanceof PhpDocInfo) {
return null;
}
/** @var PhpDocTagNode[] $desiredTagValueNodes */
$desiredTagValueNodes = $phpDocInfo->getTagsByName('dataProvider');
if ($desiredTagValueNodes === []) {
return null;
}
$currentClass = $node->getAttribute(AttributeKey::PARENT_NODE);
if (!$currentClass instanceof Class_) {
return null;
}
foreach ($desiredTagValueNodes as $desiredTagValueNode) {
if (!$desiredTagValueNode->value instanceof GenericTagValueNode) {
continue;
}
$originalAttributeValue = $desiredTagValueNode->value->value;
$methodName = \trim($originalAttributeValue, '()');
$attributeGroup = $this->phpAttributeGroupFactory->createFromClassWithItems('PHPUnit\\Framework\\Attributes\\DataProvider', [$methodName]);
$node->attrGroups[] = $attributeGroup;
// cleanup
$this->phpDocTagRemover->removeTagValueFromNode($phpDocInfo, $desiredTagValueNode);
}
if (!$phpDocInfo->hasChanged()) {
return null;
}
return $node;
}
}

View File

@ -2,6 +2,16 @@
All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
## [5.0.0] - 2022-02-03
### Changed
* Passing a `DiffOutputBuilderInterface` instance to `Differ::__construct()` is no longer optional
### Removed
* Removed support for PHP 7.3, PHP 7.4, and PHP 8.0
## [4.0.4] - 2020-10-26
### Fixed
@ -76,6 +86,7 @@ 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.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
[4.0.2]: https://github.com/sebastianbergmann/diff/compare/4.0.1...4.0.2

View File

@ -1,33 +1,29 @@
sebastian/diff
BSD 3-Clause License
Copyright (c) 2002-2020, Sebastian Bergmann <sebastian@phpunit.de>.
Copyright (c) 2002-2023, Sebastian Bergmann
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Sebastian Bergmann nor the names of his
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -1,7 +1,9 @@
# sebastian/diff
[![Latest Stable Version](https://poser.pugx.org/sebastian/diff/v/stable.png)](https://packagist.org/packages/sebastian/diff)
[![CI Status](https://github.com/sebastianbergmann/diff/workflows/CI/badge.svg)](https://github.com/sebastianbergmann/diff/actions)
[![Type Coverage](https://shepherd.dev/github/sebastianbergmann/diff/coverage.svg)](https://shepherd.dev/github/sebastianbergmann/diff)
[![codecov](https://codecov.io/gh/sebastianbergmann/diff/branch/main/graph/badge.svg)](https://codecov.io/gh/sebastianbergmann/diff)
# sebastian/diff
Diff implementation for PHP, factored out of PHPUnit into a stand-alone component.
@ -78,9 +80,9 @@ $builder = new StrictUnifiedDiffOutputBuilder([
'collapseRanges' => true, // ranges of length one are rendered with the trailing `,1`
'commonLineThreshold' => 6, // number of same lines before ending a new hunk and creating a new one (if needed)
'contextLines' => 3, // like `diff: -u, -U NUM, --unified[=NUM]`, for patch/git apply compatibility best to keep at least @ 3
'fromFile' => null,
'fromFile' => '',
'fromFileDate' => null,
'toFile' => null,
'toFile' => '',
'toFileDate' => null,
]);

9
vendor/sebastian/diff/SECURITY.md vendored Normal file
View File

@ -0,0 +1,9 @@
# 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 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.**
## Security Contact Information
After the above, if you still would like to report a security vulnerability, please email `sebastian@phpunit.de`.

View File

@ -22,16 +22,16 @@
"prefer-stable": true,
"config": {
"platform": {
"php": "7.3.0"
"php": "8.1.0"
},
"optimize-autoloader": true,
"sort-packages": true
},
"require": {
"php": ">=7.3"
"php": ">=8.1"
},
"require-dev": {
"phpunit\/phpunit": "^9.3",
"phpunit\/phpunit": "^10.0",
"symfony\/process": "^4.2 || ^5"
},
"autoload": {
@ -46,7 +46,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "4.0-dev"
"dev-main": "5.0-dev"
}
}
}

View File

@ -30,7 +30,7 @@ final class Chunk
*/
private $endRange;
/**
* @var Line[]
* @var mixed[]
*/
private $lines;
public function __construct(int $start = 0, int $startRange = 1, int $end = 0, int $endRange = 1, array $lines = [])
@ -58,14 +58,14 @@ final class Chunk
return $this->endRange;
}
/**
* @return Line[]
* @psalm-return list<Line>
*/
public function getLines() : array
{
return $this->lines;
}
/**
* @param Line[] $lines
* @psalm-param list<Line> $lines
*/
public function setLines(array $lines) : void
{

View File

@ -22,11 +22,12 @@ final class Diff
*/
private $to;
/**
* @var Chunk[]
* @psalm-var list<Chunk>
* @var mixed[]
*/
private $chunks;
/**
* @param Chunk[] $chunks
* @psalm-param list<Chunk> $chunks
*/
public function __construct(string $from, string $to, array $chunks = [])
{
@ -43,14 +44,14 @@ final class Diff
return $this->to;
}
/**
* @return Chunk[]
* @psalm-return list<Chunk>
*/
public function getChunks() : array
{
return $this->chunks;
}
/**
* @param Chunk[] $chunks
* @psalm-param list<Chunk> $chunks
*/
public function setChunks(array $chunks) : void
{

View File

@ -20,20 +20,15 @@ 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 str_ends_with;
use function substr;
use RectorPrefix202302\SebastianBergmann\Diff\Output\DiffOutputBuilderInterface;
use RectorPrefix202302\SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder;
final class Differ
{
public const OLD = 0;
@ -42,66 +37,33 @@ final class Differ
public const DIFF_LINE_END_WARNING = 3;
public const NO_LINE_END_EOF_WARNING = 4;
/**
* @var DiffOutputBuilderInterface
* @var \SebastianBergmann\Diff\Output\DiffOutputBuilderInterface
*/
private $outputBuilder;
/**
* @param DiffOutputBuilderInterface $outputBuilder
*
* @throws InvalidArgumentException
*/
public function __construct($outputBuilder = null)
public function __construct(DiffOutputBuilderInterface $outputBuilder)
{
if ($outputBuilder instanceof DiffOutputBuilderInterface) {
$this->outputBuilder = $outputBuilder;
} elseif (null === $outputBuilder) {
$this->outputBuilder = new UnifiedDiffOutputBuilder();
} 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('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 . '"'));
}
$this->outputBuilder = $outputBuilder;
}
/**
* Returns the diff between two arrays or strings as string.
*
* @param array|string $from
* @param array|string $to
* @param mixed[]|string $from
* @param mixed[]|string $to
*/
public function diff($from, $to, LongestCommonSubsequenceCalculator $lcs = null) : string
{
$diff = $this->diffToArray($this->normalizeDiffInput($from), $this->normalizeDiffInput($to), $lcs);
$diff = $this->diffToArray($from, $to, $lcs);
return $this->outputBuilder->getDiff($diff);
}
/**
* Returns the diff between two arrays or strings as array.
*
* Each array element contains two elements:
* - [0] => mixed $token
* - [1] => 2|1|0
*
* - 2: REMOVED: $token was removed from $from
* - 1: ADDED: $token was added to $from
* - 0: OLD: $token is not changed in $to
*
* @param array|string $from
* @param array|string $to
* @param LongestCommonSubsequenceCalculator $lcs
* @param mixed[]|string $from
* @param mixed[]|string $to
*/
public function diffToArray($from, $to, LongestCommonSubsequenceCalculator $lcs = null) : array
{
if (is_string($from)) {
$from = $this->splitStringByLines($from);
} elseif (!is_array($from)) {
throw new InvalidArgumentException('"from" must be an array or string.');
}
if (is_string($to)) {
$to = $this->splitStringByLines($to);
} elseif (!is_array($to)) {
throw new InvalidArgumentException('"to" must be an array or string.');
}
[$from, $to, $start, $end] = self::getArrayDiffParted($from, $to);
if ($lcs === null) {
@ -139,21 +101,6 @@ final class Differ
}
return $diff;
}
/**
* Casts variable to string if it is not a string or array.
*
* @return array|string
*/
private function normalizeDiffInput($input)
{
if (!is_array($input) && !is_string($input)) {
return (string) $input;
}
return $input;
}
/**
* Checks if input is string, if so it will split it line-by-line.
*/
private function splitStringByLines(string $input) : array
{
return preg_split('/(.*\\R)/', $input, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
@ -171,8 +118,6 @@ final class Differ
return new TimeEfficientLongestCommonSubsequenceCalculator();
}
/**
* Calculates the estimated memory footprint for the DP-based method.
*
* @return float|int
*/
private function calculateEstimatedFootprint(array $from, array $to)
@ -180,9 +125,6 @@ final class Differ
$itemSize = PHP_INT_SIZE === 4 ? 76 : 144;
return $itemSize * min(count($from), count($to)) ** 2;
}
/**
* Returns true if line ends don't match in a diff.
*/
private function detectUnmatchedLineEndings(array $diff) : bool
{
$newLineBreaks = ['' => \true];
@ -202,7 +144,7 @@ final class Differ
if (['' => \true] === $newLineBreaks || ['' => \true] === $oldLineBreaks) {
return \false;
}
// two way compare
// two-way compare
foreach ($newLineBreaks as $break => $set) {
if (!isset($oldLineBreaks[$break])) {
return \true;
@ -227,7 +169,7 @@ final class Differ
if ("\n" !== $lc) {
return '';
}
if ("\r\n" === substr($line, -2)) {
if (\substr_compare($line, "\r\n", -\strlen("\r\n")) === 0) {
return "\r\n";
}
return "\n";

View File

@ -11,7 +11,6 @@ declare (strict_types=1);
*/
namespace RectorPrefix202302\SebastianBergmann\Diff;
use function get_class;
use function gettype;
use function is_object;
use function sprintf;
@ -20,6 +19,6 @@ final class ConfigurationException extends InvalidArgumentException
{
public function __construct(string $option, string $expected, $value, int $code = 0, Exception $previous = null)
{
parent::__construct(sprintf('Option "%s" must be %s, got "%s".', $option, $expected, is_object($value) ? get_class($value) : (null === $value ? '<null>' : gettype($value) . '#' . $value)), $code, $previous);
parent::__construct(sprintf('Option "%s" must be %s, got "%s".', $option, $expected, is_object($value) ? \get_class($value) : (null === $value ? '<null>' : gettype($value) . '#' . $value)), $code, $previous);
}
}

View File

@ -21,7 +21,7 @@ use function max;
final class MemoryEfficientLongestCommonSubsequenceCalculator implements LongestCommonSubsequenceCalculator
{
/**
* {@inheritdoc}
* @inheritDoc
*/
public function calculate(array $from, array $to) : array
{

View File

@ -25,14 +25,14 @@ abstract class AbstractChunkOutputBuilder implements DiffOutputBuilderInterface
$chunkStart = 0;
$chunkSize = 0;
$commonChunks = [];
for ($i = 0; $i < $diffSize; ++$i) {
for ($i = 0; $i < $diffSize; $i++) {
if ($diff[$i][1] === 0) {
if ($capturing === \false) {
$capturing = \true;
$chunkStart = $i;
$chunkSize = 0;
} else {
++$chunkSize;
$chunkSize++;
}
} elseif ($capturing !== \false) {
if ($chunkSize >= $lineThreshold) {

View File

@ -14,6 +14,7 @@ namespace RectorPrefix202302\SebastianBergmann\Diff\Output;
use function fclose;
use function fopen;
use function fwrite;
use function str_ends_with;
use function stream_get_contents;
use function substr;
use RectorPrefix202302\SebastianBergmann\Diff\Differ;
@ -36,7 +37,7 @@ final class DiffOnlyOutputBuilder implements DiffOutputBuilderInterface
$buffer = fopen('php://memory', 'r+b');
if ('' !== $this->header) {
fwrite($buffer, $this->header);
if ("\n" !== substr($this->header, -1, 1)) {
if (\substr_compare($this->header, "\n", -\strlen("\n")) !== 0) {
fwrite($buffer, "\n");
}
}
@ -52,7 +53,7 @@ final class DiffOnlyOutputBuilder implements DiffOutputBuilderInterface
} else {
/* Not changed (old) 0 */
continue;
// we didn't write the non changs line, so do not add a line break either
// we didn't write the not-changed line, so do not add a line break either
}
$lc = substr($diffEntry[0], -1);
if ($lc !== "\n" && $lc !== "\r") {

View File

@ -34,6 +34,9 @@ use RectorPrefix202302\SebastianBergmann\Diff\Differ;
*/
final class StrictUnifiedDiffOutputBuilder implements DiffOutputBuilderInterface
{
/**
* @var mixed[]
*/
private static $default = [
'collapseRanges' => \true,
// ranges of length one are rendered with the trailing `,1`
@ -55,7 +58,8 @@ final class StrictUnifiedDiffOutputBuilder implements DiffOutputBuilderInterface
*/
private $collapseRanges;
/**
* @var int >= 0
* @psalm-var positive-int
* @var int
*/
private $commonLineThreshold;
/**
@ -63,7 +67,8 @@ final class StrictUnifiedDiffOutputBuilder implements DiffOutputBuilderInterface
*/
private $header;
/**
* @var int >= 0
* @psalm-var positive-int
* @var int
*/
private $contextLines;
public function __construct(array $options = [])
@ -118,9 +123,9 @@ final class StrictUnifiedDiffOutputBuilder implements DiffOutputBuilderInterface
}
} else {
// search back for the last `+` and `-` line,
// check if has trailing linebreak, else add under it warning under it
// check if it has a trailing linebreak, else add a warning under it
$toFind = [1 => \true, 2 => \true];
for ($i = $upperLimit - 1; $i >= 0; --$i) {
for ($i = $upperLimit - 1; $i >= 0; $i--) {
if (isset($toFind[$diff[$i][1]])) {
unset($toFind[$diff[$i][1]]);
$lc = substr($diff[$i][0], -1);
@ -144,13 +149,13 @@ final class StrictUnifiedDiffOutputBuilder implements DiffOutputBuilderInterface
if (0 === $entry[1]) {
// same
if (\false === $hunkCapture) {
++$fromStart;
++$toStart;
$fromStart++;
$toStart++;
continue;
}
++$sameCount;
++$toRange;
++$fromRange;
$sameCount++;
$toRange++;
$fromRange++;
if ($sameCount === $cutOff) {
$contextStartOffset = $hunkCapture - $this->contextLines < 0 ? $hunkCapture : $this->contextLines;
// note: $contextEndOffset = $this->contextLines;
@ -181,17 +186,17 @@ final class StrictUnifiedDiffOutputBuilder implements DiffOutputBuilderInterface
}
if (Differ::ADDED === $entry[1]) {
// added
++$toRange;
$toRange++;
}
if (Differ::REMOVED === $entry[1]) {
// removed
++$fromRange;
$fromRange++;
}
}
if (\false === $hunkCapture) {
return;
}
// we end here when cutoff (commonLineThreshold) was not reached, but we where capturing a hunk,
// we end here when cutoff (commonLineThreshold) was not reached, but we were capturing a hunk,
// do not render hunk till end automatically because the number of context lines might be less than the commonLineThreshold
$contextStartOffset = $hunkCapture - $this->contextLines < 0 ? $hunkCapture : $this->contextLines;
// prevent trying to write out more common lines than there are in the diff _and_
@ -212,7 +217,7 @@ final class StrictUnifiedDiffOutputBuilder implements DiffOutputBuilderInterface
fwrite($output, ',' . $toRange);
}
fwrite($output, " @@\n");
for ($i = $diffStartIndex; $i < $diffEndIndex; ++$i) {
for ($i = $diffStartIndex; $i < $diffEndIndex; $i++) {
if ($diff[$i][1] === Differ::ADDED) {
$this->changed = \true;
fwrite($output, '+' . $diff[$i][0]);

View File

@ -18,6 +18,7 @@ use function fopen;
use function fwrite;
use function max;
use function min;
use function str_ends_with;
use function stream_get_contents;
use function strlen;
use function substr;
@ -32,11 +33,12 @@ final class UnifiedDiffOutputBuilder extends AbstractChunkOutputBuilder
*/
private $collapseRanges = \true;
/**
* @var int >= 0
* @var int
*/
private $commonLineThreshold = 6;
/**
* @var int >= 0
* @psalm-var positive-int
* @var int
*/
private $contextLines = 3;
/**
@ -57,7 +59,7 @@ final class UnifiedDiffOutputBuilder extends AbstractChunkOutputBuilder
$buffer = fopen('php://memory', 'r+b');
if ('' !== $this->header) {
fwrite($buffer, $this->header);
if ("\n" !== substr($this->header, -1, 1)) {
if (\substr_compare($this->header, "\n", -strlen("\n")) !== 0) {
fwrite($buffer, "\n");
}
}
@ -82,9 +84,9 @@ final class UnifiedDiffOutputBuilder extends AbstractChunkOutputBuilder
}
} else {
// search back for the last `+` and `-` line,
// check if has trailing linebreak, else add under it warning under it
// check if it has trailing linebreak, else add a warning under it
$toFind = [1 => \true, 2 => \true];
for ($i = $upperLimit - 1; $i >= 0; --$i) {
for ($i = $upperLimit - 1; $i >= 0; $i--) {
if (isset($toFind[$diff[$i][1]])) {
unset($toFind[$diff[$i][1]]);
$lc = substr($diff[$i][0], -1);
@ -108,13 +110,13 @@ final class UnifiedDiffOutputBuilder extends AbstractChunkOutputBuilder
if (0 === $entry[1]) {
// same
if (\false === $hunkCapture) {
++$fromStart;
++$toStart;
$fromStart++;
$toStart++;
continue;
}
++$sameCount;
++$toRange;
++$fromRange;
$sameCount++;
$toRange++;
$fromRange++;
if ($sameCount === $cutOff) {
$contextStartOffset = $hunkCapture - $this->contextLines < 0 ? $hunkCapture : $this->contextLines;
// note: $contextEndOffset = $this->contextLines;
@ -143,16 +145,16 @@ final class UnifiedDiffOutputBuilder extends AbstractChunkOutputBuilder
$hunkCapture = $i;
}
if (Differ::ADDED === $entry[1]) {
++$toRange;
$toRange++;
}
if (Differ::REMOVED === $entry[1]) {
++$fromRange;
$fromRange++;
}
}
if (\false === $hunkCapture) {
return;
}
// we end here when cutoff (commonLineThreshold) was not reached, but we where capturing a hunk,
// we end here when cutoff (commonLineThreshold) was not reached, but we were capturing a hunk,
// do not render hunk till end automatically because the number of context lines might be less than the commonLineThreshold
$contextStartOffset = $hunkCapture - $this->contextLines < 0 ? $hunkCapture : $this->contextLines;
// prevent trying to write out more common lines than there are in the diff _and_
@ -177,7 +179,7 @@ final class UnifiedDiffOutputBuilder extends AbstractChunkOutputBuilder
} else {
fwrite($output, "@@ @@\n");
}
for ($i = $diffStartIndex; $i < $diffEndIndex; ++$i) {
for ($i = $diffStartIndex; $i < $diffEndIndex; $i++) {
if ($diff[$i][1] === Differ::ADDED) {
fwrite($output, '+' . $diff[$i][0]);
} elseif ($diff[$i][1] === Differ::REMOVED) {

View File

@ -34,7 +34,7 @@ final class Parser
$diffs = [];
$diff = null;
$collected = [];
for ($i = 0; $i < $lineCount; ++$i) {
for ($i = 0; $i < $lineCount; $i++) {
if (preg_match('#^---\\h+"?(?P<file>[^\\v\\t"]+)#', $lines[$i], $fromMatch) && preg_match('#^\\+\\+\\+\\h+"?(?P<file>[^\\v\\t"]+)#', $lines[$i + 1], $toMatch)) {
if ($diff !== null) {
$this->parseFileDiff($diff, $collected);
@ -42,9 +42,9 @@ final class Parser
$collected = [];
}
$diff = new Diff($fromMatch['file'], $toMatch['file']);
++$i;
$i++;
} else {
if (preg_match('/^(?:diff --git |index [\\da-f\\.]+|[+-]{3} [ab])/', $lines[$i])) {
if (preg_match('/^(?:diff --git |index [\\da-f.]+|[+-]{3} [ab])/', $lines[$i])) {
continue;
}
$collected[] = $lines[$i];
@ -76,9 +76,7 @@ final class Parser
$type = Line::REMOVED;
}
$diffLines[] = new Line($type, $match['line']);
if (null !== $chunk) {
$chunk->setLines($diffLines);
}
($chunk2 = $chunk) ? $chunk2->setLines($diffLines) : null;
}
}
$diff->setChunks($chunks);

View File

@ -18,7 +18,7 @@ use SplFixedArray;
final class TimeEfficientLongestCommonSubsequenceCalculator implements LongestCommonSubsequenceCalculator
{
/**
* {@inheritdoc}
* @inheritDoc
*/
public function calculate(array $from, array $to) : array
{
@ -27,14 +27,14 @@ final class TimeEfficientLongestCommonSubsequenceCalculator implements LongestCo
$toLength = count($to);
$width = $fromLength + 1;
$matrix = new SplFixedArray($width * ($toLength + 1));
for ($i = 0; $i <= $fromLength; ++$i) {
for ($i = 0; $i <= $fromLength; $i++) {
$matrix[$i] = 0;
}
for ($j = 0; $j <= $toLength; ++$j) {
for ($j = 0; $j <= $toLength; $j++) {
$matrix[$j * $width] = 0;
}
for ($i = 1; $i <= $fromLength; ++$i) {
for ($j = 1; $j <= $toLength; ++$j) {
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);
}
@ -44,14 +44,14 @@ final class TimeEfficientLongestCommonSubsequenceCalculator implements LongestCo
while ($i > 0 && $j > 0) {
if ($from[$i - 1] === $to[$j - 1]) {
$common[] = $from[$i - 1];
--$i;
--$j;
$i--;
$j--;
} else {
$o = $j * $width + $i;
if ($matrix[$o - $width] > $matrix[$o - 1]) {
--$j;
$j--;
} else {
--$i;
$i--;
}
}
}