Skip to content

Commit

Permalink
[DeadCode] Remove RemoveJustVariableAssignRector as often done on pur…
Browse files Browse the repository at this point in the history
…pose or with side effect (#4450)
  • Loading branch information
TomasVotruba committed Jul 9, 2023
1 parent 33019ba commit ce03029
Show file tree
Hide file tree
Showing 17 changed files with 2 additions and 577 deletions.
101 changes: 2 additions & 99 deletions build/target-repository/docs/rector_rules_overview.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 367 Rules Overview
# 362 Rules Overview

<br>

Expand All @@ -10,12 +10,10 @@

- [CodingStyle](#codingstyle) (31)

- [DeadCode](#deadcode) (43)
- [DeadCode](#deadcode) (42)

- [EarlyReturn](#earlyreturn) (10)

- [MysqlToMysqli](#mysqltomysqli) (4)

- [Naming](#naming) (6)

- [Php52](#php52) (2)
Expand Down Expand Up @@ -2730,27 +2728,6 @@ Inline property fetch assign to a variable, that has no added value

<br>

### RemoveJustVariableAssignRector

Remove variable just to assign value or return value

- class: [`Rector\DeadCode\Rector\StmtsAwareInterface\RemoveJustVariableAssignRector`](../rules/DeadCode/Rector/StmtsAwareInterface/RemoveJustVariableAssignRector.php)

```diff
final class SomeClass
{
public function run()
{
- $result = 100;
-
- $this->temporaryValue = $result;
+ $this->temporaryValue = 100;
}
}
```

<br>

### RemoveNonExistingVarAnnotationRector

Removes non-existing `@var` annotations above the code
Expand Down Expand Up @@ -3468,80 +3445,6 @@ Replace if conditioned variable override with direct return

<br>

## MysqlToMysqli

### MysqlAssignToMysqliRector

Converts more complex mysql functions to mysqli

- class: [`Rector\MysqlToMysqli\Rector\Assign\MysqlAssignToMysqliRector`](../rules/MysqlToMysqli/Rector/Assign/MysqlAssignToMysqliRector.php)

```diff
-$data = mysql_db_name($result, $row);
+mysqli_data_seek($result, $row);
+$fetch = mysql_fetch_row($result);
+$data = $fetch[0];
```

<br>

### MysqlFuncCallToMysqliRector

Converts more complex mysql functions to mysqli

- class: [`Rector\MysqlToMysqli\Rector\FuncCall\MysqlFuncCallToMysqliRector`](../rules/MysqlToMysqli/Rector/FuncCall/MysqlFuncCallToMysqliRector.php)

```diff
-mysql_drop_db($database);
+mysqli_query('DROP DATABASE ' . $database);
```

<br>

### MysqlPConnectToMysqliConnectRector

Replace `mysql_pconnect()` with `mysqli_connect()` with host p: prefix

- class: [`Rector\MysqlToMysqli\Rector\FuncCall\MysqlPConnectToMysqliConnectRector`](../rules/MysqlToMysqli/Rector/FuncCall/MysqlPConnectToMysqliConnectRector.php)

```diff
final class SomeClass
{
public function run($host, $username, $password)
{
- return mysql_pconnect($host, $username, $password);
+ return mysqli_connect('p:' . $host, $username, $password);
}
}
```

<br>

### MysqlQueryMysqlErrorWithLinkRector

Add mysql_query and mysql_error with connection

- class: [`Rector\MysqlToMysqli\Rector\FuncCall\MysqlQueryMysqlErrorWithLinkRector`](../rules/MysqlToMysqli/Rector/FuncCall/MysqlQueryMysqlErrorWithLinkRector.php)

```diff
class SomeClass
{
public function run()
{
$conn = mysqli_connect('host', 'user', 'pass');

- mysql_error();
+ mysqli_error($conn);
$sql = 'SELECT';

- return mysql_query($sql);
+ return mysqli_query($conn, $sql);
}
}
```

<br>

## Naming

### RenameForeachValueVariableToMatchExprVariableRector
Expand Down
2 changes: 0 additions & 2 deletions config/set/dead-code.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
use Rector\DeadCode\Rector\StaticCall\RemoveParentCallWithoutParentRector;
use Rector\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector;
use Rector\DeadCode\Rector\StmtsAwareInterface\RemoveJustPropertyFetchForAssignRector;
use Rector\DeadCode\Rector\StmtsAwareInterface\RemoveJustVariableAssignRector;
use Rector\DeadCode\Rector\Switch_\RemoveDuplicatedCaseInSwitchRector;
use Rector\DeadCode\Rector\Ternary\TernaryToBooleanOrFalseToBooleanAndRector;
use Rector\DeadCode\Rector\TryCatch\RemoveDeadTryCatchRector;
Expand Down Expand Up @@ -90,7 +89,6 @@

RemoveUnusedPromotedPropertyRector::class,
RemoveJustPropertyFetchForAssignRector::class,
RemoveJustVariableAssignRector::class,

RemoveAlwaysTrueIfConditionRector::class,
RemoveDeadZeroAndOneOperationRector::class,
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit ce03029

Please sign in to comment.