Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DevelopmentCodeFragment doesn't work as expected #949

Open
6 tasks done
SanderSander opened this issue Apr 15, 2022 · 1 comment
Open
6 tasks done

DevelopmentCodeFragment doesn't work as expected #949

SanderSander opened this issue Apr 15, 2022 · 1 comment

Comments

@SanderSander
Copy link
Contributor

SanderSander commented Apr 15, 2022

  • PHPMD version: 2.12.0
  • PHP Version: 8.1
  • Installation type: (composer)

Function calls like var_dump are not detected in by the the Rule/Class DevelopmentCodeFragment.
It sees the calls as in my case string(21) "composerlink\var_dump" where composerlink is the root namespace.

This has to do with the namespace, but in the namespace composerlink a method var_dump doesn't exist at all.

PHP Just uses the internal var_dump method, and you should expect phpmd to fail on this, except when you define a method var_dump in that namespace. (When ignore-namespace is true it should always fail).

Current Behavior

No violations detected

Expected Behavior

 86 | VIOLATION | The method LinkManager::linkPackage() calls the typical debug function var_dump() which is mostly only used during development.

Steps To Reproduce:

Add var_dump somewhere in your code, and run ./vendor/bin/phpmd ./src ansi design

Additional info

With the following configuration it works like excepted, but disables the ability to define one of these methods in any namespace.

    <rule ref="rulesets/design.xml">
        <exclude name="DevelopmentCodeFragment" />
    </rule>
    <rule ref="rulesets/design.xml/DevelopmentCodeFragment">
        <properties>
            <property name="ignore-namespaces" value="true" />
        </properties>
    </rule>

Checks before submitting

  • Be sure that there isn't already an issue about this. See: Issues list
  • Be sure that there isn't already a pull request about this. See: Pull requests
  • I have added every step to reproduce the bug.
  • If possible I added relevant code examples.
  • This issue is about 1 bug and nothing more.
  • The issue has a descriptive title. For example: "JSON rendering failed on Windows for filenames with space".
@SanderSander
Copy link
Contributor Author

I tried to fix it but I''m not aware of a way to detect if the method truly exists

@ravage84 ravage84 added this to the 2.x (unspecific) milestone May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants