mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-08 04:10:51 +00:00
hotfix mysql connection resolving (#4399)
This commit is contained in:
parent
a31837679d
commit
cb991af9c6
10
.github/workflows/code_analysis.yaml
vendored
10
.github/workflows/code_analysis.yaml
vendored
|
@ -44,10 +44,12 @@ jobs:
|
|||
run: bin/rector validate-sets --ansi
|
||||
|
||||
-
|
||||
name: 'Validate PHPStan Compatibility'
|
||||
run: |
|
||||
bin/rector sync-types --ansi
|
||||
bin/rector check-static-type-mappers --ansi
|
||||
name: 'Validate PHPStan Types Compatibility'
|
||||
run: bin/rector sync-types --ansi
|
||||
|
||||
-
|
||||
name: 'Validate PHPStan Mappers Compatibility'
|
||||
run: bin/rector check-static-type-mappers --ansi
|
||||
|
||||
-
|
||||
name: 'PHP Linter'
|
||||
|
|
|
@ -274,7 +274,6 @@
|
|||
"packages/symfony-php-config/tests",
|
||||
"rules/symfony-php-config/tests"
|
||||
],
|
||||
"Rector\\SymfonyPhpDocParser\\Tests\\": "packages/simple-php-doc-parser/tests",
|
||||
"Rector\\Symfony\\Tests\\": "rules/symfony/tests",
|
||||
"Rector\\Transform\\Tests\\": "rules/transform/tests",
|
||||
"Rector\\Twig\\Tests\\": "rules/twig/tests",
|
||||
|
|
|
@ -15,12 +15,12 @@
|
|||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Rector\\SymfonyPhpDocParser\\": "src"
|
||||
"Rector\\SimplePhpDocParser\\": "src"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Rector\\SymfonyPhpDocParser\\Tests\\": "tests"
|
||||
"Rector\\SimplePhpDocParser\\Tests\\": "tests"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,10 @@ use PhpParser\Node\Arg;
|
|||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Name;
|
||||
use PHPStan\Type\ResourceType;
|
||||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
|
@ -130,22 +132,18 @@ CODE_SAMPLE
|
|||
return true;
|
||||
}
|
||||
|
||||
$st = $this->getStaticType($node);
|
||||
$staticType = $this->getStaticType($node);
|
||||
$resourceType = new ResourceType();
|
||||
|
||||
if ($st->equals($resourceType)) {
|
||||
if ($staticType->equals($resourceType)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($st instanceof UnionType) {
|
||||
foreach ($st->getTypes() as $type) {
|
||||
if ($type->equals($resourceType)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if ($this->isUnionTypeWithResourceSubType($staticType, $resourceType)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return $node instanceof Variable && $this->isName($node, 'connection');
|
||||
}
|
||||
|
||||
private function findConnectionVariable(FuncCall $funcCall): ?Expr
|
||||
|
@ -160,4 +158,17 @@ CODE_SAMPLE
|
|||
|
||||
return $connectionAssign !== null ? $connectionAssign->var : null;
|
||||
}
|
||||
|
||||
private function isUnionTypeWithResourceSubType(Type $staticType, ResourceType $resourceType): bool
|
||||
{
|
||||
if ($staticType instanceof UnionType) {
|
||||
foreach ($staticType->getTypes() as $type) {
|
||||
if ($type->equals($resourceType)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
35
rules/mysql-to-mysqli/tests/Fixture/full_tests.php.inc
Normal file
35
rules/mysql-to-mysqli/tests/Fixture/full_tests.php.inc
Normal file
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\MysqlToMysqli\Tests\Fixture;
|
||||
|
||||
final class FullTests
|
||||
{
|
||||
public function run_with_connection()
|
||||
{
|
||||
$connection = mysql_connect('host', 'user', 'pass', true, MYSQL_CLIENT_IGNORE_SPACE);
|
||||
|
||||
return mysql_close($connection);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\MysqlToMysqli\Tests\Fixture;
|
||||
|
||||
final class FullTests
|
||||
{
|
||||
public function run_with_connection()
|
||||
{
|
||||
$connection = mysqli_connect('host', 'user', 'pass');
|
||||
|
||||
return mysqli_close($connection);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
namespace Rector\Utils\PHPStanStaticTypeMapperChecker\Command;
|
||||
|
||||
use PHPStan\Type\NonexistentParentClassType;
|
||||
use PHPStan\Type\ParserNodeTypeToPHPStanType;
|
||||
use Rector\Core\Console\Command\AbstractCommand;
|
||||
use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface;
|
||||
use Rector\Utils\PHPStanStaticTypeMapperChecker\Finder\PHPStanTypeClassFinder;
|
||||
|
@ -61,14 +62,15 @@ final class CheckStaticTypeMappersCommand extends AbstractCommand
|
|||
return ShellCode::SUCCESS;
|
||||
}
|
||||
|
||||
$errorMessage = sprintf(
|
||||
'Add new class to "%s" that implements "%s" for this type',
|
||||
'packages/phpstan-static-type-mapper/src/TypeMapper',
|
||||
TypeMapperInterface::class
|
||||
);
|
||||
$this->symfonyStyle->error($errorMessage);
|
||||
|
||||
$this->symfonyStyle->listing($missingNodeClasses);
|
||||
foreach ($missingNodeClasses as $missingNodeClass) {
|
||||
$errorMessage = sprintf(
|
||||
'Add new class to "%s" that implements "%s" for "%s" type',
|
||||
'packages/phpstan-static-type-mapper/src/TypeMapper',
|
||||
TypeMapperInterface::class,
|
||||
$missingNodeClass
|
||||
);
|
||||
$this->symfonyStyle->error($errorMessage);
|
||||
}
|
||||
|
||||
return ShellCode::ERROR;
|
||||
}
|
||||
|
@ -92,7 +94,7 @@ final class CheckStaticTypeMappersCommand extends AbstractCommand
|
|||
$unsupportedTypeClasses[] = $phpStanTypeClass;
|
||||
}
|
||||
|
||||
$typesToRemove = [NonexistentParentClassType::class];
|
||||
$typesToRemove = [NonexistentParentClassType::class, ParserNodeTypeToPHPStanType::class];
|
||||
|
||||
return array_diff($unsupportedTypeClasses, $typesToRemove);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user