Skip to content

Commit

Permalink
Bump to Rector 0.9.20 (#1961)
Browse files Browse the repository at this point in the history
* [TASK]  Bump to Rector 0.9.20
  • Loading branch information
TomasVotruba authored Feb 10, 2021
1 parent 37e3cc8 commit c7eb16c
Show file tree
Hide file tree
Showing 140 changed files with 718 additions and 449 deletions.
14 changes: 6 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
"require": {
"php": "^7.3|^8.0",
"phpstan/phpstan": "^0.12.69, <0.12.70",
"rector/rector": "0.9.18"
"rector/rector": "0.9.20"
},
"require-dev": {
"captainhook/captainhook": "^5.4",
"captainhook/plugin-composer": "^5.2",
"phpunit/phpunit": "^8.0|^9.0",
"symplify/coding-standard": "^9.0.17",
"symplify/easy-coding-standard": "^9.0.17",
"symplify/phpstan-extensions": "^9.0.17"
"phpunit/phpunit": "^9.0",
"symplify/coding-standard": "^9.1",
"symplify/easy-coding-standard": "^9.1",
"symplify/phpstan-extensions": "^9.1"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -56,7 +56,5 @@
"docs": "vendor/bin/rule-doc-generator generate src/Rector --output-file docs/all_rectors_overview.md --ansi",
"rector": "vendor/bin/rector rectify --dry-run --ansi --match-git-diff",
"fix-rector": "vendor/bin/rector rectify --ansi"
},
"minimum-stability": "dev",
"prefer-stable": true
}
}
11 changes: 0 additions & 11 deletions phpstan-baseline.neon

This file was deleted.

5 changes: 4 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ includes:
# see https://github.com/symplify/phpstan-extensions
- vendor/symplify/phpstan-extensions/config/config.neon
- utils/phpstan/config/typo3-rector.neon
- phpstan-baseline.neon

parameters:
level: 8
Expand All @@ -17,8 +16,12 @@ parameters:

inferPrivatePropertyTypeFromConstructor: true
checkMissingIterableValueType: false

checkGenericClassInNonGenericObjectType: false

ignoreErrors:
- '#Function Symfony\\Component\\DependencyInjection\\Loader\\Configurator\\ref not found#'
- '#Function Symfony\\Component\\DependencyInjection\\Loader\\Configurator\\service not found#'
- '#Used function Symfony\\Component\\DependencyInjection\\Loader\\Configurator\\ref not found#'
- '#Used function Symfony\\Component\\DependencyInjection\\Loader\\Configurator\\service not found#'
- '#Parameter \#2 \$stmt of method Rector\\Core\\NodeManipulator\\ClassInsertManipulator\:\:addAsFirstMethod\(\) expects PhpParser\\Node\\Stmt\\ClassConst\|PhpParser\\Node\\Stmt\\ClassMethod\|PhpParser\\Node\\Stmt\\Property, PhpParser\\Node\\Stmt\\Nop given#'
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,19 @@
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;

trait ConnectionCallTrait
final class ConnectionCallFactory
{
/**
* @var NodeFactory
*/
protected $nodeFactory;
private $nodeFactory;

/**
* @required
*/
public function autowireNodeFactoryTrait(NodeFactory $nodeFactory): void
public function __construct(NodeFactory $nodeFactory)
{
$this->nodeFactory = $nodeFactory;
}

private function createConnectionCall(Arg $firstArgument): Assign
public function createConnectionCall(Arg $firstArgument): Assign
{
$connection = $this->nodeFactory->createMethodCall(
$this->nodeFactory->createStaticCall(GeneralUtility::class, 'makeInstance', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,25 @@

use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\Variable;
use Rector\Core\PhpParser\Node\NodeFactory;

final class DatabaseConnectionExecInsertQueryRefactoring implements DatabaseConnectionToDbalRefactoring
{
use ConnectionCallTrait;
/**
* @var ConnectionCallFactory
*/
private $connectionCallFactory;

/**
* @var NodeFactory
*/
private $nodeFactory;

public function __construct(ConnectionCallFactory $connectionCallFactory, NodeFactory $nodeFactory)
{
$this->connectionCallFactory = $connectionCallFactory;
$this->nodeFactory = $nodeFactory;
}

public function refactor(MethodCall $oldNode): array
{
Expand All @@ -20,7 +35,7 @@ public function refactor(MethodCall $oldNode): array
return [];
}

$connectionAssignment = $this->createConnectionCall($tableArgument);
$connectionAssignment = $this->connectionCallFactory->createConnectionCall($tableArgument);

$connectionInsertCall = $this->nodeFactory->createMethodCall(
new Variable('connection'), 'insert', [$tableArgument->value, $dataArgument->value]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,25 @@

use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\Variable;
use Rector\Core\PhpParser\Node\NodeFactory;

final class DatabaseConnectionExecTruncateTableRefactoring implements DatabaseConnectionToDbalRefactoring
{
use ConnectionCallTrait;
/**
* @var ConnectionCallFactory
*/
private $connectionCallFactory;

/**
* @var NodeFactory
*/
private $nodeFactory;

public function __construct(ConnectionCallFactory $connectionCallFactory, NodeFactory $nodeFactory)
{
$this->connectionCallFactory = $connectionCallFactory;
$this->nodeFactory = $nodeFactory;
}

public function refactor(MethodCall $oldNode): array
{
Expand All @@ -19,7 +34,7 @@ public function refactor(MethodCall $oldNode): array
return [];
}

$connectionAssignment = $this->createConnectionCall($tableArgument);
$connectionAssignment = $this->connectionCallFactory->createConnectionCall($tableArgument);

$connectionInsertCall = $this->nodeFactory->createMethodCall(
new Variable('connection'), 'truncate', [$tableArgument->value]
Expand Down
44 changes: 27 additions & 17 deletions src/Helper/Typo3NodeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@
use PhpParser\Node\Expr\PropertyFetch;
use PHPStan\Type\ObjectType;
use Rector\Core\PhpParser\Node\Value\ValueResolver;
use Rector\Core\Rector\AbstractRector\NameResolverTrait;
use Rector\Core\Rector\AbstractRector\NodeTypeResolverTrait;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\NodeTypeResolver\NodeTypeResolver;

final class Typo3NodeResolver
{
use NameResolverTrait;
use NodeTypeResolverTrait;

/**
* @var string
*/
Expand Down Expand Up @@ -85,11 +83,23 @@ final class Typo3NodeResolver
private $valueResolver;

/**
* @required
* @var NodeNameResolver
*/
public function autowireValueResolverTrait(ValueResolver $valueResolver): void
{
private $nodeNameResolver;

/**
* @var NodeTypeResolver
*/
private $nodeTypeResolver;

public function __construct(
ValueResolver $valueResolver,
NodeNameResolver $nodeNameResolver,
NodeTypeResolver $nodeTypeResolver
) {
$this->valueResolver = $valueResolver;
$this->nodeNameResolver = $nodeNameResolver;
$this->nodeTypeResolver = $nodeTypeResolver;
}

public function isMethodCallOnGlobals(Node $node, string $methodCall, string $global): bool
Expand All @@ -102,11 +112,11 @@ public function isMethodCallOnGlobals(Node $node, string $methodCall, string $gl
return false;
}

if (! $this->isName($node->name, $methodCall)) {
if (! $this->nodeNameResolver->isName($node->name, $methodCall)) {
return false;
}

if (! $this->isName($node->var->var, self::GLOBALS)) {
if (! $this->nodeNameResolver->isName($node->var->var, self::GLOBALS)) {
return false;
}

Expand All @@ -127,7 +137,7 @@ public function isAnyMethodCallOnGlobals(Node $node, string $global): bool
return false;
}

if (! $this->isName($node->var->var, self::GLOBALS)) {
if (! $this->nodeNameResolver->isName($node->var->var, self::GLOBALS)) {
return false;
}

Expand All @@ -144,7 +154,7 @@ public function isTypo3Global(Node $node, string $global): bool
return false;
}

if (! $this->isName($node->var, self::GLOBALS)) {
if (! $this->nodeNameResolver->isName($node->var, self::GLOBALS)) {
return false;
}

Expand Down Expand Up @@ -186,7 +196,7 @@ public function isPropertyFetchOnAnyPropertyOfGlobals(Node $node, string $global
return false;
}

if (! $this->isName($node->var->var, self::GLOBALS)) {
if (! $this->nodeNameResolver->isName($node->var->var, self::GLOBALS)) {
return false;
}

Expand Down Expand Up @@ -216,11 +226,11 @@ public function isMethodCallOnPropertyOfGlobals(Node $node, string $global, stri
return false;
}

if (! $this->isName($node->var->var->var, self::GLOBALS)) {
if (! $this->nodeNameResolver->isName($node->var->var->var, self::GLOBALS)) {
return false;
}

if (! $this->isName($node->var->name, $property)) {
if (! $this->nodeNameResolver->isName($node->var->name, $property)) {
return false;
}

Expand All @@ -238,7 +248,7 @@ public function isMethodCallOnBackendUser(Node $node): bool

private function isPropertyFetchOnParentVariableOfType(Node $node, string $type): bool
{
$parentNode = $node->getAttribute('parent');
$parentNode = $node->getAttribute(AttributeKey::PARENT_NODE);

if (! $parentNode instanceof Assign) {
return false;
Expand All @@ -248,7 +258,7 @@ private function isPropertyFetchOnParentVariableOfType(Node $node, string $type)
return false;
}

$objectType = $this->getObjectType($parentNode->expr->var);
$objectType = $this->nodeTypeResolver->getStaticType($parentNode->expr->var);

if (! $objectType instanceof ObjectType) {
return false;
Expand Down
38 changes: 38 additions & 0 deletions src/NodeAnalyzer/ClassConstAnalyzer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace Ssch\TYPO3Rector\NodeAnalyzer;

use PhpParser\Node\Expr;
use PhpParser\Node\Expr\ClassConstFetch;
use Rector\NodeNameResolver\NodeNameResolver;

final class ClassConstAnalyzer
{
/**
* @var NodeNameResolver
*/
private $nodeNameResolver;

public function __construct(NodeNameResolver $nodeNameResolver)
{
$this->nodeNameResolver = $nodeNameResolver;
}

/**
* Detects "SomeClass::class"
*/
public function isClassConstReference(Expr $expr, string $className): bool
{
if (! $expr instanceof ClassConstFetch) {
return false;
}

if (! $this->nodeNameResolver->isName($expr->name, 'class')) {
return false;
}

return $this->nodeNameResolver->isName($expr->class, $className);
}
}
Loading

0 comments on commit c7eb16c

Please sign in to comment.