Skip to content

Commit

Permalink
TASK: Fix calls for this (#4037)
Browse files Browse the repository at this point in the history
* TASK: Fix calls for this

Resolves: #4017

* [CI] Rector Rectify

---------

Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
sabbelasichon and actions-user authored Jan 24, 2024
1 parent 0284e59 commit f853b45
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Rector/v12/v3/typo3/MigrateMagicRepositoryMethodsRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use PHPStan\Reflection\MethodReflection;
use PHPStan\Type\Constant\ConstantBooleanType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\ThisType;
use PHPStan\Type\TypeCombinator;
use Rector\Core\Rector\AbstractScopeAwareRector;
use Rector\Core\Reflection\ReflectionResolver;
Expand Down Expand Up @@ -123,15 +124,19 @@ public function getRuleDefinition(): RuleDefinition
private function resolveMethodReflection(MethodCall $node, Scope $scope, string $methodName): ?MethodReflection
{
$resolvedType = $this->getType($node->var);

$type = TypeCombinator::removeNull($resolvedType);
$type = TypeCombinator::remove($type, new ConstantBooleanType(\false));
if (! $type instanceof ObjectType) {
if ($type instanceof ObjectType) {
/** @phpstan-var class-string $className */
$className = $type->getClassName();
} elseif ($resolvedType instanceof ThisType) {
/** @phpstan-var class-string $className */
$className = $resolvedType->getClassName();
} else {
return null;
}

/** @phpstan-var class-string $className */
$className = $type->getClassName();

return $this->reflectionResolver->resolveMethodReflection($className, $methodName, $scope);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace Ssch\TYPO3Rector\Tests\Rector\v12\v3\typo3\MigrateMagicRepositoryMetho

use Ssch\TYPO3Rector\Tests\Rector\v12\v3\typo3\MigrateMagicRepositoryMethodsRector\Source\ExampleRepository;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Persistence\Repository;

class MyController extends ActionController
{
Expand All @@ -29,6 +30,21 @@ class MyController extends ActionController
}
}

class MyRepository extends Repository
{
public function findByUids(array $uids): array
{
$result = [];
foreach ($uids as $uid) {
$contact = $this->findByUid($uid);
if ($contact) {
$result[] = $contact;
}
}
return $result;
}
}

?>
-----
<?php
Expand All @@ -37,6 +53,7 @@ namespace Ssch\TYPO3Rector\Tests\Rector\v12\v3\typo3\MigrateMagicRepositoryMetho

use Ssch\TYPO3Rector\Tests\Rector\v12\v3\typo3\MigrateMagicRepositoryMethodsRector\Source\ExampleRepository;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Persistence\Repository;

class MyController extends ActionController
{
Expand All @@ -62,4 +79,19 @@ class MyController extends ActionController
}
}

class MyRepository extends Repository
{
public function findByUids(array $uids): array
{
$result = [];
foreach ($uids as $uid) {
$contact = $this->findByUid($uid);
if ($contact) {
$result[] = $contact;
}
}
return $result;
}
}

?>

0 comments on commit f853b45

Please sign in to comment.