Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion rules/CodingStyle/Rector/FuncCall/StrictInArrayRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,14 @@ public function refactor(Node $node): ?Node
return null;
}

$firstArgType = $this->nodeTypeResolver->getNativeType($args[0]->value);
$secondArgType = $this->nodeTypeResolver->getNativeType($args[1]->value);

if (! $secondArgType->isArray()->yes()) {
return null;
}

$firstArgType = $this->nodeTypeResolver->getNativeType($args[0]->value);

if ($this->typeComparator->isSubtype($secondArgType->getIterableValueType(), $firstArgType)) {
$node->args[] = new Arg($this->nodeFactory->createTrue());
return $node;
Expand Down
10 changes: 8 additions & 2 deletions rules/CodingStyle/Rector/String_/SimplifyQuoteEscapeRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,18 @@ public function refactor(Node $node): ?String_
{
$this->hasChanged = false;

$doubleQuoteCount = substr_count($node->value, '"');
$singleQuoteCount = substr_count($node->value, "'");

// no quotes to simplify
if ($doubleQuoteCount === 0 && $singleQuoteCount === 0) {
return null;
}

if ($this->hasNonPrintableChars($node->value)) {
return null;
}

$doubleQuoteCount = substr_count($node->value, '"');
$singleQuoteCount = substr_count($node->value, "'");
$kind = $node->getAttribute(AttributeKey::KIND);

if ($kind === String_::KIND_SINGLE_QUOTED) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public function refactor(Node $node): ?Node
}

$classNames = $this->getExistingClasses($node);
$classNames = $this->filterOurShortClasses($classNames);

if ($classNames === []) {
return null;
Expand Down Expand Up @@ -111,6 +110,11 @@ private function getExistingClasses(String_ $string): array
$classNames = [];

foreach ($matches['class_name'] as $matchedClassName) {
// short, non-namespaced names are not resolved to a ::class constant
if (! str_contains($matchedClassName, '\\')) {
continue;
}

if (! $this->reflectionProvider->hasClass($matchedClassName)) {
continue;
}
Expand Down Expand Up @@ -138,13 +142,4 @@ private function createExpressionsToConcat(array $parts): array

return $exprsToConcat;
}

/**
* @param string[] $classNames
* @return string[]
*/
private function filterOurShortClasses(array $classNames): array
{
return array_filter($classNames, static fn (string $className): bool => str_contains($className, '\\'));
}
}
Loading