Updated Rector to commit 4db20ca6d5c2106a71d6c7113889f263aa379904

4db20ca6d5 [Console] Allow https url instead of git:// on SetupCICommand (#3799)
This commit is contained in:
Tomas Votruba 2023-05-11 15:16:47 +00:00
parent e947b0aeed
commit e241ac1961
10 changed files with 21 additions and 274 deletions

View File

@ -20,7 +20,6 @@ use Rector\CodingStyle\Rector\Encapsed\WrapEncapsedVariableInCurlyBracesRector;
use Rector\CodingStyle\Rector\FuncCall\CallUserFuncArrayToVariadicRector;
use Rector\CodingStyle\Rector\FuncCall\CallUserFuncToMethodCallRector;
use Rector\CodingStyle\Rector\FuncCall\ConsistentImplodeRector;
use Rector\CodingStyle\Rector\FuncCall\ConsistentPregDelimiterRector;
use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector;
use Rector\CodingStyle\Rector\FuncCall\StrictArraySearchRector;
use Rector\CodingStyle\Rector\FuncCall\VersionCompareFuncCallToConstantRector;
@ -40,5 +39,5 @@ use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Rector\Transform\Rector\FuncCall\FuncCallToConstFetchRector;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->ruleWithConfiguration(FuncCallToConstFetchRector::class, ['php_sapi_name' => 'PHP_SAPI', 'pi' => 'M_PI']);
$rectorConfig->rules([SeparateMultiUseImportsRector::class, PostIncDecToPreIncDecRector::class, UnSpreadOperatorRector::class, NewlineAfterStatementRector::class, RemoveFinalFromConstRector::class, NullableCompareToNullRector::class, BinarySwitchToIfElseRector::class, ConsistentImplodeRector::class, TernaryConditionVariableAssignmentRector::class, SymplifyQuoteEscapeRector::class, StringClassNameToClassConstantRector::class, ConsistentPregDelimiterRector::class, CatchExceptionNameMatchingTypeRector::class, UseIncrementAssignRector::class, SplitDoubleAssignRector::class, VarConstantCommentRector::class, EncapsedStringsToSprintfRector::class, WrapEncapsedVariableInCurlyBracesRector::class, NewlineBeforeNewAssignSetRector::class, AddArrayDefaultToArrayPropertyRector::class, AddFalseDefaultToBoolPropertyRector::class, MakeInheritedMethodVisibilitySameAsParentRector::class, CallUserFuncArrayToVariadicRector::class, VersionCompareFuncCallToConstantRector::class, StaticArrowFunctionRector::class, StaticClosureRector::class, CountArrayToEmptyArrayComparisonRector::class, CallUserFuncToMethodCallRector::class, FuncGetArgsToVariadicParamRector::class, StrictArraySearchRector::class, UseClassKeywordForClassNameResolutionRector::class, SplitGroupedPropertiesRector::class, SplitGroupedClassConstantsRector::class]);
$rectorConfig->rules([SeparateMultiUseImportsRector::class, PostIncDecToPreIncDecRector::class, UnSpreadOperatorRector::class, NewlineAfterStatementRector::class, RemoveFinalFromConstRector::class, NullableCompareToNullRector::class, BinarySwitchToIfElseRector::class, ConsistentImplodeRector::class, TernaryConditionVariableAssignmentRector::class, SymplifyQuoteEscapeRector::class, StringClassNameToClassConstantRector::class, CatchExceptionNameMatchingTypeRector::class, UseIncrementAssignRector::class, SplitDoubleAssignRector::class, VarConstantCommentRector::class, EncapsedStringsToSprintfRector::class, WrapEncapsedVariableInCurlyBracesRector::class, NewlineBeforeNewAssignSetRector::class, AddArrayDefaultToArrayPropertyRector::class, AddFalseDefaultToBoolPropertyRector::class, MakeInheritedMethodVisibilitySameAsParentRector::class, CallUserFuncArrayToVariadicRector::class, VersionCompareFuncCallToConstantRector::class, StaticArrowFunctionRector::class, StaticClosureRector::class, CountArrayToEmptyArrayComparisonRector::class, CallUserFuncToMethodCallRector::class, FuncGetArgsToVariadicParamRector::class, StrictArraySearchRector::class, UseClassKeywordForClassNameResolutionRector::class, SplitGroupedPropertiesRector::class, SplitGroupedClassConstantsRector::class]);
};

View File

