Skip to content

Commit

Permalink
Cleanup (#1054)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Oct 24, 2021
1 parent 06ea31c commit 8e2908c
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,6 @@ private function processFqnNameImport(
}

if ($this->shouldImport($newNode, $identifierTypeNode, $fullyQualifiedObjectType)) {
// do not import twice
if ($this->useNodesToAddCollector->isShortImported($file, $fullyQualifiedObjectType)) {
return null;
}

$this->useNodesToAddCollector->addUseImport($fullyQualifiedObjectType);
return $newNode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ private function isArrayDimFetchRead(ArrayDimFetch $arrayDimFetch): bool
}

// the array dim fetch is assing here only; but the variable might be used later
if ($this->readExprAnalyzer->isExprRead($arrayDimFetch->var)) {
return true;
}

return ! $this->assignManipulator->isLeftPartOfAssign($arrayDimFetch);
return $this->readExprAnalyzer->isExprRead($arrayDimFetch->var);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use PHPStan\Type\Constant\ConstantBooleanType;
use PHPStan\Type\ConstantType;
use PHPStan\Type\Type;
use Rector\Core\Exception\NotImplementedYetException;
use PHPStan\Type\VerbosityLevel;
use Rector\Core\Exception\ShouldNotHappenException;

final class DefaultParameterValueResolver
Expand Down Expand Up @@ -76,13 +76,8 @@ private function resolveValueFromType(ConstantType $constantType): ConstFetch |

private function resolveConstantBooleanType(ConstantBooleanType $constantBooleanType): ConstFetch
{
if (! $constantBooleanType->getValue()) {
$name = new Name('false');
} elseif ($constantBooleanType->getValue()) {
$name = new Name('true');
} else {
throw new NotImplementedYetException();
}
$value = $constantBooleanType->describe(VerbosityLevel::value());
$name = new Name($value);

return new ConstFetch($name);
}
Expand Down
4 changes: 0 additions & 4 deletions rules/Php70/Rector/FuncCall/EregToPregMatchRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,6 @@ private function processSplitLimitArgument(FuncCall $funcCall, string $functionN
}

// 3rd argument - $limit, 0 → 1
if (! isset($funcCall->args[2])) {
return;
}

if (! $funcCall->args[2]->value instanceof LNumber) {
return;
}
Expand Down
12 changes: 5 additions & 7 deletions rules/Php70/Rector/Ternary/TernaryToNullCoalescingRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function getNodeTypes(): array
public function refactor(Node $node): ?Node
{
if ($node->cond instanceof Isset_) {
return $this->processTernaryWithIsset($node);
return $this->processTernaryWithIsset($node, $node->cond);
}

if ($node->cond instanceof Identical) {
Expand Down Expand Up @@ -87,24 +87,22 @@ public function provideMinPhpVersion(): int
return PhpVersionFeature::NULL_COALESCE;
}

private function processTernaryWithIsset(Ternary $ternary): ?Coalesce
private function processTernaryWithIsset(Ternary $ternary, Isset_ $isset): ?Coalesce
{
if ($ternary->if === null) {
return null;
}

/** @var Isset_ $issetNode */
$issetNode = $ternary->cond;
// none or multiple isset values cannot be handled here
if (! isset($issetNode->vars[0])) {
if (! isset($isset->vars[0])) {
return null;
}

if (count($issetNode->vars) > 1) {
if (count($isset->vars) > 1) {
return null;
}

if ($this->nodeComparator->areNodesEqual($ternary->if, $issetNode->vars[0])) {
if ($this->nodeComparator->areNodesEqual($ternary->if, $isset->vars[0])) {
return new Coalesce($ternary->if, $ternary->else);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function refactor(Node $node): ?Node
}

$parentClassReflection = $classReflection->getParentClass();
if (! $parentClassReflection) {
if (! $parentClassReflection instanceof ClassReflection) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
final class AttributeKeyToClassConstFetch
{
/**
* @param array<mixed, string> $valuesToConstantsMap
* @param array<string, string> $valuesToConstantsMap
*/
public function __construct(
private string $attributeClass,
Expand Down
4 changes: 0 additions & 4 deletions src/NodeManipulator/ClassMethodAssignManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,6 @@ private function findParentForeach(Assign $assign): ?Foreach_

private function isExplicitlyReferenced(Node $node): bool
{
if (! property_exists($node, 'byRef')) {
return false;
}

if ($node instanceof Arg || $node instanceof ClosureUse || $node instanceof Param) {
return $node->byRef;
}
Expand Down

0 comments on commit 8e2908c

Please sign in to comment.