Hi, I trying to make new rule and stuck with removing multiline comment.
It looks like:
/**
* @DI\InjectParams({
* "repository" = @DI\Inject("repository"),
* "option" = @DI\Inject("%option%"),
* })
*/
I use
$inf = $constructMethod->getAttribute(AttributeKey::PHP_DOC_INFO);
$inf->removeByName('DI');
but this command removes only 1 line
---------- begin diff ----------
--- Original
+++ New
@@ -21,7 +21,6 @@
/**
- * @DI\InjectParams({
* "repository" = @DI\Inject("repository"),
* "option" = @DI\Inject("%option%"),
* })
----------- end diff -----------
Also I tried to make custom TagValueNode, but didn't find a way to registered new PhpDocNodeFactory.
Need help :)
rector version dev-master(v0.7.0)
Hi, failing test case PR is needed.
Also keep the use imports
Any update?
I will try to do it on weekends.
Demo should be enough for me: https://getrector.org/demo
The demo link you provided doesn't show any diff nor bug.
Have you had something like this in mind?
Yes, that's exactly what I needed. Thank you very much
@TomasVotruba Hi! I trying to run RemoveJmsInjectParamsAnnotationRector on my codebase and seems it doesn't work.
I created rector.yaml
services:
Rector\JMS\Rector\ClassMethod\RemoveJmsInjectParamsAnnotationRector: null
Then run
php vendor/bin/rector process utils/Test.php --dry-run
Annotation was not deleted. But if I run your test, it works.
Test.php I created from your test example. On real files it doesn't works too.
And one more problem, I can't run rector unit tests:
PHP Fatal error: Cannot declare class Rector\Architecture\Tests\Rector\Class_\ConstructorInjectionToActionInjectionRector\Fixture\DuplicateController, because the name is already in use in /tmp/rector_temp_tests/original_066106da16a7_duplicate.php on line 34
I removed /tmp/rector_temp_tests but it not helped
Could you provide demo link?
https://getrector.org/demo
@TomasVotruba There is no such rector
https://getrector.org/demo/3ea88594-ebc8-498f-9cf4-519247e9ba0c
@oldy777 Ha, it seems the Rector version on demo is not updated.
@JanMikes Hi, could you look at update of demo Rector version?
It doesn't use the latest one.
The `RemoveJmsInjectParamsAnnotationRector class is here in code, but is missing in demo: https://getrector.org/demo/ace7ba3a-6641-40ee-9d5d-f9b39021e960#result
Hi, i checked, demo is updated and latest image is downloaded, because the file is present in docker:
[email protected]:~# docker run -it --entrypoint="" rector/rector-secured:latest ls -l rules/jms/src/Rector/ClassMethod
total 4
-rw-r--r-- 1 root root 2045 Feb 26 00:00 RemoveJmsInjectParamsAnnotationRector.php
I am investigating, will let you know with update
Oh man, stupid school boy mistake 馃槃
Fixed by https://github.com/rectorphp/getrector.org/commit/c4954e7f56de66ed3bf0f41faa3441e704e85e29 (will be deployed in few minutes).
I was living in other reality, though we had :latest tag docker image in production already, but instead it was in different branch.
Shit happens :) that's how programmers get work :D.
Thanks for quick fix :+1:
@TomasVotruba It seems I found out the problem. Everything works correct on rector/rector (v0.7.3), but it doesn't work on rector/rector-prefixed (0.8.x-dev)
@oldy777 We need failing test case to confirm that
@TomasVotruba I don't know how to do it.
I have a file like in demo
<?php
use JMS\DiExtraBundle\Annotation as DI;
class SomeClass
{
/**
* @DI\InjectParams({
* "subscribeService" = @DI\Inject("app.email.service.subscribe"),
* "ipService" = @DI\Inject("app.util.service.ip")
* })
*/
public function __construct()
{
}
}
Run rector-prefixed:
php vendor/bin/rector process test.php --dry-run
Rector 0.8.x-dev@e72639d
Config file: rector.yaml
3/3 [鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔] 100%
[OK] Rector is done!
Then run rector:
php ../demo/vendor/bin/rector process test.php --dry-run
Rector v0.7.3
Config file: rector.yaml
3/3 [鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔] 100%
1 file with changes
===================
1) test.php
---------- begin diff ----------
--- Original
+++ New
@@ -4,13 +4,7 @@
class SomeClass
{
- /**
- * @DI\InjectParams({
- * "subscribeService" = @DI\Inject("app.email.service.subscribe"),
- * "ipService" = @DI\Inject("app.util.service.ip")
- * })
- */
public function __construct()
{
}
}
\ No newline at end of file
----------- end diff -----------
Applied rules:
* Rector\JMS\Rector\ClassMethod\RemoveJmsInjectParamsAnnotationRector
[OK] Rector is done! 1 file have been changed.
The best would be to copy existing workflow in rector-prefixed,
https://github.com/rectorphp/rector-prefixed/tree/master/.github/workflows
add your setup, code, config and command line,
and send it as pull-request. Having that, it should fail.
Also, if possible, verify that JMS\DiExtraBundle\Annotation is autoloaded by your projects' composer.json.