1

I'm running this command:

sudo phpmd /repository/my/code/trunk/src/ text naming --reportfile code.staticanalysis

And getting this result:

Invalid field modifiers given, allowed modifiers are IS_PUBLIC, IS_PROTECTED, IS_PRIVATE and IS_STATIC.

This is a fresh install of PHPMD, via pear. I have tried it with different and multiple rulesets (codesize, naming, unusedcode) for the same result. I had a suspicion the PDepend library might be bad, but reinstalling it didn't help. Any pointers?

Nathaniel Ford
  • 20,545
  • 20
  • 91
  • 102
  • 2
    make sure there is nothing in your source using the old style `var` property declarations. That might be throwing it for a loop – Orangepill May 31 '13 at 21:40
  • @Orangepill Can you be more specific what form the old style var declarations are? I'm not familiar and since this is legacy code there is a very good chance this is the problem! – Nathaniel Ford May 31 '13 at 22:10
  • 1
    example is `class A { var $property = "value"; }` instead of `class A { public $property = "value"; }` PHP 4 didn't support the visibility designation. – Orangepill May 31 '13 at 22:14
  • I did an extensive refactoring and search for issues related to `var` and replaced them with `public` or appropriate, and it's still dying. Does anyone know how I can get a stack trace to find the offending functions? – Nathaniel Ford Jun 03 '13 at 18:30
  • You may be able to get away with running your code through the command line `php -l` with `E_STRICT | E_ALL` set as the error reporting level. – Orangepill Jun 03 '13 at 18:36
  • `php.ini` is set with that already; it appears phpmd may be suppressing the additional information? This could be a limitation of that program. – Nathaniel Ford Jun 03 '13 at 18:44
  • is the code.staticanalysis file being created? – Orangepill Jun 03 '13 at 18:58
  • Yes, but it is empty. – Nathaniel Ford Jun 03 '13 at 18:59
  • What version of PDepnd are you using.... and try limiting the scope of the test to just include smaller code branches. – Orangepill Jun 03 '13 at 22:07

1 Answers1

2

Try as I may I was unable to reproduce the issue that you where experiencing but I did a little digging and this is what I found, hopefully it will lead to some sort of resolution:

The error you are describing is emitted as an exception of the PHP_Depend_Code_ASTFieldDeclaration:::setModifiers method call, it is thrown as a result of not having any modifiers for the method/class/property in question.

If I had to take a guess on what your issue was then I would say I might be because a version mismatch between PDepend and PHPMD. I would try uninstalling and reinstalling (I sourced mine from the pear repo if that makes any difference).

Good Luck.

Orangepill
  • 24,500
  • 3
  • 42
  • 63
  • So, after doing the above I spent a night exhaustively breaking down the codebase until I found the chunks that were failing. There were a couple of legacy instances of `interface MyInterface {` containing `private $_someVar`. I'm not sure if this ever worked in PHP but apparently it throws the somewhat misleading error message cited. Thanks for all your help @Orangepill ! – Nathaniel Ford Jun 04 '13 at 17:07
  • 1
    Not a problem, glad you got it squashed... Thanks for turning me on to the tool.. it's pretty nifty. – Orangepill Jun 04 '13 at 17:10
  • I'll award the bounty as soon as I can... ~1 hr. Thanks again for your help! – Nathaniel Ford Jun 04 '13 at 17:15