Closed eerison closed 10 months ago
Hi,
if there is such a rule, you can find it here: https://github.com/rectorphp/rector-phpunit/blob/main/docs/rector_rules_overview.md
there is this rule: https://github.com/rectorphp/rector-phpunit/blob/main/docs/rector_rules_overview.md#assertequalsparametertospecificmethodstyperector
But I didn't see a way to pass the delta value :/
I see. Would you like to improve it?
there is this rule: https://github.com/rectorphp/rector-phpunit/blob/main/docs/rector_rules_overview.md#assertequalsparametertospecificmethodstyperector
But I didn't see a way to pass the delta value :/
Yep, Should I improve this rule or create a new one?
What would you recommend from you as end user?
What would you recommend from you as end user?
I guess improve the current rule is more interesting 🤔, I will try that, and we can see in the PR ;)
Hey @TomasVotruba
I'm follwing those 2 examples
and when I'm debugging it is passing into getNodeTypes
method, But it does not go into refactor
method :/
it's my class
<?php
namespace crmi\tests;
use Mockery\MethodCall;
use PhpParser\Node;
use PhpParser\Node\Identifier;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
final class AssertEqualsOrAssertSameFloatParameterToSpecificMethodsTypeRector extends AbstractRector
{
/**
* This method helps other to understand the rule and to generate documentation.
*/
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
'Change method calls from set* to change*.',
[
new CodeSample(
// code before
'$user->setPassword("123456");',
// code after
'$user->changePassword("123456");'
),
]
);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes(): array
{
// what node types are we looking for?
// pick any node from https://github.com/rectorphp/php-parser-nodes-docs/
return [MethodCall::class];
}
public function refactor(Node $node): ?Node
{
$methodCallName = $this->getName($node->name);
if ($methodCallName === null) {
return null;
}
// we only care about "set*" method names
if (! str_starts_with($methodCallName, 'set')) {
// return null to skip it
return null;
}
$newMethodCallName = preg_replace('#^set#', 'change', $methodCallName);
$node->name = new Identifier($newMethodCallName);
// return $node if you modified it
return $node;
}
}
am I missing something?
Note: I'm doing it into the project just as a first try, after that I will pass to the lib ;)
Sure. The namespace use Mockery\MethodCall;
is the trouble. It happened to me million times, IDE could be a bit smarter indeed :)
Ohhh man, after I change to use PhpParser\Node\Expr\MethodCall;
, now it's passing into refactor
, thank you :)
Are PRs allowed to main
branch only? or is there other branch that accepts php 7.4
?
Are PRs allowed to
main
branch only? or is there other branch that accepts php7.4
?
What? how is it possible? this repository requires php >=8.1, But I could install this in my project (php 7.4 🤯 )
Or is it possible, because I require rector in my dev dependency and in dev dependency does not have php restrictions 👀
We have only the main
branch.
The code is downgraded to PHP 7.2, so it will be available to use on PHP 7.4 too.
Hello guys
I'm bumping phpunit to version 9 and I faced this issue in some places
is there any rule to change