diff --git a/build/target-repository/docs/rector_rules_overview.md b/build/target-repository/docs/rector_rules_overview.md
index 9f1614133a7..ee4f24c21b0 100644
--- a/build/target-repository/docs/rector_rules_overview.md
+++ b/build/target-repository/docs/rector_rules_overview.md
@@ -1,4 +1,4 @@
-# 412 Rules Overview
+# 411 Rules Overview
@@ -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
-### ConsistentPregDelimiterRector
-
-Replace PREG delimiter with configured one
-
-:wrench: **configure it!**
-
-- class: [`Rector\CodingStyle\Rector\FuncCall\ConsistentPregDelimiterRector`](../rules/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector.php)
-
-```php
-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);
- }
- }
-```
-
-
-
### CountArrayToEmptyArrayComparisonRector
Change count array comparison to empty array comparison to improve performance
diff --git a/config/set/coding-style.php b/config/set/coding-style.php
index b3c590c2574..e62c655394b 100644
--- a/config/set/coding-style.php
+++ b/config/set/coding-style.php
@@ -19,7 +19,6 @@
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;
@@ -57,7 +56,6 @@
TernaryConditionVariableAssignmentRector::class,
SymplifyQuoteEscapeRector::class,
StringClassNameToClassConstantRector::class,
- ConsistentPregDelimiterRector::class,
CatchExceptionNameMatchingTypeRector::class,
UseIncrementAssignRector::class,
SplitDoubleAssignRector::class,
diff --git a/rules-tests/CodeQuality/Rector/Class_/CompleteDynamicPropertiesRector/Fixture/skip_anonymous_class.php b/rules-tests/CodeQuality/Rector/Class_/CompleteDynamicPropertiesRector/Fixture/skip_anonymous_class.php
new file mode 100644
index 00000000000..76bab72d64a
--- /dev/null
+++ b/rules-tests/CodeQuality/Rector/Class_/CompleteDynamicPropertiesRector/Fixture/skip_anonymous_class.php
@@ -0,0 +1,49 @@
+addVisitor($this->createNodeVisitor($callable));
+ $nodeTraverser->traverse($nodes);
+ }
+
+ private function createNodeVisitor(callable $callable): NodeVisitor
+ {
+ return new class($callable) extends NodeVisitorAbstract {
+ /**
+ * @var callable
+ */
+ private $callable;
+
+ public function __construct(callable $callable)
+ {
+ $this->callable = $callable;
+ }
+
+ /**
+ * @return int|Node|null
+ */
+ public function enterNode(Node $node)
+ {
+ $callable = $this->callable;
+ return $callable($node);
+ }
+ };
+ }
+}
diff --git a/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/ConsistentPregDelimiterRectorTest.php b/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/ConsistentPregDelimiterRectorTest.php
deleted file mode 100644
index 1013390c8e0..00000000000
--- a/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/ConsistentPregDelimiterRectorTest.php
+++ /dev/null
@@ -1,28 +0,0 @@
-doTestFile($filePath);
- }
-
- public static function provideData(): Iterator
- {
- return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
- }
-
- public function provideConfigFilePath(): string
- {
- return __DIR__ . '/config/configured_rule.php';
- }
-}
diff --git a/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/DirectStringConfigTest.php b/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/DirectStringConfigTest.php
deleted file mode 100644
index 695cc87c526..00000000000
--- a/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/DirectStringConfigTest.php
+++ /dev/null
@@ -1,28 +0,0 @@
-doTestFile($filePath);
- }
-
- public static function provideData(): Iterator
- {
- return self::yieldFilesFromDirectory(__DIR__ . '/FixtureDirectStringConfig');
- }
-
- public function provideConfigFilePath(): string
- {
- return __DIR__ . '/config/direct_string_configured_rule.php';
- }
-}
diff --git a/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/Fixture/do_not_escape_expression_and_anchor.php.inc b/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/Fixture/do_not_escape_expression_and_anchor.php.inc
deleted file mode 100644
index 6373a968d98..00000000000
--- a/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/Fixture/do_not_escape_expression_and_anchor.php.inc
+++ /dev/null
@@ -1,29 +0,0 @@
-
------
-
diff --git a/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/Fixture/escape_content_delimiter_in_pattern.php.inc b/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/Fixture/escape_content_delimiter_in_pattern.php.inc
deleted file mode 100644
index 856e1d24944..00000000000
--- a/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/Fixture/escape_content_delimiter_in_pattern.php.inc
+++ /dev/null
@@ -1,27 +0,0 @@
-
------
-
diff --git a/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/Fixture/escape_content_delimiter_in_pattern_multi.php.inc b/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/Fixture/escape_content_delimiter_in_pattern_multi.php.inc
deleted file mode 100644
index 41c6c30ec3c..00000000000
--- a/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/Fixture/escape_content_delimiter_in_pattern_multi.php.inc
+++ /dev/null
@@ -1,27 +0,0 @@
-
------
-
diff --git a/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/Fixture/escape_nette_static_call.php.inc b/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/Fixture/escape_nette_static_call.php.inc
deleted file mode 100644
index 7946ab79703..00000000000
--- a/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/Fixture/escape_nette_static_call.php.inc
+++ /dev/null
@@ -1,31 +0,0 @@
-
------
-
diff --git a/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/Fixture/escaped_dollar_char.php.inc b/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/Fixture/escaped_dollar_char.php.inc
deleted file mode 100644
index 933999dc52d..00000000000
--- a/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/Fixture/escaped_dollar_char.php.inc
+++ /dev/null
@@ -1,27 +0,0 @@
-
------
-
diff --git a/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/Fixture/fixture.php.inc b/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/Fixture/fixture.php.inc
deleted file mode 100644
index ba6bc523bb8..00000000000
--- a/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/Fixture/fixture.php.inc
+++ /dev/null
@@ -1,29 +0,0 @@
-
------
-
diff --git a/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/Fixture/skip_concat.php.inc b/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/Fixture/skip_concat.php.inc
deleted file mode 100644
index 29123449f73..00000000000
--- a/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/Fixture/skip_concat.php.inc
+++ /dev/null
@@ -1,13 +0,0 @@
-
------
-
diff --git a/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/FixtureDirectStringConfig/fixture.php.inc b/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/FixtureDirectStringConfig/fixture.php.inc
deleted file mode 100644
index 6aaaf06f824..00000000000
--- a/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/FixtureDirectStringConfig/fixture.php.inc
+++ /dev/null
@@ -1,29 +0,0 @@
-
------
-
diff --git a/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/config/configured_rule.php b/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/config/configured_rule.php
deleted file mode 100644
index 56f85841f24..00000000000
--- a/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/config/configured_rule.php
+++ /dev/null
@@ -1,10 +0,0 @@
-rule(ConsistentPregDelimiterRector::class);
-};
diff --git a/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/config/direct_string_configured_rule.php b/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/config/direct_string_configured_rule.php
deleted file mode 100644
index 66d69963afe..00000000000
--- a/rules-tests/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector/config/direct_string_configured_rule.php
+++ /dev/null
@@ -1,11 +0,0 @@
-ruleWithConfiguration(ConsistentPregDelimiterRector::class, ['/']);
-};
diff --git a/rules/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector.php b/rules/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector.php
deleted file mode 100644
index 11334d511b3..00000000000
--- a/rules/CodingStyle/Rector/FuncCall/ConsistentPregDelimiterRector.php
+++ /dev/null
@@ -1,265 +0,0 @@
-.*?)(?[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 = '#(?.*?)(?[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 = '#^"(?.{1}).{1,}\k[imsxeADSUXJu]*"$#';
-
- /**
- * All with pattern as 1st argument
- * @var array
- */
- 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>
- */
- private const STATIC_METHODS_WITH_REGEX_PATTERN = [
- 'Nette\Utils\Strings' => [
- 'match' => 1,
- 'matchAll' => 1,
- 'replace' => 1,
- 'split' => 1,
- ],
- ];
-
- private string $delimiter = '#';
-
- public function __construct(
- private readonly NodePrinterInterface $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>
- */
- 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 && str_contains($string->value, '"')) {
- return true;
- }
-
- return $kind === String_::KIND_SINGLE_QUOTED && str_contains($string->value, "'");
- }
-
- private function refactorArgument(FuncCall|StaticCall $node, Arg $arg): Node|null
- {
- 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;
- }
-}
diff --git a/src/Autoloading/BootstrapFilesIncluder.php b/src/Autoloading/BootstrapFilesIncluder.php
index 2995b7bae36..9c0be92637a 100644
--- a/src/Autoloading/BootstrapFilesIncluder.php
+++ b/src/Autoloading/BootstrapFilesIncluder.php
@@ -21,17 +21,17 @@
*/
final class BootstrapFilesIncluder
{
+ /**
+ * @var array
+ */
+ private array $configCache = [];
+
public function __construct(
private readonly ParameterProvider $parameterProvider,
private readonly PHPStanExtensionsConfigResolver $phpStanExtensionsConfigResolver,
) {
}
- /**
- * @var array
- */
- private $configCache = [];
-
public function includePHPStanExtensionsBoostrapFiles(?Container $container = null): void
{
$extensionConfigFiles = $this->phpStanExtensionsConfigResolver->resolve();
@@ -74,13 +74,14 @@ private function resolveAbsoluteBootstrapFilePaths(array $extensionConfigFiles):
$absoluteBootstrapFilePaths = [];
foreach ($extensionConfigFiles as $extensionConfigFile) {
- if (!array_key_exists($extensionConfigFile, $this->configCache)) {
+ if (! array_key_exists($extensionConfigFile, $this->configCache)) {
$extensionConfigContents = Neon::decodeFile($extensionConfigFile);
$this->configCache[$extensionConfigFile] = $extensionConfigContents;
} else {
$extensionConfigContents = $this->configCache[$extensionConfigFile];
}
+
$configDirectory = dirname($extensionConfigFile);
$bootstrapFiles = $extensionConfigContents['parameters']['bootstrapFiles'] ?? [];