[PHP] Support of PHP frameworks (Symfony, Zend etc...)

63 views
Skip to first unread message

mad....@gmail.com

unread,
Oct 15, 2015, 8:15:01 AM10/15/15
to SonarQube
He everyone.

The question is for some rules which parsed by PSR-2 or SonarWay rules as "duplicates". 

For example:
Symfony2 framework

Given we have entity repository AcmeDemoBundle:Post
When we retrive this repository from manager in PostController like $this->getManager()->getRepository('AcmeDemoBundle:Post'); for more than 4 times
Then we have "issue" in sonar about "duplicate code" and we need to move this alias (AcmeDemoBundle:Post) to const...

But I guess that is not right way...

What do you think about this?

Thanx!

Elena Vilchik

unread,
Oct 16, 2015, 4:34:39 AM10/16/15
to SonarQube
Hello!

It wan't easy to "decode" your feedback, but I understood your problem as following: 
Due to some pattern of some PHP framework you have issue on rule "String literals should not be duplicated".

So,
1) I don't see the reason not to move string repeated 4 times into constant (IMHO even 1 time is enough in this use case).
2)  This rule "String literals should not be duplicated" has parameter equal 3 by default, you can increase it. Finally you can always disable rule.

If you think that first option is a bad one, please explain why. 

Next time, please specify rule and code which reproduces the issue more properly.

Thanks! 
Reply all
Reply to author
Forward
0 new messages