remove vendor-patches

This commit is contained in:
Tomas Votruba 2022-05-30 09:04:57 +02:00
parent 5768646837
commit 46f05e5a7f
17 changed files with 0 additions and 618 deletions

View File

@ -1,25 +0,0 @@
The MIT License
---------------
Copyright (c) 2020-present Tomas Votruba (https://tomasvotruba.com)
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

View File

@ -1,5 +0,0 @@
#!/usr/bin/env php
<?php
namespace RectorPrefix20220530;
require __DIR__ . '/vendor-patches.php';

View File

@ -1,16 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix20220530;
use RectorPrefix20220530\Symplify\SymplifyKernel\ValueObject\KernelBootAndApplicationRun;
use RectorPrefix20220530\Symplify\VendorPatches\Kernel\VendorPatchesKernel;
$possibleAutoloadPaths = [__DIR__ . '/../autoload.php', __DIR__ . '/../vendor/autoload.php', __DIR__ . '/../../../autoload.php', __DIR__ . '/../../../vendor/autoload.php'];
foreach ($possibleAutoloadPaths as $possibleAutoloadPath) {
if (!\file_exists($possibleAutoloadPath)) {
continue;
}
require_once $possibleAutoloadPath;
}
$kernelBootAndApplicationRun = new \RectorPrefix20220530\Symplify\SymplifyKernel\ValueObject\KernelBootAndApplicationRun(\RectorPrefix20220530\Symplify\VendorPatches\Kernel\VendorPatchesKernel::class);
$kernelBootAndApplicationRun->run();

View File

@ -1,64 +0,0 @@
{
"name": "symplify\/vendor-patches",
"description": "Generate vendor patches for packages with single command",
"license": "MIT",
"bin": [
"bin\/vendor-patches"
],
"require": {
"php": ">=8.0",
"nette\/utils": "^3.2",
"symfony\/console": "^6.0",
"symfony\/dependency-injection": "^6.0",
"sebastian\/diff": "^4.0",
"cweagans\/composer-patches": "^1.7",
"symplify\/composer-json-manipulator": "^10.2.7",
"symplify\/symplify-kernel": "^10.2.7"
},
"require-dev": {
"phpunit\/phpunit": "^9.5"
},
"autoload": {
"psr-4": {
"RectorPrefix20220530\\Symplify\\VendorPatches\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"RectorPrefix20220530\\Symplify\\VendorPatches\\Tests\\": "tests"
}
},
"extra": {
"branch-alias": {
"dev-main": "10.3-dev"
}
},
"conflict": {
"symplify\/astral": "<10.2.7",
"symplify\/easy-coding-standard": "<10.2.7",
"symplify\/phpstan-rules": "<10.2.7",
"symplify\/easy-testing": "<10.2.7",
"symplify\/rule-doc-generator-contracts": "<10.2.7",
"symplify\/php-config-printer": "<10.2.7",
"symplify\/autowire-array-parameter": "<10.2.7",
"symplify\/package-builder": "<10.2.7",
"symplify\/amnesia": "<10.2.7",
"symplify\/phpstan-extensions": "<10.2.7",
"symplify\/rule-doc-generator": "<10.2.7",
"symplify\/skipper": "<10.2.7",
"symplify\/smart-file-system": "<10.2.7",
"symplify\/symfony-static-dumper": "<10.2.7",
"symplify\/git-wrapper": "<10.2.7",
"symplify\/monorepo-builder": "<10.2.7",
"symplify\/config-transformer": "<10.2.7",
"symplify\/easy-ci": "<10.2.7",
"symplify\/coding-standard": "<10.2.7",
"symplify\/latte-phpstan-compiler": "<10.2.2",
"symplify\/template-phpstan-compiler": "<10.2.2",
"symplify\/phpstan-latte-rules": "<10.2.2",
"symplify\/easy-parallel": "<10.2.7",
"symplify\/neon-config-dumper": "<10.2.7"
},
"minimum-stability": "dev",
"prefer-stable": true
}

View File

@ -1,26 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix20220530;
use RectorPrefix20220530\SebastianBergmann\Diff\Differ;
use RectorPrefix20220530\SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder;
use RectorPrefix20220530\Symfony\Component\Console\Application;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use RectorPrefix20220530\Symplify\PackageBuilder\Composer\VendorDirProvider;
use RectorPrefix20220530\Symplify\PackageBuilder\Yaml\ParametersMerger;
use RectorPrefix20220530\Symplify\SmartFileSystem\Json\JsonFileSystem;
use RectorPrefix20220530\Symplify\VendorPatches\Console\VendorPatchesApplication;
use function RectorPrefix20220530\Symfony\Component\DependencyInjection\Loader\Configurator\service;
return static function (\Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator $containerConfigurator) : void {
$services = $containerConfigurator->services();
$services->defaults()->public()->autowire()->autoconfigure();
$services->load('RectorPrefix20220530\Symplify\\VendorPatches\\', __DIR__ . '/../src')->exclude([__DIR__ . '/../src/Kernel', __DIR__ . '/../src/ValueObject']);
$services->set(\RectorPrefix20220530\SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder::class)->args(['$addLineNumbers' => \true]);
$services->set(\RectorPrefix20220530\SebastianBergmann\Diff\Differ::class)->args(['$outputBuilder' => \RectorPrefix20220530\Symfony\Component\DependencyInjection\Loader\Configurator\service(\RectorPrefix20220530\SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder::class)]);
$services->set(\RectorPrefix20220530\Symplify\PackageBuilder\Composer\VendorDirProvider::class);
$services->set(\RectorPrefix20220530\Symplify\SmartFileSystem\Json\JsonFileSystem::class);
// for autowired commands
$services->alias(\RectorPrefix20220530\Symfony\Component\Console\Application::class, \RectorPrefix20220530\Symplify\VendorPatches\Console\VendorPatchesApplication::class);
$services->set(\RectorPrefix20220530\Symplify\PackageBuilder\Yaml\ParametersMerger::class);
};

View File

@ -1,13 +0,0 @@
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
verbose="true"
>
<testsuites>
<testsuite name="unit">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>

View File

@ -1,93 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix20220530\Symplify\VendorPatches\Command;
use RectorPrefix20220530\Symfony\Component\Console\Input\InputInterface;
use RectorPrefix20220530\Symfony\Component\Console\Output\OutputInterface;
use RectorPrefix20220530\Symplify\PackageBuilder\Composer\VendorDirProvider;
use RectorPrefix20220530\Symplify\PackageBuilder\Console\Command\AbstractSymplifyCommand;
use RectorPrefix20220530\Symplify\PackageBuilder\Console\Command\CommandNaming;
use RectorPrefix20220530\Symplify\VendorPatches\Composer\ComposerPatchesConfigurationUpdater;
use RectorPrefix20220530\Symplify\VendorPatches\Console\GenerateCommandReporter;
use RectorPrefix20220530\Symplify\VendorPatches\Differ\PatchDiffer;
use RectorPrefix20220530\Symplify\VendorPatches\Finder\OldToNewFilesFinder;
use RectorPrefix20220530\Symplify\VendorPatches\PatchFileFactory;
final class GenerateCommand extends \RectorPrefix20220530\Symplify\PackageBuilder\Console\Command\AbstractSymplifyCommand
{
/**
* @var \Symplify\VendorPatches\Finder\OldToNewFilesFinder
*/
private $oldToNewFilesFinder;
/**
* @var \Symplify\VendorPatches\Differ\PatchDiffer
*/
private $patchDiffer;
/**
* @var \Symplify\VendorPatches\Composer\ComposerPatchesConfigurationUpdater
*/
private $composerPatchesConfigurationUpdater;
/**
* @var \Symplify\PackageBuilder\Composer\VendorDirProvider
*/
private $vendorDirProvider;
/**
* @var \Symplify\VendorPatches\PatchFileFactory
*/
private $patchFileFactory;
/**
* @var \Symplify\VendorPatches\Console\GenerateCommandReporter
*/
private $generateCommandReporter;
public function __construct(\RectorPrefix20220530\Symplify\VendorPatches\Finder\OldToNewFilesFinder $oldToNewFilesFinder, \RectorPrefix20220530\Symplify\VendorPatches\Differ\PatchDiffer $patchDiffer, \RectorPrefix20220530\Symplify\VendorPatches\Composer\ComposerPatchesConfigurationUpdater $composerPatchesConfigurationUpdater, \RectorPrefix20220530\Symplify\PackageBuilder\Composer\VendorDirProvider $vendorDirProvider, \RectorPrefix20220530\Symplify\VendorPatches\PatchFileFactory $patchFileFactory, \RectorPrefix20220530\Symplify\VendorPatches\Console\GenerateCommandReporter $generateCommandReporter)
{
$this->oldToNewFilesFinder = $oldToNewFilesFinder;
$this->patchDiffer = $patchDiffer;
$this->composerPatchesConfigurationUpdater = $composerPatchesConfigurationUpdater;
$this->vendorDirProvider = $vendorDirProvider;
$this->patchFileFactory = $patchFileFactory;
$this->generateCommandReporter = $generateCommandReporter;
parent::__construct();
}
protected function configure() : void
{
$this->setName(\RectorPrefix20220530\Symplify\PackageBuilder\Console\Command\CommandNaming::classToName(self::class));
$this->setDescription('Generate patches from /vendor directory');
}
protected function execute(\RectorPrefix20220530\Symfony\Component\Console\Input\InputInterface $input, \RectorPrefix20220530\Symfony\Component\Console\Output\OutputInterface $output) : int
{
$vendorDirectory = $this->vendorDirProvider->provide();
$oldAndNewFileInfos = $this->oldToNewFilesFinder->find($vendorDirectory);
$composerExtraPatches = [];
$addedPatchFilesByPackageName = [];
foreach ($oldAndNewFileInfos as $oldAndNewFileInfo) {
if ($oldAndNewFileInfo->isContentIdentical()) {
$this->generateCommandReporter->reportIdenticalNewAndOldFile($oldAndNewFileInfo);
continue;
}
// write into patches file
$patchFileRelativePath = $this->patchFileFactory->createPatchFilePath($oldAndNewFileInfo, $vendorDirectory);
$composerExtraPatches[$oldAndNewFileInfo->getPackageName()][] = $patchFileRelativePath;
$patchFileAbsolutePath = \dirname($vendorDirectory) . \DIRECTORY_SEPARATOR . $patchFileRelativePath;
// dump the patch
$patchDiff = $this->patchDiffer->diff($oldAndNewFileInfo);
if (\is_file($patchFileAbsolutePath)) {
$message = \sprintf('File "%s" was updated', $patchFileRelativePath);
$this->symfonyStyle->note($message);
} else {
$message = \sprintf('File "%s" was created', $patchFileRelativePath);
$this->symfonyStyle->note($message);
}
$this->smartFileSystem->dumpFile($patchFileAbsolutePath, $patchDiff);
$addedPatchFilesByPackageName[$oldAndNewFileInfo->getPackageName()][] = $patchFileRelativePath;
}
$this->composerPatchesConfigurationUpdater->updateComposerJsonAndPrint(\getcwd() . '/composer.json', $composerExtraPatches);
if ($addedPatchFilesByPackageName !== []) {
$message = \sprintf('Great! %d new patch files added', \count($addedPatchFilesByPackageName));
$this->symfonyStyle->success($message);
} else {
$this->symfonyStyle->success('No new patches were added');
}
return self::SUCCESS;
}
}

View File

@ -1,59 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix20220530\Symplify\VendorPatches\Composer;
use RectorPrefix20220530\Symplify\Astral\Exception\ShouldNotHappenException;
use RectorPrefix20220530\Symplify\ComposerJsonManipulator\ComposerJsonFactory;
use RectorPrefix20220530\Symplify\ComposerJsonManipulator\FileSystem\JsonFileManager;
use RectorPrefix20220530\Symplify\ComposerJsonManipulator\ValueObject\ComposerJson;
use RectorPrefix20220530\Symplify\PackageBuilder\Yaml\ParametersMerger;
use Symplify\SmartFileSystem\SmartFileInfo;
/**
* @see \Symplify\VendorPatches\Tests\Composer\ComposerPatchesConfigurationUpdater\ComposerPatchesConfigurationUpdaterTest
*/
final class ComposerPatchesConfigurationUpdater
{
/**
* @var \Symplify\ComposerJsonManipulator\ComposerJsonFactory
*/
private $composerJsonFactory;
/**
* @var \Symplify\ComposerJsonManipulator\FileSystem\JsonFileManager
*/
private $jsonFileManager;
/**
* @var \Symplify\PackageBuilder\Yaml\ParametersMerger
*/
private $parametersMerger;
public function __construct(\RectorPrefix20220530\Symplify\ComposerJsonManipulator\ComposerJsonFactory $composerJsonFactory, \RectorPrefix20220530\Symplify\ComposerJsonManipulator\FileSystem\JsonFileManager $jsonFileManager, \RectorPrefix20220530\Symplify\PackageBuilder\Yaml\ParametersMerger $parametersMerger)
{
$this->composerJsonFactory = $composerJsonFactory;
$this->jsonFileManager = $jsonFileManager;
$this->parametersMerger = $parametersMerger;
}
/**
* @param mixed[] $composerExtraPatches
*/
public function updateComposerJson(string $composerJsonFilePath, array $composerExtraPatches) : \RectorPrefix20220530\Symplify\ComposerJsonManipulator\ValueObject\ComposerJson
{
$extra = ['patches' => $composerExtraPatches];
$composerJson = $this->composerJsonFactory->createFromFilePath($composerJsonFilePath);
// merge "extra" section - deep merge is needed, so original patches are included
$newExtra = $this->parametersMerger->merge($composerJson->getExtra(), $extra);
$composerJson->setExtra($newExtra);
return $composerJson;
}
/**
* @param mixed[] $composerExtraPatches
*/
public function updateComposerJsonAndPrint(string $composerJsonFilePath, array $composerExtraPatches) : void
{
$composerJson = $this->updateComposerJson($composerJsonFilePath, $composerExtraPatches);
$fileInfo = $composerJson->getFileInfo();
if (!$fileInfo instanceof \Symplify\SmartFileSystem\SmartFileInfo) {
throw new \RectorPrefix20220530\Symplify\Astral\Exception\ShouldNotHappenException();
}
$this->jsonFileManager->printComposerJsonToFilePath($composerJson, $fileInfo->getRealPath());
}
}

View File

@ -1,50 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix20220530\Symplify\VendorPatches\Composer;
use RectorPrefix20220530\Symplify\SmartFileSystem\FileSystemGuard;
use RectorPrefix20220530\Symplify\SmartFileSystem\Json\JsonFileSystem;
use Symplify\SmartFileSystem\SmartFileInfo;
use RectorPrefix20220530\Symplify\SymplifyKernel\Exception\ShouldNotHappenException;
use RectorPrefix20220530\Symplify\VendorPatches\FileSystem\PathResolver;
/**
* @see \Symplify\VendorPatches\Tests\Composer\PackageNameResolverTest
*/
final class PackageNameResolver
{
/**
* @var \Symplify\SmartFileSystem\Json\JsonFileSystem
*/
private $jsonFileSystem;
/**
* @var \Symplify\VendorPatches\FileSystem\PathResolver
*/
private $pathResolver;
/**
* @var \Symplify\SmartFileSystem\FileSystemGuard
*/
private $fileSystemGuard;
public function __construct(\RectorPrefix20220530\Symplify\SmartFileSystem\Json\JsonFileSystem $jsonFileSystem, \RectorPrefix20220530\Symplify\VendorPatches\FileSystem\PathResolver $pathResolver, \RectorPrefix20220530\Symplify\SmartFileSystem\FileSystemGuard $fileSystemGuard)
{
$this->jsonFileSystem = $jsonFileSystem;
$this->pathResolver = $pathResolver;
$this->fileSystemGuard = $fileSystemGuard;
}
public function resolveFromFileInfo(\Symplify\SmartFileSystem\SmartFileInfo $vendorFile) : string
{
$packageComposerJsonFilePath = $this->getPackageComposerJsonFilePath($vendorFile);
$composerJson = $this->jsonFileSystem->loadFilePathToJson($packageComposerJsonFilePath);
if (!isset($composerJson['name'])) {
throw new \RectorPrefix20220530\Symplify\SymplifyKernel\Exception\ShouldNotHappenException();
}
return $composerJson['name'];
}
private function getPackageComposerJsonFilePath(\Symplify\SmartFileSystem\SmartFileInfo $vendorFileInfo) : string
{
$vendorPackageDirectory = $this->pathResolver->resolveVendorDirectory($vendorFileInfo);
$packageComposerJsonFilePath = $vendorPackageDirectory . '/composer.json';
$this->fileSystemGuard->ensureFileExists($packageComposerJsonFilePath, __METHOD__);
return $packageComposerJsonFilePath;
}
}

View File

@ -1,23 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix20220530\Symplify\VendorPatches\Console;
use RectorPrefix20220530\Symfony\Component\Console\Style\SymfonyStyle;
use RectorPrefix20220530\Symplify\VendorPatches\ValueObject\OldAndNewFileInfo;
final class GenerateCommandReporter
{
/**
* @var \Symfony\Component\Console\Style\SymfonyStyle
*/
private $symfonyStyle;
public function __construct(\RectorPrefix20220530\Symfony\Component\Console\Style\SymfonyStyle $symfonyStyle)
{
$this->symfonyStyle = $symfonyStyle;
}
public function reportIdenticalNewAndOldFile(\RectorPrefix20220530\Symplify\VendorPatches\ValueObject\OldAndNewFileInfo $oldAndNewFileInfo) : void
{
$message = \sprintf('Files "%s" and "%s" have the same content. Did you forgot to change it?', $oldAndNewFileInfo->getOldFileRelativePath(), $oldAndNewFileInfo->getNewFileRelativePath());
$this->symfonyStyle->warning($message);
}
}

View File

@ -1,18 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix20220530\Symplify\VendorPatches\Console;
use RectorPrefix20220530\Symfony\Component\Console\Application;
use RectorPrefix20220530\Symfony\Component\Console\Command\Command;
final class VendorPatchesApplication extends \RectorPrefix20220530\Symfony\Component\Console\Application
{
/**
* @param Command[] $commands
*/
public function __construct(array $commands)
{
$this->addCommands($commands);
parent::__construct();
}
}

View File

@ -1,56 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix20220530\Symplify\VendorPatches\Differ;
use RectorPrefix20220530\Nette\Utils\Strings;
use RectorPrefix20220530\SebastianBergmann\Diff\Differ;
use Symplify\SmartFileSystem\SmartFileInfo;
use RectorPrefix20220530\Symplify\SymplifyKernel\Exception\ShouldNotHappenException;
use RectorPrefix20220530\Symplify\VendorPatches\ValueObject\OldAndNewFileInfo;
/**
* @see \Symplify\VendorPatches\Tests\Differ\PatchDifferTest
*/
final class PatchDiffer
{
/**
* @see https://regex101.com/r/0O5NO1/4
* @var string
*/
private const LOCAL_PATH_REGEX = '#vendor\\/[^\\/]+\\/[^\\/]+\\/(?<local_path>.*?)$#is';
/**
* @see https://regex101.com/r/vNa7PO/1
* @var string
*/
private const START_ORIGINAL_REGEX = '#^--- Original#';
/**
* @see https://regex101.com/r/o8C90E/1
* @var string
*/
private const START_NEW_REGEX = '#^\\+\\+\\+ New#m';
/**
* @var \SebastianBergmann\Diff\Differ
*/
private $differ;
public function __construct(\RectorPrefix20220530\SebastianBergmann\Diff\Differ $differ)
{
$this->differ = $differ;
}
public function diff(\RectorPrefix20220530\Symplify\VendorPatches\ValueObject\OldAndNewFileInfo $oldAndNewFileInfo) : string
{
$oldFileInfo = $oldAndNewFileInfo->getOldFileInfo();
$newFileInfo = $oldAndNewFileInfo->getNewFileInfo();
$diff = $this->differ->diff($oldFileInfo->getContents(), $newFileInfo->getContents());
$patchedFileRelativePath = $this->resolveFileInfoPathRelativeFilePath($newFileInfo);
$clearedDiff = \RectorPrefix20220530\Nette\Utils\Strings::replace($diff, self::START_ORIGINAL_REGEX, '--- /dev/null');
return \RectorPrefix20220530\Nette\Utils\Strings::replace($clearedDiff, self::START_NEW_REGEX, '+++ ' . $patchedFileRelativePath);
}
private function resolveFileInfoPathRelativeFilePath(\Symplify\SmartFileSystem\SmartFileInfo $beforeFileInfo) : string
{
$match = \RectorPrefix20220530\Nette\Utils\Strings::match($beforeFileInfo->getRealPath(), self::LOCAL_PATH_REGEX);
if (!isset($match['local_path'])) {
throw new \RectorPrefix20220530\Symplify\SymplifyKernel\Exception\ShouldNotHappenException();
}
return '../' . $match['local_path'];
}
}

View File

@ -1,24 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix20220530\Symplify\VendorPatches\FileSystem;
use RectorPrefix20220530\Nette\Utils\Strings;
use Symplify\SmartFileSystem\SmartFileInfo;
use RectorPrefix20220530\Symplify\SymplifyKernel\Exception\ShouldNotHappenException;
final class PathResolver
{
/**
* @see https://regex101.com/r/KhzCSu/1
* @var string
*/
private const VENDOR_PACKAGE_DIRECTORY_REGEX = '#^(?<vendor_package_directory>.*?vendor\\/(\\w|\\.|\\-)+\\/(\\w|\\.|\\-)+)\\/#si';
public function resolveVendorDirectory(\Symplify\SmartFileSystem\SmartFileInfo $fileInfo) : string
{
$match = \RectorPrefix20220530\Nette\Utils\Strings::match($fileInfo->getRealPath(), self::VENDOR_PACKAGE_DIRECTORY_REGEX);
if (!isset($match['vendor_package_directory'])) {
throw new \RectorPrefix20220530\Symplify\SymplifyKernel\Exception\ShouldNotHappenException('Could not resolve vendor package directory');
}
return $match['vendor_package_directory'];
}
}

View File

@ -1,57 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix20220530\Symplify\VendorPatches\Finder;
use RectorPrefix20220530\Symfony\Component\Finder\Finder;
use RectorPrefix20220530\Symplify\SmartFileSystem\Finder\FinderSanitizer;
use Symplify\SmartFileSystem\SmartFileInfo;
use RectorPrefix20220530\Symplify\VendorPatches\Composer\PackageNameResolver;
use RectorPrefix20220530\Symplify\VendorPatches\ValueObject\OldAndNewFileInfo;
final class OldToNewFilesFinder
{
/**
* @var \Symplify\SmartFileSystem\Finder\FinderSanitizer
*/
private $finderSanitizer;
/**
* @var \Symplify\VendorPatches\Composer\PackageNameResolver
*/
private $packageNameResolver;
public function __construct(\RectorPrefix20220530\Symplify\SmartFileSystem\Finder\FinderSanitizer $finderSanitizer, \RectorPrefix20220530\Symplify\VendorPatches\Composer\PackageNameResolver $packageNameResolver)
{
$this->finderSanitizer = $finderSanitizer;
$this->packageNameResolver = $packageNameResolver;
}
/**
* @return OldAndNewFileInfo[]
*/
public function find(string $directory) : array
{
$oldAndNewFileInfos = [];
$oldFileInfos = $this->findSmartFileInfosInDirectory($directory);
foreach ($oldFileInfos as $oldFileInfo) {
$oldRealPath = $oldFileInfo->getRealPath();
$oldStrrPos = (int) \strrpos($oldRealPath, '.old');
if (\strlen($oldRealPath) - $oldStrrPos !== 4) {
continue;
}
$newFilePath = \substr($oldRealPath, 0, $oldStrrPos);
if (!\file_exists($newFilePath)) {
continue;
}
$newFileInfo = new \Symplify\SmartFileSystem\SmartFileInfo($newFilePath);
$packageName = $this->packageNameResolver->resolveFromFileInfo($newFileInfo);
$oldAndNewFileInfos[] = new \RectorPrefix20220530\Symplify\VendorPatches\ValueObject\OldAndNewFileInfo($oldFileInfo, $newFileInfo, $packageName);
}
return $oldAndNewFileInfos;
}
/**
* @return SmartFileInfo[]
*/
private function findSmartFileInfosInDirectory(string $directory) : array
{
$finder = \RectorPrefix20220530\Symfony\Component\Finder\Finder::create()->in($directory)->files()->exclude('composer/')->exclude('ocramius/')->name('*.old');
return $this->finderSanitizer->sanitize($finder);
}
}

View File

@ -1,20 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix20220530\Symplify\VendorPatches\Kernel;
use RectorPrefix20220530\Psr\Container\ContainerInterface;
use RectorPrefix20220530\Symplify\ComposerJsonManipulator\ValueObject\ComposerJsonManipulatorConfig;
use RectorPrefix20220530\Symplify\SymplifyKernel\HttpKernel\AbstractSymplifyKernel;
final class VendorPatchesKernel extends \RectorPrefix20220530\Symplify\SymplifyKernel\HttpKernel\AbstractSymplifyKernel
{
/**
* @param string[] $configFiles
*/
public function createFromConfigs(array $configFiles) : \RectorPrefix20220530\Psr\Container\ContainerInterface
{
$configFiles[] = __DIR__ . '/../../config/config.php';
$configFiles[] = \RectorPrefix20220530\Symplify\ComposerJsonManipulator\ValueObject\ComposerJsonManipulatorConfig::FILE_PATH;
return $this->create($configFiles);
}
}

View File

@ -1,18 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix20220530\Symplify\VendorPatches;
use RectorPrefix20220530\Nette\Utils\Strings;
use RectorPrefix20220530\Symplify\VendorPatches\ValueObject\OldAndNewFileInfo;
final class PatchFileFactory
{
public function createPatchFilePath(\RectorPrefix20220530\Symplify\VendorPatches\ValueObject\OldAndNewFileInfo $oldAndNewFileInfo, string $vendorDirectory) : string
{
$newFileInfo = $oldAndNewFileInfo->getNewFileInfo();
$inVendorRelativeFilePath = $newFileInfo->getRelativeFilePathFromDirectory($vendorDirectory);
$relativeFilePathWithoutSuffix = \RectorPrefix20220530\Nette\Utils\Strings::lower($inVendorRelativeFilePath);
$pathFileName = \RectorPrefix20220530\Nette\Utils\Strings::webalize($relativeFilePathWithoutSuffix) . '.patch';
return 'patches' . \DIRECTORY_SEPARATOR . $pathFileName;
}
}

View File

@ -1,51 +0,0 @@
<?php
declare (strict_types=1);
namespace RectorPrefix20220530\Symplify\VendorPatches\ValueObject;
use Symplify\SmartFileSystem\SmartFileInfo;
final class OldAndNewFileInfo
{
/**
* @var \Symplify\SmartFileSystem\SmartFileInfo
*/
private $oldFileInfo;
/**
* @var \Symplify\SmartFileSystem\SmartFileInfo
*/
private $newFileInfo;
/**
* @var string
*/
private $packageName;
public function __construct(\Symplify\SmartFileSystem\SmartFileInfo $oldFileInfo, \Symplify\SmartFileSystem\SmartFileInfo $newFileInfo, string $packageName)
{
$this->oldFileInfo = $oldFileInfo;
$this->newFileInfo = $newFileInfo;
$this->packageName = $packageName;
}
public function getOldFileInfo() : \Symplify\SmartFileSystem\SmartFileInfo
{
return $this->oldFileInfo;
}
public function getOldFileRelativePath() : string
{
return $this->oldFileInfo->getRelativeFilePathFromCwd();
}
public function getNewFileRelativePath() : string
{
return $this->newFileInfo->getRelativeFilePathFromCwd();
}
public function getNewFileInfo() : \Symplify\SmartFileSystem\SmartFileInfo
{
return $this->newFileInfo;
}
public function isContentIdentical() : bool
{
return $this->newFileInfo->getContents() === $this->oldFileInfo->getContents();
}
public function getPackageName() : string
{
return $this->packageName;
}
}