@ -1,4 +1,4 @@
# 412 Rules Overview
# 411 Rules Overview
<br>
@ -8,7 +8,7 @@
- [CodeQuality](#codequality) (76)
- [CodingStyle](#codingstyle) (37)
- [CodingStyle](#codingstyle) (36)
- [Compatibility](#compatibility) (1)
@ -1997,46 +1997,6 @@ Changes various implode forms to consistent one
<br>
### ConsistentPregDelimiterRector
Replace PREG delimiter with configured one
:wrench: **configure it!**
- class: [`Rector\CodingStyle\Rector\FuncCall\ConsistentPregDelimiterRector`](../rules/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector.php)
```php
<?php
declare(strict_types=1);
use Rector\CodingStyle\Rector\FuncCall\ConsistentPregDelimiterRector;
use Rector\Config\RectorConfig;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->ruleWithConfiguration(ConsistentPregDelimiterRector::class, [
ConsistentPregDelimiterRector::DELIMITER => '#',
]);
};
```
```diff
class SomeClass
{
public function run()
{
- preg_match('~value~', $value);
- preg_match_all('~value~im', $value);
+ preg_match('#value#', $value);
+ preg_match_all('#value#im', $value);
}
}
```
<br>
### CountArrayToEmptyArrayComparisonRector
Change count array comparison to empty array comparison to improve performance

View File

@ -1,210 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\CodingStyle\Rector\FuncCall;
use RectorPrefix202305\Nette\Utils\Strings;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Scalar\String_;
use PHPStan\Type\ObjectType;
use Rector\Core\Contract\PhpParser\NodePrinterInterface;
use Rector\Core\Contract\Rector\AllowEmptyConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Util\StringUtils;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Tests\CodingStyle\Rector\FuncCall\ConsistentPregDelimiterRector\ConsistentPregDelimiterRectorTest
*/
final class ConsistentPregDelimiterRector extends AbstractRector implements AllowEmptyConfigurableRectorInterface
{
/**
* @api
* @var string
*/
public const DELIMITER = 'delimiter';
/**
* @var string
* @see https://regex101.com/r/isdgEN/1
*
* For modifiers see https://www.php.net/manual/en/reference.pcre.pattern.modifiers.php
*/
private const INNER_REGEX = '#(?<content>.*?)(?<close>[imsxeADSUXJu]*)$#s';
/**
* @var string
* @see https://regex101.com/r/nnuwUo/1
*
* For modifiers see https://www.php.net/manual/en/reference.pcre.pattern.modifiers.php
*/
private const INNER_UNICODE_REGEX = '#(?<content>.*?)(?<close>[imsxeADSUXJu]*)$#u';
/**
* @var string
* @see https://regex101.com/r/KpCzg6/1
*/
private const NEW_LINE_REGEX = '#(\\r|\\n)#';
/**
* @var string
* @see https://regex101.com/r/EyXsV6/6
*/
private const DOUBLE_QUOTED_REGEX = '#^"(?<delimiter>.{1}).{1,}\\k<delimiter>[imsxeADSUXJu]*"$#';
/**
* All with pattern as 1st argument
* @var array<string, int>
*/
private const FUNCTIONS_WITH_REGEX_PATTERN = ['preg_match' => 0, 'preg_replace_callback_array' => 0, 'preg_replace_callback' => 0, 'preg_replace' => 0, 'preg_match_all' => 0, 'preg_split' => 0, 'preg_grep' => 0];
/**
* All with pattern as 2st argument
* @var array<string, array<string, int>>
*/
private const STATIC_METHODS_WITH_REGEX_PATTERN = ['Nette\\Utils\\Strings' => ['match' => 1, 'matchAll' => 1, 'replace' => 1, 'split' => 1]];
/**
* @var string
*/
private $delimiter = '#';
/**
* @readonly
* @var \Rector\Core\Contract\PhpParser\NodePrinterInterface
*/
private $nodePrinter;
public function __construct(NodePrinterInterface $nodePrinter)
{
$this->nodePrinter = $nodePrinter;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Replace PREG delimiter with configured one', [new ConfiguredCodeSample(<<<'CODE_SAMPLE'
class SomeClass
{
public function run()
{
preg_match('~value~', $value);
preg_match_all('~value~im', $value);
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
class SomeClass
{
public function run()
{
preg_match('#value#', $value);
preg_match_all('#value#im', $value);
}
}
CODE_SAMPLE
, [self::DELIMITER => '#'])]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [FuncCall::class, StaticCall::class];
}
/**
* @param FuncCall|StaticCall $node
*/
public function refactor(Node $node) : ?Node
{
if ($node instanceof FuncCall) {
return $this->refactorFuncCall($node);
}
foreach (self::STATIC_METHODS_WITH_REGEX_PATTERN as $type => $methodsToPositions) {
if (!$this->isObjectType($node->class, new ObjectType($type))) {
continue;
}
foreach ($methodsToPositions as $method => $position) {
if (!$this->isName($node->name, $method)) {
continue;
}
if (!$node->args[$position] instanceof Arg) {
continue;
}
return $this->refactorArgument($node, $node->args[$position]);
}
}
return null;
}
public function configure(array $configuration) : void
{
$this->delimiter = $configuration[self::DELIMITER] ?? (string) \current($configuration);
}
private function refactorFuncCall(FuncCall $funcCall) : ?FuncCall
{
foreach (self::FUNCTIONS_WITH_REGEX_PATTERN as $function => $position) {
if (!$this->isName($funcCall, $function)) {
continue;
}
if (!$funcCall->args[$position] instanceof Arg) {
continue;
}
return $this->refactorArgument($funcCall, $funcCall->args[$position]);
}
return null;
}
private function hasNewLineWithUnicodeModifier(string $string) : bool
{
$matchInnerRegex = Strings::match($string, self::INNER_REGEX);
$matchInnerUnionRegex = Strings::match($string, self::INNER_UNICODE_REGEX);
if (!\is_array($matchInnerRegex)) {
return \false;
}
if (!\is_array($matchInnerUnionRegex)) {
return \false;
}
if ($matchInnerRegex === $matchInnerUnionRegex) {
return \false;
}
if (StringUtils::isMatch($matchInnerUnionRegex['content'], self::NEW_LINE_REGEX)) {
return \true;
}
return isset($string[0]) && $matchInnerUnionRegex['content'] === $string[0];
}
private function hasEscapedQuote(String_ $string) : bool
{
$kind = $string->getAttribute(AttributeKey::KIND);
if ($kind === String_::KIND_DOUBLE_QUOTED && \strpos($string->value, '"') !== \false) {
return \true;
}
return $kind === String_::KIND_SINGLE_QUOTED && \strpos($string->value, "'") !== \false;
}
/**
* @param \PhpParser\Node\Expr\FuncCall|\PhpParser\Node\Expr\StaticCall $node
*/
private function refactorArgument($node, Arg $arg) : ?\PhpParser\Node
{
if (!$arg->value instanceof String_) {
return null;
}
/** @var String_ $string */
$string = $arg->value;
if ($this->hasEscapedQuote($string)) {
return null;
}
if ($this->hasNewLineWithUnicodeModifier($string->value)) {
return null;
}
$string->value = Strings::replace($string->value, self::INNER_REGEX, function (array $match) use(&$string) : string {
$printedString = $this->nodePrinter->print($string);
if (StringUtils::isMatch($printedString, self::DOUBLE_QUOTED_REGEX)) {
$string->setAttribute(AttributeKey::IS_REGULAR_PATTERN, \true);
}
$innerPattern = $match['content'];
$positionDelimiter = \strpos($innerPattern, $this->delimiter);
if ($positionDelimiter > 0) {
$innerPattern = \str_replace($this->delimiter, '\\' . $this->delimiter, $innerPattern);
}
// change delimiter
if (\strlen($innerPattern) > 2 && $innerPattern[0] === $innerPattern[\strlen($innerPattern) - 1]) {
$innerPattern[0] = $this->delimiter;
$innerPattern[\strlen($innerPattern) - 1] = $this->delimiter;
}
return $innerPattern . $match['close'];
});
return $node;
}
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '218d1dd561c49e3afbbaa60fa85b6fd327e62dac';
public const PACKAGE_VERSION = '4db20ca6d5c2106a71d6c7113889f263aa379904';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-05-11 14:01:42';
public const RELEASE_DATE = '2023-05-11 22:12:52';
/**
* @var int
*/

View File

@ -19,6 +19,10 @@ use RectorPrefix202305\Webmozart\Assert\Assert;
*/
final class BootstrapFilesIncluder
{
/**
* @var array<string, mixed>
*/
private $configCache = [];
/**
* @readonly
* @var \Rector\Core\Configuration\Parameter\ParameterProvider
@ -34,10 +38,6 @@ final class BootstrapFilesIncluder
$this->parameterProvider = $parameterProvider;
$this->phpStanExtensionsConfigResolver = $phpStanExtensionsConfigResolver;
}
/**
* @var array<string, mixed>
*/
private $configCache = [];
public function includePHPStanExtensionsBoostrapFiles(?Container $container = null) : void
{
$extensionConfigFiles = $this->phpStanExtensionsConfigResolver->resolve();

View File

@ -16,9 +16,9 @@ final class SetupCICommand extends Command
{
/**
* @var string
* @see https://regex101.com/r/etcmog/1
* @see https://regex101.com/r/etcmog/2
*/
private const GITHUB_REPOSITORY_REGEX = '#github\\.com:(?<repository_name>.*?)\\.git#';
private const GITHUB_REPOSITORY_REGEX = '#github\\.com[:\\/](?<repository_name>.*?)\\.git#';
/**
* @readonly
* @var \Symfony\Component\Console\Style\SymfonyStyle

2
vendor/autoload.php vendored
View File

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

View File

@ -1335,7 +1335,6 @@ return array(
'Rector\\CodingStyle\\Rector\\FuncCall\\CallUserFuncArrayToVariadicRector' => $baseDir . '/rules/CodingStyle/Rector/FuncCall/CallUserFuncArrayToVariadicRector.php',
'Rector\\CodingStyle\\Rector\\FuncCall\\CallUserFuncToMethodCallRector' => $baseDir . '/rules/CodingStyle/Rector/FuncCall/CallUserFuncToMethodCallRector.php',
'Rector\\CodingStyle\\Rector\\FuncCall\\ConsistentImplodeRector' => $baseDir . '/rules/CodingStyle/Rector/FuncCall/ConsistentImplodeRector.php',
'Rector\\CodingStyle\\Rector\\FuncCall\\ConsistentPregDelimiterRector' => $baseDir . '/rules/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector.php',
'Rector\\CodingStyle\\Rector\\FuncCall\\CountArrayToEmptyArrayComparisonRector' => $baseDir . '/rules/CodingStyle/Rector/FuncCall/CountArrayToEmptyArrayComparisonRector.php',
'Rector\\CodingStyle\\Rector\\FuncCall\\StrictArraySearchRector' => $baseDir . '/rules/CodingStyle/Rector/FuncCall/StrictArraySearchRector.php',
'Rector\\CodingStyle\\Rector\\FuncCall\\VersionCompareFuncCallToConstantRector' => $baseDir . '/rules/CodingStyle/Rector/FuncCall/VersionCompareFuncCallToConstantRector.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit40418e59bdc73afb732cc1607629746f
class ComposerAutoloaderInitd696f3bbd0fde981a49e4f64111c7d8b
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit40418e59bdc73afb732cc1607629746f
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit40418e59bdc73afb732cc1607629746f', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitd696f3bbd0fde981a49e4f64111c7d8b', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit40418e59bdc73afb732cc1607629746f', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitd696f3bbd0fde981a49e4f64111c7d8b', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit40418e59bdc73afb732cc1607629746f::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitd696f3bbd0fde981a49e4f64111c7d8b::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit40418e59bdc73afb732cc1607629746f::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInitd696f3bbd0fde981a49e4f64111c7d8b::$files;
$requireFile = \Closure::bind(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 ComposerStaticInit40418e59bdc73afb732cc1607629746f
class ComposerStaticInitd696f3bbd0fde981a49e4f64111c7d8b
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -1577,7 +1577,6 @@ class ComposerStaticInit40418e59bdc73afb732cc1607629746f
'Rector\\CodingStyle\\Rector\\FuncCall\\CallUserFuncArrayToVariadicRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/FuncCall/CallUserFuncArrayToVariadicRector.php',
'Rector\\CodingStyle\\Rector\\FuncCall\\CallUserFuncToMethodCallRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/FuncCall/CallUserFuncToMethodCallRector.php',
'Rector\\CodingStyle\\Rector\\FuncCall\\ConsistentImplodeRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/FuncCall/ConsistentImplodeRector.php',
'Rector\\CodingStyle\\Rector\\FuncCall\\ConsistentPregDelimiterRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector.php',
'Rector\\CodingStyle\\Rector\\FuncCall\\CountArrayToEmptyArrayComparisonRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/FuncCall/CountArrayToEmptyArrayComparisonRector.php',
'Rector\\CodingStyle\\Rector\\FuncCall\\StrictArraySearchRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/FuncCall/StrictArraySearchRector.php',
'Rector\\CodingStyle\\Rector\\FuncCall\\VersionCompareFuncCallToConstantRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/FuncCall/VersionCompareFuncCallToConstantRector.php',
@ -3110,9 +3109,9 @@ class ComposerStaticInit40418e59bdc73afb732cc1607629746f
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit40418e59bdc73afb732cc1607629746f::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit40418e59bdc73afb732cc1607629746f::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit40418e59bdc73afb732cc1607629746f::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitd696f3bbd0fde981a49e4f64111c7d8b::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitd696f3bbd0fde981a49e4f64111c7d8b::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitd696f3bbd0fde981a49e4f64111c7d8b::$classMap;
}, null, ClassLoader::class);
}