pax_global_header00006660000000000000000000000064136016430320014510gustar00rootroot0000000000000052 comment=146c3527f06eec5c63cec434e8c4b6b7001e08d9 phpmd-2.8.1/000077500000000000000000000000001360164303200126305ustar00rootroot00000000000000phpmd-2.8.1/.editorconfig000066400000000000000000000010231360164303200153010ustar00rootroot00000000000000; This file is for unifying the coding style for different editors and IDEs. ; More information at http://editorconfig.org root = true [*] end_of_line = lf [*.php] indent_style = space indent_size = 4 end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true [*.bat] end_of_line = crlf [*.yml] indent_style = space indent_size = 2 [*.rst] insert_final_newline = true trim_trailing_whitespace = true [*.json] indent_style = space indent_size = 2 trim_trailing_whitespace = true insert_final_newline = true phpmd-2.8.1/.github/000077500000000000000000000000001360164303200141705ustar00rootroot00000000000000phpmd-2.8.1/.github/FUNDING.yml000066400000000000000000000000421360164303200160010ustar00rootroot00000000000000tidelift: "packagist/phpmd/phpmd" phpmd-2.8.1/.github/ISSUE_TEMPLATE/000077500000000000000000000000001360164303200163535ustar00rootroot00000000000000phpmd-2.8.1/.github/ISSUE_TEMPLATE/1_Bug.md000066400000000000000000000017241360164303200176360ustar00rootroot00000000000000--- name: "Bug" about: 'Report a problem with PHPMD' --- - PHPMD version: #.#.# - PHP Version: #.#.# - Installation type: (phar file/ composer) - Operating System / Distribution & Version: (Windows 10 / CentOS 7.6 / ...) ### Current Behavior Explain the result that you get. ### Expected Behavior Explain the result that you expected. ### Steps To Reproduce: Explain **all** the steps you did to create this bug so we can reproduce it. ## Checks before submitting * [ ] Be sure that there isn't already an issue about this. See: [Issues list](https://github.com/phpmd/phpmd/issues) * [ ] Be sure that there isn't already a pull request about this. See: [Pull requests](https://github.com/phpmd/phpmd/pulls) * [ ] 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". phpmd-2.8.1/.github/ISSUE_TEMPLATE/2_Feature_Proposal.md000066400000000000000000000012701360164303200223700ustar00rootroot00000000000000--- name: "Feature Proposal" about: 'Propose a new feature' --- ## Description Describe the proposal, explain what it does and why. Try to describe the benefits but also the consequences of the proposal. ## Checks before submitting * [ ] Be sure that there isn't already an issue about this. See: [Issues list](https://github.com/phpmd/phpmd/issues) * [ ] Be sure that there isn't already a pull request about this. See: [Pull requests](https://github.com/phpmd/phpmd/pulls) * [ ] Tell if you have the option to provide the code for this proposal. * [ ] This issue is about 1 feature proposal and nothing more. * [ ] The issue has a descriptive title. For example: "Add JSON render option". phpmd-2.8.1/.github/ISSUE_TEMPLATE/3_Question.md000066400000000000000000000006011360164303200207230ustar00rootroot00000000000000--- name: "Question" about: 'This repository is for bugs and feature proposals only. If you have any question please visit or community on Gitter to ask the questions: https://gitter.im/phpmd/community' --- This repository is only for bugs and feature proposals. If you have any question or need support please visit our Gitter channel: https://gitter.im/phpmd/community Thank you! phpmd-2.8.1/.github/ISSUE_TEMPLATE/4_Documentation_and_Website_Issue.md000066400000000000000000000015721360164303200254120ustar00rootroot00000000000000--- name: "Documentation & Website Issue" about: 'Do you see something incorrect or do you miss some information in the documentation or the website. Tell us.' --- ## Description Describe what you miss or is incorrect on the [website](https://phpmd.org/) or in the documentation. Be as explicit as possible. If possible add a URL to the incorrect web page/documentation. ## Checks before submitting * [ ] Be sure that there isn't already an issue about this. See: [Issues list](https://github.com/phpmd/phpmd/issues) * [ ] Be sure that there isn't already a pull request about this. See: [Pull requests](https://github.com/phpmd/phpmd/pulls) * [ ] Tell if you have the possibility to create a Pull Request to solve this issue. * [ ] If possible add a URL to the incorrect website page or documentation file. * [ ] This issue is about 1 documentation or website issue and nothing more. phpmd-2.8.1/.github/ISSUE_TEMPLATE/config.yml000066400000000000000000000002101360164303200203340ustar00rootroot00000000000000blank_issues_enabled: false contact_links: - name: Gitter url: https://gitter.im/phpmd/community about: Chat with us on Gitterphpmd-2.8.1/.github/PULL_REQUEST_TEMPLATE.md000066400000000000000000000014421360164303200177720ustar00rootroot00000000000000Type: (bugfix / feature / refactoring / documentation update) Issue: Resolves #.. the corresponding issue for this PR (if exist) Breaking change: yes/no (if yes explain why) phpmd-2.8.1/.gitignore000066400000000000000000000001211360164303200146120ustar00rootroot00000000000000.abc .idea .sonar .project .buildpath .settings *.phar composer.lock vendor dist phpmd-2.8.1/.gitmodules000066400000000000000000000001221360164303200150000ustar00rootroot00000000000000[submodule "setup"] path = setup url = git://github.com/Qafoo/build-commons.git phpmd-2.8.1/.mailmap000066400000000000000000000003551360164303200142540ustar00rootroot00000000000000Manuel Pichler Stefan Zerkalica Daniel Mason Ilia Shakitko phpmd-2.8.1/.scrutinizer.yml000066400000000000000000000002531360164303200160120ustar00rootroot00000000000000build: environment: php: version: 7.4.0 checks: php: code_rating: true duplication: true filter: excluded_paths: - src/test/resources/files/ phpmd-2.8.1/.stickler.yml000066400000000000000000000002221360164303200152450ustar00rootroot00000000000000linters: phpcs: standard: 'PSR2' extensions: '.php' tab_width: 4 ignore: 'src/test/resources/*' branches: ignore: ['1.5.x'] phpmd-2.8.1/.travis.yml000066400000000000000000000045751360164303200147540ustar00rootroot00000000000000language: php matrix: include: - php: 5.3 dist: precise - php: 5.3 dist: precise env: DEPENDENCIES=low - php: 5.4 dist: trusty - php: 5.4 dist: trusty env: DEPENDENCIES=low - php: 5.5 dist: trusty - php: 5.5 dist: trusty env: DEPENDENCIES=low - php: 5.6 - php: 5.6 env: DEPENDENCIES=low - php: 7.0 - php: 7.0 env: DEPENDENCIES=low - php: 7.1 - php: 7.1 env: DEPENDENCIES=low - php: 7.2 # Could be enabled when we'll upgrade PHPUnit # - php: 7.2 # env: DEPENDENCIES=low - php: 7.3 env: COVERAGE=true # Could be enabled when we'll upgrade PHPUnit # - php: 7.3 # env: DEPENDENCIES=low - php: 7.4 - php: 5.4 dist: trusty env: BUILD_PHAR=true - php: 7.3 env: WEBSITE=true fast_finish: true sudo: false env: global: TEST_CONFIG="phpunit.xml.dist" before_script: - phpenv config-rm xdebug.ini || echo "XDebug is not enabled" - composer self-update - if [[ $DEPENDENCIES = low ]]; then composer update --prefer-dist --prefer-lowest --prefer-stable; fi - if [[ ! $DEPENDENCIES ]]; then composer install; fi script: - if [[ $WEBSITE = 'true' ]]; then composer build-website; fi - if [[ $WEBSITE != 'true' && $BUILD_PHAR != 'true' && $COVERAGE != 'true' ]]; then vendor/bin/phpunit --configuration $TEST_CONFIG --colors; fi - if [[ $WEBSITE != 'true' && $BUILD_PHAR != 'true' && $COVERAGE = 'true' ]]; then phpdbg -qrr vendor/bin/phpunit --configuration $TEST_CONFIG --colors --coverage-text --coverage-clover=coverage.xml; fi - if [[ $BUILD_PHAR = 'true' ]]; then git submodule update --init && ant package -D-phar:filename=./phpmd.phar && ./phpmd.phar --version; fi notifications: webhooks: urls: - https://webhooks.gitter.im/e/5a993c0b870b2fa9141e # PHPMD Gitter Core Channel - https://webhooks.gitter.im/e/1c62ab29700f53c70ec5 # PHPMD Gitter Community Channel on_success: change on_failure: always on_start: never deploy: - provider: pages skip_cleanup: true github_token: $GITHUB_TOKEN local_dir: dist/website on: branch: master condition: $WEBSITE - provider: releases api_key: $GITHUB_TOKEN file: phpmd.phar skip_cleanup: true on: tags: true repo: phpmd/phpmd condition: "$BUILD_PHAR" addons: snaps: - name: ant classic: true phpmd-2.8.1/AUTHORS.rst000066400000000000000000000025371360164303200145160ustar00rootroot00000000000000================ Authors of PHPMD ================ Main Authors/Maintainers ------------------------ - Manuel Pichler (Since 2009) - Marc Würth (Since 2014) / https://github.com/ravage84 Contributors ------------ - Volker Dusch (Since 2010) / https://github.com/edorian - timmartin (Since 2010) / https://github.com/timmartin - Sebastian Bergmann (Since 2011) / https://github.com/sebastianbergmann - Zsolt Takacs (Since 2011) / https://github.com/zstakacs - Che Hodgins (Since 2011) / https://github.com/chehodgins - Gennadiy Litvinyuk (Since 2011) / https://github.com/gennadiylitvinyuk - Francis Besset (Since 2011) / https://github.com/francisbesset - zerkalica (Since 2012) / https://github.com/zerkalica - palbertini (Since 2012) / https://github.com/palbertini - bahulneel (Since 2012) / https://github.com/bahulneel - Willem Stuursma (Since 2012) / https://github.com/willemstuursma - Nimlhug (Since 2012) / https://github.com/Nimlhug - A. Martin Llano (Since 2012) / https://github.com/amllano - Juan Basso (Since 2012) / https://github.com/jrbasso - Brian Ridley (Since 2013) / https://github.com/ptlis - Radosław Mejer (Since 2014) / https://github.com/radmen - Tobias Nyholm (Since 2014) / https://github.com/Nyholm - Gasillo (Since 2014) / https://github.com/Gasillo .. Local Variables: mode: rst fill-column: 79 End: vim: et syn=rst tw=79 phpmd-2.8.1/CHANGELOG000066400000000000000000000757041360164303200140570ustar00rootroot00000000000000phpmd-2.8.1 (2019/12/27) ======================== - Fixed PHP 7.4 unit tests compatibility - Improved documentation - Automated website generation and PHAR publishing phpmd-2.8.0 (2019/12/18) ======================== - Required at least pdepend/pdepend 2.6: - Added PHP 7.1 to 7.3 syntax support - Added Symfony 5 support See full changes list: https://github.com/pdepend/pdepend/releases/tag/2.6.0 - Added #497: Undefined variable rule - Improved performances by disabling XDebug if in use - Added #571: ignore-namespaces property to DevelopmentCodeFragment rule - Added #595: Renderer which writes an ansi report string - Fixed #657: IfStatementAssignment violation message - Optimized Composer autoloader when building Phar - Fixed #661: IfStatementAssignment thrown incorrectly - Fixed #676: Handle @SuppressWarnings on each method for CountInLoop - Fixed #659: PHP 7.4 compatibility for implode() usage phpmd-2.7.0 (2019/07/30) ======================== This is the first minor release of the new PHPMD maintainer team. It contains all the new features, improvements and fixes from two and a half years since 2.6.0. Please take note of a backwards incompatible property renaming in the CouplingBetweenObjects rule. - Fixed #482: Renamed minimum property to maximum in CouplingBetweenObjects rule (backwards incompatible) Fixed in commit #9210116. - Fixed #626: Fixed special characters escaping in violation description for XML output Fixed in commit #5305f5b. - Fixed #378: Fixed warning/error when trying to export to a non-existing path Fixed in commit #67bd7c6. - Fixed #575: Fixed UnusedFormalParameter false positive in string compound variable Fixed in commit #8790cbb. - Fixed #480: Fixed "Start tag expected, '<' not found" error Fixed in commit #3e2e058. - Fixed #494: Fixed UnusedPrivateField false positive Fixed in commit #99f3ba9. - Fixed #583: Changed LongNaming rule to apply on private fields too Fixed in commit #42bf8ad. - Fixed #598: Fixed a bug in the renderer auto-discovery Fixed in commit #cc06bfd. - Fixed #572: Added support for both @SuppressWarnings and @suppressWarnings annotation cases Fixed in commit #bb2cfe9. - Fixed invalid "array of strings" type hints Fixed in commit #16e4eda. - Fixed #599: Fixed Composer package type Fixed in commit #0ca4eff. - Fixed #604: Renamed mikey179/vfsStream to mikey179/vfsstream to prevent Composer error Fixed in commit #f66247f. - Fixed #632: Changed Scrutinizer CI settings to use local PHPUnit Fixed in commit #dfaa509. - Fixed #633: Fixed AppVeyor CI build Fixed in commit #40189f3. - Fixed #609: Fixed main logo link in website build script Fixed in commit #f3b68be. - Fixed #631: Fixed URL to "How to create a custom rule set" documentation page on website Fixed in commit #3c5b534. - Fixed #449: Improved code style Fixed in commit #67cdab2. - Fixed #447: Improved code style Fixed in commit #3ef4ba8. - Fixed #450: Improved code style Fixed in commit #9525da7. - Fixed #582: Fixed a typo in Clean Code Rules documentation Fixed in commit #85e48ad. - Fixed #567: Fixed a typo in Clean Code Rules documentation Fixed in commit #175b08f. - Implemented #472: Added rule for assignment within conditional (IfStatementAssignment) Implemented in commit #716ecf5. - Implemented #490: Added rule for count in loop (CountInLoop) Implemented in commit #0e30d82. - Implemented #484: Added rule for duplicated array key (DuplicatedArrayKey) Implemented in commit #a295850. - Implemented #476: Added rule for empty catch block (EmptyCatchBlock) Implemented in commit #4bc19bd. - Implemented #636: Added rule for missing import (MissingImport) Implemented in commit #3a82eab. - Implemented #443: Added support for compound variables in UnusedLocalVariable rule Implemented in commit #c7009d5. - Implemented #329: Added support to whitelist variables in the UnusedLocalVariable rule Implemented in commit #55ca654. - Implemented #478: Implemented renderer auto-discovery Implemented in commit #91c4ca8. - Implemented #405: Added JSON output format Implemented in commit #7552089. - Implemented #525: Added new options to CLI (min-priority, minimum-priority, report-file, input-file, not-strict) Implemented in commit #71b52be. - Implemented #579: Added support for setting the maximum execution priority through CLI (max-priority, maximum-priority, maximumpriority) Implemented in commit #45de3be. - Implemented #489: Added new predefined variables to AbstractLocalVariable rule Implemented in commit #63047d9. - Implemented #382: Changed TooManyMethods rule to ignore isser-, hasser-, wither-methods Implemented in commit #609c6bb. - Implemented #625: Fixed DuplicatedArrayKey rule to check only arrays with keys Implemented in commit #43d4ed0. - Implemented #528: Fixed Travis-CI build by temporarily removing PHP 5.3 Implemented in commit #0a69edf. - Implemented #643: Fixed Travis-CI build to run PHP 5.3 and fixed 5.3 compatibility Implemented in commit #4a8a567. - Implemented #475: Added tests that show support for chained methods (fluent interfaces) for UnusedPrivateMethod rule Implemented in commit #d5c1372. - Implemented #495: Added test for SuppressWarnings for ExcessivePublicCount Implemented in commit #b1c15f8. - Implemented #381: Added annotations to allow IDEs to reference correct classes Implemented in commit #2dbae11. - Implemented #639: Fixed arrays types to use standard type syntax Implemented in commit #858c9fd. - Implemented #640: Added type hint annotations Implemented in commit #d68e511. - Implemented #481: Cleaned boc block comments Implemented in commit #08a38d4. - Implemented #491: Cleaned whitespaces Implemented in commit #dcdd61a. - Implemented #477: Fixed code formatting Implemented in commit #3c6b69b. - Implemented #548: Updated PDepend to 2.5.2 Implemented in commit #f1c145e. - Implemented #474: Dropped HHVM support Implemented in commit #9f7b4d2. - Implemented #458: Updated PHPCS dev dependency from 2.3.4 to 2.8.1 Implemented in commit #f2ae09f. - Implemented #458: Updated PHPCS & added Composer scripts Implemented in commit #24ff5a9. - Implemented #469: Updated Coding Standard command Implemented in commit #9962dae. - Implemented #627: Removed composer.lock Implemented in commit #981c78f. - Implemented #623: Extended test matrix & do only one job per build on Travis-CI Implemented in commit #a2c64bf. - Implemented #617: Replaced Travis-CI build notification from IRC to the new Gitter core channel Implemented in commit #e1a4cd7. - Implemented #620: Added PHPMD Gitter Community Channel notifications for Travis-CI Implemented in commit #f1c05bf. - Implemented #459: Integrated Stickler CI Implemented in commit #d106330. - Implemented #492: Adjusted Stickler-CI config for ignoring test resource files Implemented in commit #9b18153. - Implemented #460: Added ApiGen config file Implemented in commit #4514235. - Implemented #471: Modified default PHP installation directory to match Chocolatey package in AppVeyor CI config Implemented in commit #2b55442. - Implemented #552: Updated PHP in AppVeyor CI builds to 7.1 Implemented in commit #252b178. - Implemented #605: Added a pure PHP build script to generate the website as static files Implemented in commit #6f56a8f. - Implemented #608: Updated the website build script to handle anchor links and to use direct links whenever possible Implemented in commit #6cf7a2d. - Implemented #483: Removed broken link to Web Content Viewer from website Implemented in commit #eeea9ee. - Implemented #611: Removed section about commercial support from website Implemented in commit #671760a. - Implemented #612: Removed IRC, add Gitter & reword Support & Contact section from/on website Implemented in commit #3e94d6b. - Implemented #479: Replaced all file header doc blocks with uniform one Implemented in commit #fff046c. - Implemented #470: Changed HTTP to HTTPS in some files Implemented in commit #1ca30d0. - Implemented #448: Switched from HTTP to HTTPS in some files Implemented in commit #51eb887. - Implemented #524: Switched from HTTP to HTTPS in resource file Implemented in commit #409b276. - Implemented #454: Switched from HTTP to HTTPS for test files Implemented in commit #f1c1426. - Implemented #451: Switched from HTTP to HTTPS for main files Implemented in commit #9a77c48. - Implemented #455: Switched from HTTP to HTTPS for resource files Implemented in commit #b073ad2. - Implemented #566: Added CLI usage example Implemented in commit #e12e59c. - Implemented #621: Updated wording about PHPMD Implemented in commit #c116054. - Implemented #606: Updated license according to BSD 3-clause template Implemented in commit #e850660. - Implemented #469: Improved contributing guide for Linux / OS X users Implemented in commit #63ff5bf. - Implemented #383: Improved the ElseExpression description Implemented in commit #6f02406. - Implemented #565: Added example for modifying properties in a rule set Implemented in commit #59551fc. - Implemented #614: Removed API docs that do not exist anymore Implemented in commit #7c8d9bc. - Implemented #615: Added Gitter badge Implemented in commit #8e1e9e8. - Implemented #618: Added badges for the monthly and total downloads Implemented in commit #1e86639. phpmd-2.6.1 (2019/07/06) ======================== This is the first release of the new maintainer team of PHPMD. It is a re-tag of 2.6.0 but with PHAR build on Travis-CI and deployment to GitHub releases. - Implemented #616: Build the PHAR file on Travis-CI and publish it to GitHub releases Implemented in commit #135327d. phpmd-2.6.0 (2017/01/20) ======================== This release incorporates several pending PRs. Beside that we have rebased PHPMD on PDepend 2.5 which should complete support for PHP 7 language features. - Fixed #345: Development Code Fragment feature is not working Fixed in commit #1c0afd4. - Fixed #384: use-statement for functions returns in: UnexpectedTokenException Fixed in commit #1c0afd4. - Fixed #409: Test for PHPMD or PMD on SuppressWarnings Fixed in commit #147beb1. - Fixed #418: Add missing link to TooManyPublicMethods rule in the rules document Fixed in commit #eccacb0. - Fixed #419: Fix a link to github help because the link is broken Fixed in commit #3c9ef0b. - Fixed #426: Enable Windows Update service on AppVeyor Fixed in commit #4bd2516. - Fixed #429: Added ext-xml to require in composer.json file Fixed in commit #0aecd07. - Fixed #433: Mistake in documentation of CCN Fixed in commit #f686673. - Implemented #379: Code cleaning. Implemented in commit #902da6c. - Implemented #412: Add .mailmap file to fix git shortlog Implemented in commit #7fe3d6b. - Implemented #416: Test against lowest possible dependencies Implemented in commit #d2b58b3. phpmd-2.5.0 (2016/11/23) ======================== This release closes several minor/major issues in PHPMD itself and it bundles a new version of PDepend that also provides fixes for several bugs. - Fixed #386: English language fixes Fixed in commit #2a31103. - Fixed #395: Fix typo in rulesets/cleancode Fixed in commit #f6aa5be. - Fix copy & paste error Fixed in commit #c51ea72. - Fixed #411: Unexpected token: list - Fixed #389: Unexpected token: EMPTY - Implemented #365: Remove the leading blank line from the TextRenderer Implemented in commit #ca59154. - Implemented #380: add --ignore-exit-violations CLI flag to allow exit code 0 event if violation is found (will allow successfull build for CI) Implemented in commit #9f71d98. - Bump PHP dependency to 5.3.9 Implemented in commit #540d61c. phpmd-2.4.4 (2016/11/22) ======================== Maintenance release with new PDepend version bundled - Fixed #347: Fixed UnexpectedTokenException on null coalesce operator. Fixed in commit #8e80aaa. phpmd-2.4.2 (2016/03/10) ======================== - Fixed #261: Prove Issue 261 and added tests for CamelCaseVariableName Fixed in commit #319b398. - Fixed #328: Cannot create new nodes, when internal state is frozen. Fixed in commit #2fd479b. - Fixed #354: Replace plus by a dot as concat operator in filename creation. Fixed in commit #6a121ea. - Implemented #343: Trim exceptions for StaticAccess Implemented in commit #3121c58. phpmd-2.4.1 (2016/03/08) ======================== This release fixes a method naming issue, that was introduced with 2.4.0. phpmd-2.4.0 (2016/03/08) ======================== This release adds a new helper method to access the full qualified name of an analyzed node. - Fixed #335: Typo in clean code rule description fixed. Fixed in commit #59a6e8a. - Helper method added, so that we can access the full qualified name of a class, method, interface or function. Implemented in commit #e46a099. - Implemented #334: Added __debugInfo to list of ignored methods. Implemented in commit #f8b017a. phpmd-2.3.3 (2016/03/08) ======================== Some minor issues fixed phpmd-2.3.2 (2015/09/24) ======================== With this release we make the Symfony dependency superfluous. - Implemented #312: No more hard Symfony dependency. Implemented in commit #1da75aa. phpmd-2.3.1 (2015/09/22) ======================== Bugfix release for issue #311 introduced with the 2.3.0 release. - Fixed #311: Property "allow-underscore-test" does not exist. Fixed in commit #0db4a3e. phpmd-2.3.0 (2015/09/22) ======================== This new release contains several contributed bugfixes and additions to PHPMD. Beside that we now have better support for language constructs in the upcoming PHP 7. - Fixed #272: Improve type hint. Fixed in commit #724bf76. - Fixed #293: Declared missing method in abstract class Fixed in commit #9b806f6. - Fixed #297: Complete fix for timezone warning. Fixed in commit #227d469. - Fixed #301: Fix mixed up links in documentation. Fixed in commit #4bc4eeb. - Fixed #304: Fix #303, change if condition order. Fixed in commit #3376c73. - Implemented #232: Three new features about references, includes and include-paths Implemented in commit #180848f. - Implemented #241: Fix of UnusedPrivateMethod chained method calls. Implemented in commit #7e02f38. - Implemented #257: Add option to allow having an undercore in test methods. Implemented in commit #3cbe76d. - Implemented #265: Search for development code Implemented in commit #dfa6872. - Implemented #273: Add TooManyPublicMethods rule. Implemented in commit #b862f1f. - Implemented #291: Define the version constraints of deps in Composer using the caret operator. Implemented in commit #586ccfc. - Implemented #306: Use new Travis infrastructure. Implemented in commit #cd1308e. phpmd-2.2.3 (2015/05/27) ======================== Bugfix release that closes issues and adds some improvements to phpmd. - Fixed #285: Corrected HTML TR closing tag Fixed in commit #df6280f. - Fixed link to rules documentation Fixed in commit #20a0142. - Implemented #281: Code cleanup Implemented in commit #5e94a65. - Underlying PDepend version bumped. Implemented in commit #f4ddb8a. phpmd-2.2.2 (2015/03/26) ======================== Bugfix release that closes some issues in phpmd's core and in the project documentation. - Fixed #271: Fix cp error in doc Fixed in commit #b73dd32. - Fixed #270: Fixing namespace issue for OutOfBoundsException Fixed in commit #0d4bed1. - Fixed #80: Out ot the box usage in combination with composer of all rules failes throws error Property $exceptions does not exist. Fixed in commit #0d4bed1. phpmd-2.2.1 (2015/03/01) ======================== This release integration several pull requests and closes and handful of issues. - Fixed #237: Display type correctly for constructors Fixed in commit #49f19d8. - Fixed #238: Fix link to rulesets Fixed in commit #829d110. - Fixed #244: Fix typos in type hints Fixed in commit #b5a04ce. - Fixed #245: Fix CamelCase vs camelCase issue in the docs Fixed in commit #6cd03ce. - Implemented #210: Added editorconfig Implemented in commit #22a73a7. - Implemented #211: Added phpcs as development dependency Implemented in commit #441398d. - Implemented #214: Short method name exceptions Implemented in commit #55b799b. - Implemented #225: Refactor - remove right side whitespaces Implemented in commit #c12fffa. - Implemented #242: Unused "use" statement removed from RuleViolation class Implemented in commit #966ce38. - Implemented #243: Unused private property removed. Implemented in commit #121d43b. - Implemented #246: Improve WMC documentation Implemented in commit #b1e9be9. - Implemented #249: Remove redundant line Implemented in commit #a9bd6cb. phpmd-2.2.0 (2015/01/25) ======================== Closes an issue with recent symfony versions - Fixed #226: Fixed error message for StaticAccess Fixed in commit #efa1dcd. - Fixed #216: Refactor - removed right side spaces Fixed in commit #422345e. - Implemented #221: Ignore php4 style ctor in interfaces and namespaces Implemented in commit #b248315. - Implemented #220: Skip check for ConstructorWithNameAsEnclosingClass when in an interface or namespace Implemented in commit #b248315. - Implemented #219: Do not trigger UnusedFormalParameter with some magic methods. Implemented in commit #4d3b154. - Implemented #218: Allow any future minor version of Symfony2 2.5 components. Implemented in commit #6317043. - Implemented #215: Improved composer.json Implemented in commit #6da3358. - Implemented #196: Composer Compatible for symfony >= 2.5 and < master/dev. Implemented in commit #6317043. - Implemented #208: Appveyor CI for Windows Implemented in commit #05210b6. - Implemented #207: Added a contribution guide Implemented in commit #d6de6a5. - Implemented #205: Removed all @version annotations Implemented in commit #5b1fcef. - Implemented #204: Removed all traces of "PHP Version 5" in the file header DocBlock Implemented in commit #c36897b. - Implemented #203: Some improvements to the README Implemented in commit #cc354ed. - Implemented #201: Added the missing cleancode section to the website. Implemented in commit #ead3368. - Implemented #200: StaticAccess - ability to add exceptions for specific class names Implemented in commit #b428516. - Implemented #199: Changed the OutOfBounds exceptions when getting a property Implemented in commit #0dad28d. - Implemented #198: Allow unused foreach variables Implemented in commit #98bed5a. - Implemented #197: Allow underscore camelcase property name Implemented in commit #6eb7dcd. - Implemented #152: Update DepthOfInheritance.php: Using the right condition and naming of property. Implemented in commit #e59053c. - Implemented #97: Fixed typo in rule ElseExpression CDATA Implemented in commit #7593f17. phpmd-2.1.3 (2014/09/25) ======================== Bug fix release. - Fixed #195: Missing version number in composer.json file replaced with build.properties version number. Fixed in commit #7b8d13f. phpmd-2.1.2 (2014/09/25) ======================== This release closes several minor issues and integrates some outstanding pull requests. - Fixed #164: Fixed IRC link Fixed in commit #84f2d8a. - Fixed #165: Removed lie regarding PEAR Fixed in commit #74b9f84. - Fixed #85: Documentation changes, fixed typo in PHPMD's online documentation. Fixed in commit #f954dcf. - Fixed #190: Updating composer.json Fixed in commit #45c55d8. - Fixed #191: Superglobals are not named in CamelCase Fixed in commit #b18ffbb. - Fixed #192: Fix a typo. These are the 'design rules' not the 'code size rules Fixed in commit #1eb321d. - Implemented #182: Tweak with CamelCase matching inheritDoc Implemented in commit #9271fc6. - Implemented #189: Missing composer install documentation Implemented in commit #450f91c. phpmd-2.1.1 (2014/09/09) ======================== - Fixed #181: 404 error on your website release area - Fixed #168: --version argument doesn't return version Fixed in commit #3f56c37. - Implemented #183: exceptions for CamelCaseVariableName and UnusedLocalVariable Implemented in commit #5f9e8a2. phpmd-2.1.0 (2014/09/08) ======================== This integrates several outstanding pull requests. - Fixed #118: Fix [Naming]: Trait can have method same as trait's name Fixed in commit #f93be40. - Fixed #177: Get XML contents before parsing Fixed in commit #e081088. - Implemented #150: Fix for unused variables rules when handling namespace compact() Implemented in commit #ffab9fc. - Implemented #154: Added PHP 5.6 and HHVM to travis.yml Implemented in commit #b5cdc74. - Implemented #159: Allow a single underscore at the beginning Implemented in commit #d0779c2. - Implemented #100: Quick change to add support for exclude-pattern in a ruleset Implemented in commit #6257a83. - Implemented #117: --exclude not working Implemented in commit #6257a83. phpmd-2.0.0 (2014/05/21) ======================== This is major release of PHPMD which utilizes 2.0 engine of PDepend. - Fixed #111: Changelog with old releases and invalid dates removed. Fixed in commit #cdfbb8f. - Implemented #40: Allow multiple report files Now it is possible to render multiple report files during a single PHPMD run, just add: --reportfile-xml report.xml --reportfile-html report.html --reportfile-text report.txt to the PHP command line call. Implemented in commit #e16c38c. - Implemented #61: UnusedLocalVariable fix for compact handling in Symfony2 Implemented in commit #a1dc403. - Implemented #119: PDepend 2.0 support Implemented in commit #8c3ebe1. - Implemented #122: Add: New parameter 'ignore-whitespace' to LongClass and LongMethod rules Implemented in commit #19c4da8. phpmd-1.5.0 (2013/07/26) ======================== This release closes some PHP 5.4 related issues. - Fixed #87: Fix: PHP Fatal error: Call to a member function isInstanceOf() on a non-object Fixed in commit #9ab3b6d. - Fixed #81: Fix error when using entire ruleset "Naming" Fixed in commit #a473345. - Fixed #91: (tiny) documentation typo fix Fixed in commit #2a3d304. - Implemented #66: Added support for short variable name exceptions Implemented in commit #1484e22. - Implemented #73: Show available formats and rulesets Implemented in commit #86560ce. phpmd-1.4.1 (2012/12/14) ======================== This release integrates several pull requests. - Fixed #56: package.xml date invalid: 2011/02/12. Fixed in commit #575fe7b. - Implemented #10: Fix UnusedLocalVariable to recognize compact function. Implemented in commit #e478912. - Implemented #58: Skip "unused formal parameter" checking when method signature has been annotated as inherited using @inheritdoc. Implemented in commit #158e1f5. phpmd-1.4.0 (2012/09/07) ======================== This release integrates some longer pending pull requests and smaller bugfixes. One major addition is support for Composer as distribution channel. - Fixed #51: Fixed handling of traits. Fixed in commit #22b523c. - Implemented #11: Add getStringProperty($name) to AbstractRule.php. Implemented in commit #b7d659f. - Implemented #12: Update README.rst on cmd line arguments. Implemented in commit #458d566. - Implemented #53: Added getStringProperty and rule-setting to change TooManyMethods ignore Regexp. Implemented in commit #bc795b6. - Implemented #10: Provide PHPMD as composer dependency on packagist.org. Implemented in commit #3622bb8. phpmd-1.3.3 (2012/02/29) ======================== This release closes an issue introduced with the last release. It closes one more regression related to PHP's memory_limit and the Suhosin patch. - Fixed fatal error due to bug in memory_limit modification code. Fixed in commit #e8b546d. phpmd-1.3.2 (2012/02/25) ======================== This release closes a minor issue in PHP_PMD's memory handling when it is run in a PHP environment that uses the Suhosin patch and the suhosin.memory_limit setting. - Fixed #25450811: Alert disable memory_limit Fixed in commit #19e4fc5. phpmd-1.3.1 (2012/02/16) ======================== The 1.3.1 release of PHPMD closes one critical bug in PHPMD, that causes a fatal error due to the xdebug max_nesting_level setting for very deep self calls on methods. - Fixed #24975295: Fatal: Maximum function nesting level reached in ASTNode.php:425 Fixed in commit #f6550df. phpmd-1.3.0 (2012/02/04) ======================== Version 1.3.0 now depends on PHP_Depend 1.0.0 which has support for all the new language constructs introduced with PHP 5.4. Additionally this release contains some minor fixes for PHPMD's rule violation messages. phpmd-1.2.1 (2011/10/04) ======================== The 1.2.1 release of PHPMD closes several minor issues and bugs. Beside that we have added a contribution by Francis Besset with additions rules for PHPMD. Finally we have updated the utilized PHP_Depend version to a newer release. - Fixed #14990109: False detection of unused variable Fixed in commit #183fbd5. - Fixed #23278127: PHPMD should exclude unused parameters from inherited methods Fixed in commit #d162b21. - Fixed #9355859: PHP_Depend exceptions are silently ignored Fixed in commit #d3d553f. - Implemented #11055167: Move PHPUnit annotations from method doc block to class doc block Implemented in commit #7bcddde. - Added Superglobals rule in Controversial Implemented in commit #7176e74. - Added rules to check CamelCase Implemented in commit #1c3c260. phpmd-1.2.0 (2011/09/27) ======================== Version 1.2.0 is a small feature release of PHPMD that introduces the new command line option --strict. This options forces PHPMD to apply all rules, even if a source node contains the @SuppressWarnings annotation. - Controverial PHPMD rule that checks if the project under test does not utilize PHP's super globals. Implemented in commit #0e60fb9. - Implemented #18462127: PHPMD needs a *strict* mode. Implemented in commit #b066b44. phpmd-1.1.1 (2011/06/30) ======================== Version 1.1.1 of PHPMD is a pure Bugfix release that fixes an issue in PHPMD's package manifest. This bug prevents Pyrus the PEAR2 installer from installing PHPMD. - Fixed #10096717: Bug in PHPMD's package manifest file. Fixed in commit #f063bc9. phpmd-1.1.0 (2011/03/20) ======================== Version 1.1.0 of PHPMD was released on March the 20th 2011. The key features for this release were two new rules. The first one utilizes the Coupling Between Objects (CBO) metric to detect strongly coupled classes. The second one detects the usage of PHP's questionable 'goto' statement. Beside that we have closed a minor bug in the LongVariable rule, where also private properties with descriptive names were reported. And finally we have replaced deprecated PHPUnit features in the PHPMD's test suite, so that PHPMD's tests should now work with PHPUnit 3.4.x and 3.5.x without deprecated warnings. - Fixed #10096717: LongVariable rule should not apply on private properties. Fixed in commit #f063bc9. - Implemented #10474873: Add rule for PHP's goto statement. Implemented in commit #2745a20. - Implemented #10474987: Implement rule for CBO metric. Implemented in commit #14277b4. - Implemented #11012465: Replace deprecated PHPUnit features in test suite. Implemented in commit #4adb88d. phpmd-1.0.1 (2011/02/12) ======================== - Fixed #9930643: The include_path does not match with PHP_Depend's new directory layout. Fixed in commit #531be78. - Fixed #9626017: Clear temporary resources after a test has finished. Fixed in commit #b385f15. phpmd-1.0.0 (2011/02/05) ======================== - Fixed #9626017: Clear temporary resources after a test has finished. Fixed in commit #b385f15. - New source layout that follows maven's conventions for the directory structure of a product. - Switched to PHPUnit 3.5.x as testing framework phpmd-0.2.8 (2010/11/25) ======================== - Improved help text for the PHPMD command line. Thanks to Volker Dusch for this contribution. https://github.com/edorian/phpmd - PHPMD is now compatible with next PHP_Depend release 0.10.0 phpmd-0.2.7 (2010/09/01) ======================== - Fixed #36: @SupressWarnings annotation does not work for UnusedPrivateMethod rule. Fixed in commit #284. - Fixed #35: Stream Writer closes STDOUT. Fixed in commit #286. - Fixed #33: PEAR package.xml does not @php_bin@ and @bin_dir@ on phpmd.bat. Fixed in commit #264. phpmd-0.2.6 (2010/07/03) ======================== - Fixed #28: Unused local variable and unused parameter rule produces false positives. Fixed in commit #245. - Implemented #24: Implement Depth Of Inheritance Rule. Implemented in commit #253. - Implemented #25: Implement Number of Children Rule. Implemented in commit #252. - Implemented #26: Implement Rule that detects the usage of PHP's eval() function. Implemented in commit #251. - Implemented #27: Implement Rule that detects the usage of PHP's exit() expression. Implemented in commit #250. - Implemented #30: New option --version added to PHPMD's command line interface. Implemented in commit #246. - Names of several command line options unified with PHPUnit and PHPCPD. The --ignore option is now --exclude and --extensions is now --suffixes. phpmd-0.2.5 (2010/04/03) ======================== - Fixed #17: Do not return success exit code when PHPMD detects rule violations in analyzed source code. Fixed in commit #226. - Fixed #19: Super globals were detected as unused variables. Fixed in commit #218. - Fixed #20: Local static variables were treated as unused variables. Fixed in commit #219. - Implemented #12: Add rule for the Weighted Methods Per Class Metric. Implemented in commit #228. - Implemented #16: Alternative syntax for properties in rule set files implemented. Implemented in commit #220. phpmd-0.2.4 (2010/03/08) ======================== - E_NOTICE bug fix in naming rule. phpmd-0.2.3 (2010/03/04) ======================== - Fixed #6: PHP Tokenizer required but no error when installing. - Fixed #7: UnusedLocalVariable ruleset incorrectly flags variables as unused when used inside double quoted string. Fixed in commit #187. - Fixed #14: ExcessivePublicCount rule should utilize PHP_Depend's cis metric. Fixed in commit #203. - Fixed #15: ExcessivePublicCount rule is never used. Fixed in commit #202. - Implemented #9: Add support for "Suppress warnings" annotations. Implemented in commit #200. - Implemented #10: Support for exclude element in rule-set files added. Implemented in commit #189. - Implemented #13: Implement naming rules, e.g. short variables, parameter etc. phpmd-0.2.2 (2010/01/20) ======================== - Small change to the command line interface, which did not return an exit code != 0 when an exception occured. phpmd-0.2.1 (2010/01/05) ======================== - Implemented #5: Allow multiple input files/directories. Implemented in commit #158. - Additional unit tests for multiple components added. phpmd-0.2.0 (2009/12/30) ======================== - Implemented #2: Support for unused code fules completed. Implemented in commit #134. - Implemented #3: Text renderer implemented. - Implemented #4: Implement a html renderer. Implemented in commit #139. - Several performance improvements. phpmd-0.1.0 (2009/12/20) ======================== Initial release phpmd-2.8.1/CONTRIBUTING.md000066400000000000000000000033661360164303200150710ustar00rootroot00000000000000How to Contribute ================= The PHPMD project welcomes your contribution. There are several ways to help out: * Create an [issue](https://github.com/phpmd/phpmd/issues/) on GitHub, if you have found a bug or have an idea for a feature * Write test cases for open bug issues * Write patches for open bug/feature issues * Participate on the PHPMD IRC Channel There are a few guidelines that we need contributors to follow, so that we have a chance of keeping on top of things. * The code must follow the [PSR-2 coding standard](http://www.php-fig.org/psr/psr-2/). * All code changes should be covered by unit tests Issues ------ * Submit an [issue](https://github.com/phpmd/phpmd/issues/) * Make sure it does not already exist. * Clearly describe the issue including steps to reproduce, when it is a bug. * Make sure you note the PHPMD version you use. Coding Standard --------------- Make sure your code changes comply with the PSR-2 coding standard by using [PHP Codesniffer](https://github.com/squizlabs/PHP_CodeSniffer) from within your PHPMD folder: vendor/bin/phpcs -p --extensions=php --standard=PSR2 src > phpcs.txt Linux / OS X users may extend this command to exclude files, that are not part of a commit: vendor/bin/phpcs -p --extensions=php --standard=PSR2 --ignore=src/tests/resources $(git ls-files -om --exclude-standard | grep '\.php$') > phpcs.txt Check the ``phpcs.txt`` once it finished. Additional Resources -------------------- * [Existing issues](https://github.com/phpmd/phpmd/issues/) * [General GitHub documentation](https://help.github.com/) * [GitHub pull request documentation](https://help.github.com/articles/creating-a-pull-request/) * [PHPMD IRC Channel on freenode.org](http://webchat.freenode.net/?channels=phpmd) phpmd-2.8.1/LICENSE000066400000000000000000000027621360164303200136440ustar00rootroot00000000000000BSD 3-Clause License Copyright (c) 2008, Manuel Pichler All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. phpmd-2.8.1/README.rst000066400000000000000000000165771360164303200143370ustar00rootroot00000000000000PHPMD ===== PHPMD is a spin-off project of PHP Depend and aims to be a PHP equivalent of the well known Java tool PMD. PHPMD can be seen as an user friendly frontend application for the raw metrics stream measured by PHP Depend. https://phpmd.org .. image:: https://poser.pugx.org/phpmd/phpmd/v/stable.svg :target: https://packagist.org/packages/phpmd/phpmd :alt: Latest Stable Version .. image:: https://poser.pugx.org/phpmd/phpmd/license.svg :target: https://packagist.org/packages/phpmd/phpmd :alt: License .. image:: https://travis-ci.org/phpmd/phpmd.svg?branch=master :target: https://travis-ci.org/phpmd/phpmd :alt: Travis Build Status .. image:: https://ci.appveyor.com/api/projects/status/pc08owbun2y00kwk?svg=true :target: https://ci.appveyor.com/project/phpmd/phpmd :alt: AppVeyor Build Status .. image:: https://scrutinizer-ci.com/g/phpmd/phpmd/badges/build.png?b=master :target: https://scrutinizer-ci.com/g/phpmd/phpmd/build-status/master :alt: Scrutinizer Build Status .. image:: https://scrutinizer-ci.com/g/phpmd/phpmd/badges/quality-score.png?b=master :target: https://scrutinizer-ci.com/g/phpmd/phpmd/?branch=master :alt: Scrutinizer Code Quality .. image:: https://badges.gitter.im/phpmd/community.svg :target: https://gitter.im/phpmd/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge :alt: Chat with us on Gitter .. image:: https://poser.pugx.org/phpmd/phpmd/d/monthly :target: https://packagist.org/packages/phpmd/phpmd :alt: Monthly downloads .. image:: https://poser.pugx.org/phpmd/phpmd/downloads :target: https://packagist.org/packages/phpmd/phpmd :alt: Total downloads Installation ------------ See https://phpmd.org/download/index.html Command line usage ------------------ Type ``phpmd [filename|directory] [report format] [ruleset file]``, i.e: :: mapi@arwen ~ $ phpmd php/PDepend/DbusUI/ xml rulesets.xml While the ``rulesets.xml`` ruleset file could look like this:: My custom rule set that checks my code... The xml report would like like this:: Avoid unused parameters such as '$builder'. You can pass a file name or a directory name containing PHP source code to PHPMD. The `PHPMD Phar distribution`__ includes the rule set files inside its archive, even if the "rulesets/codesize.xml" parameter above looks like a filesystem reference. __ https://phpmd.org/download/index.html Command line options -------------------- - Notice that the default output is in XML, so you can redirect it to a file and XSLT it or whatever - You can also use shortened names to refer to the built-in rule sets, like this: :: phpmd PHP/Depend/DbusUI/ xml codesize - The command line interface also accepts the following optional arguments: - ``--minimumpriority`` - The rule priority threshold; rules with lower priority than they will not be used. - ``--reportfile`` - Sends the report output to the specified file, instead of the default output target ``STDOUT``. - ``--suffixes`` - Comma-separated string of valid source code filename extensions, e.g. php,phtml. - ``--exclude`` - Comma-separated string of patterns that are used to ignore directories. - ``--strict`` - Also report those nodes with a @SuppressWarnings annotation. - ``--ignore-violations-on-exit`` - will exit with a zero code, even if any violations are found. An example command line: :: phpmd PHP/Depend/DbusUI xml codesize --reportfile phpmd.xml --suffixes php,phtml Using multiple rule sets ```````````````````````` PHPMD uses so called rule sets that configure/define a set of rules which will be applied against the source under test. The default distribution of PHPMD is already shipped with a few default sets, that can be used out-of-box. You can call PHPMD's cli tool with a set's name to apply this configuration: :: ~ $ phpmd /path/to/source text codesize But what if you would like to apply more than one rule set against your source? You can also pass a list of rule set names, separated by comma to PHPMD's cli tool: :: ~ $ phpmd /path/to/source text codesize,unusedcode,naming You can also mix custom `rule set files`__ with build-in rule sets: :: ~ $ phpmd /path/to/source text codesize,/my/rules.xml __ https://phpmd.org/documentation/creating-a-ruleset.html That's it. With this behavior you can specify you own combination of rule sets that will check the source code. Using multiple source files and folders ``````````````````````````````````````` PHPMD also allowes you to specify multiple source directories in case you want to create one output for certain parts of your code :: ~ $ phpmd /path/to/code,index.php,/another/place/with/code text codesize Exit codes ---------- PHPMD's command line tool currently defines three different exit codes. - *0*, This exit code indicates that everything worked as expected. This means there was no error/exception and PHPMD hasn't detected any rule violation in the code under test. - *1*, This exit code indicates that an error/exception occured which has interrupted PHPMD during execution. - *2*, This exit code means that PHPMD has processed the code under test without the occurence of an error/exception, but it has detected rule violations in the analyzed source code. You can also prevent this behaviour with the ``--ignore-violations-on-exit`` flag, which will result to a *0* even if any violations are found. Renderers --------- At the moment PHPMD comes with the following renderers: - *xml*, which formats the report as XML. - *text*, simple textual format. - *html*, single HTML file with possible problems. - *json*, formats JSON report. - *ansi*, a command line friendly format. PHPMD for enterprise -------------------- Available as part of the Tidelift Subscription. The maintainers of ``PHPMD`` and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. `Learn more.`__ __ https://tidelift.com/subscription/pkg/packagist-phpmd-phpmd?utm_source=packagist-phpmd-phpmd&utm_medium=referral&utm_campaign=enterprise&utm_term=repo phpmd-2.8.1/apigen.neon000066400000000000000000000003551360164303200147570ustar00rootroot00000000000000# ApiGen configuration source: - src/main/php title: "PHPMD" templateTheme: bootstrap # Options accessLevels: [public, protected] sourceCode: true download: false php: false debug: true internal: true deprecated: true todo: true phpmd-2.8.1/appveyor.yml000066400000000000000000000013151360164303200152200ustar00rootroot00000000000000build: false shallow_clone: false platform: 'x86' clone_folder: C:\projects\phpmd branches: except: - gh-pages install: - ps: Set-Service wuauserv -StartupType Manual - cinst -y OpenSSL.Light - SET PATH=C:\Program Files\OpenSSL;%PATH% - cinst -y php -version 7.1.14 - cd c:\tools\php71 - copy php.ini-production php.ini - echo date.timezone="UTC" >> php.ini - echo extension_dir=ext >> php.ini - echo extension=php_openssl.dll >> php.ini - cd C:\projects\phpmd - SET PATH=C:\tools\php71;%PATH% - php -r "readfile('http://getcomposer.org/installer');" | php - php composer.phar install --prefer-source --no-interaction test_script: - cd C:\projects\phpmd - vendor\bin\phpunit.bat phpmd-2.8.1/build.properties000066400000000000000000000013121360164303200160420ustar00rootroot00000000000000project.dir = project.uri = phpmd.org project.name = phpmd project.version = 2.8.1 project.stability = stable # Disable pear support project.pear.uri = pear.example.com vendor.dir.includes = symfony/**/*,composer/**/*,pdepend/**/*,autoload.php vendor.dir.excludes = symfony/**/Tests/**/* # Default coding standard codesniffer.standard = PSR2 # Location of the version control system project.scm.uri = github.com/${project.name}/${project.name}/commit # Execute the following command for pdepend profiling profile.command = ${basedir}/src/bin/phpmd '/opt/Sources/PHP/Flow3/Packages/Framework' xml naming,codesize,unusedcode,design --reportfile pmd.xml phpunit.package.name = phpunit-4.8.28 phpmd-2.8.1/build.xml000066400000000000000000000120311360164303200144460ustar00rootroot00000000000000 phpmd-2.8.1/composer.json000066400000000000000000000034261360164303200153570ustar00rootroot00000000000000{ "name": "phpmd/phpmd", "description": "PHPMD is a spin-off project of PHP Depend and aims to be a PHP equivalent of the well known Java tool PMD.", "keywords": [ "phpmd", "pdepend", "pmd", "mess detection", "mess detector" ], "type": "library", "license": "BSD-3-Clause", "homepage": "https://phpmd.org/", "authors": [ { "name": "Manuel Pichler", "homepage": "https://github.com/manuelpichler", "email": "github@manuel-pichler.de", "role": "Project Founder" }, { "name": "Marc Würth", "homepage": "https://github.com/ravage84", "email": "ravage@bluewin.ch", "role": "Project Maintainer" }, { "name": "Other contributors", "homepage": "https://github.com/phpmd/phpmd/graphs/contributors", "role": "Contributors" } ], "support": { "irc": "irc://irc.freenode.org/phpmd" }, "minimum-stability": "stable", "require": { "php": ">=5.3.9", "pdepend/pdepend": "^2.6", "ext-xml": "*", "composer/xdebug-handler": "^1.0" }, "require-dev": { "phpunit/phpunit": "^4.8.36 || ^5.7.27", "squizlabs/php_codesniffer": "^2.0", "mikey179/vfsstream": "^1.6.4", "gregwar/rst": "^1.0", "easy-doc/easy-doc": "0.0.0 || ^1.3.2" }, "autoload": { "psr-0": { "PHPMD\\": "src/main/php" } }, "bin": [ "src/bin/phpmd" ], "scripts": { "test": "phpunit", "cs-check": "phpcs -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 ./src/main/php ./src/test/php", "cs-fix": "phpcbf -p --standard=PSR2 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 ./src/main/php ./src/test/php", "build-website": "easy-doc build src/site/config.php --verbose" } } phpmd-2.8.1/pdepend.xml.dist000066400000000000000000000006731360164303200157410ustar00rootroot00000000000000 memory phpmd-2.8.1/phpunit.xml.dist000066400000000000000000000006361360164303200160100ustar00rootroot00000000000000 src/test/php src/main/php phpmd-2.8.1/setup/000077500000000000000000000000001360164303200137705ustar00rootroot00000000000000phpmd-2.8.1/src/000077500000000000000000000000001360164303200134175ustar00rootroot00000000000000phpmd-2.8.1/src/bin/000077500000000000000000000000001360164303200141675ustar00rootroot00000000000000phpmd-2.8.1/src/bin/phpmd000077500000000000000000000200571360164303200152310ustar00rootroot00000000000000#!/usr/bin/env php . * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ use Composer\XdebugHandler\XdebugHandler; use PHPMD\TextUI\Command; if (file_exists(__DIR__ . '/../../../../autoload.php')) { // phpmd is part of a composer installation require_once __DIR__ . '/../../../../autoload.php'; } else { require_once __DIR__ . '/../../vendor/autoload.php'; // PEAR installation workaround if (strpos('@package_version@', '@package_version') === 0) { set_include_path( dirname(__FILE__) . '/../main/php' . PATH_SEPARATOR . dirname(__FILE__) . '/../../vendor/pdepend/pdepend/src/main/php' . PATH_SEPARATOR . '.' ); } } // Restart if xdebug is loading, unless the environment variable PHPMD_ALLOW_XDEBUG is set. $xdebug = new XdebugHandler('PHPMD'); $xdebug->check(); unset($xdebug); if (!ini_get('date.timezone')) { date_default_timezone_set('UTC'); } class_alias('PHPMD\\AbstractNode', 'PHP_PMD_AbstractNode'); class_alias('PHPMD\\AbstractRenderer', 'PHP_PMD_AbstractRenderer'); class_alias('PHPMD\\AbstractRule', 'PHP_PMD_AbstractRule'); class_alias('PHPMD\\Parser', 'PHP_PMD_Parser'); class_alias('PHPMD\\ParserFactory', 'PHP_PMD_ParserFactory'); class_alias('PHPMD\\ProcessingError', 'PHP_PMD_ProcessingError'); class_alias('PHPMD\\Report', 'PHP_PMD_Report'); class_alias('PHPMD\\Rule', 'PHP_PMD_Rule'); class_alias('PHPMD\\RuleClassFileNotFoundException', 'PHP_PMD_RuleClassFileNotFoundException'); class_alias('PHPMD\\RuleClassNotFoundException', 'PHP_PMD_RuleClassNotFoundException'); class_alias('PHPMD\\RuleSet', 'PHP_PMD_RuleSet'); class_alias('PHPMD\\RuleSetFactory', 'PHP_PMD_RuleSetFactory'); class_alias('PHPMD\\RuleSetNotFoundException', 'PHP_PMD_RuleSetNotFoundException'); class_alias('PHPMD\\RuleViolation', 'PHP_PMD_RuleViolation'); class_alias('PHPMD\\Node\\AbstractCallableNode', 'PHP_PMD_Node_AbstractCallable'); class_alias('PHPMD\\Node\\AbstractNode', 'PHP_PMD_Node_AbstractNode'); class_alias('PHPMD\\Node\\AbstractTypeNode', 'PHP_PMD_Node_AbstractType'); class_alias('PHPMD\\Node\\ASTNode', 'PHP_PMD_Node_ASTNode'); class_alias('PHPMD\\Node\\Annotation', 'PHP_PMD_Node_Annotation'); class_alias('PHPMD\\Node\\Annotations', 'PHP_PMD_Node_Annotations'); class_alias('PHPMD\\Node\\ClassNode', 'PHP_PMD_Node_Class'); class_alias('PHPMD\\Node\\FunctionNode', 'PHP_PMD_Node_Function'); class_alias('PHPMD\\Node\\InterfaceNode', 'PHP_PMD_Node_Interface'); class_alias('PHPMD\\Node\\MethodNode', 'PHP_PMD_Node_Method'); class_alias('PHPMD\\Node\\TraitNode', 'PHP_PMD_Node_Trait'); class_alias('PHPMD\\Renderer\\HTMLRenderer', 'PHP_PMD_Renderer_HTMLRenderer'); class_alias('PHPMD\\Renderer\\TextRenderer', 'PHP_PMD_Renderer_TextRenderer'); class_alias('PHPMD\\Renderer\\XMLRenderer', 'PHP_PMD_Renderer_XMLRenderer'); class_alias('PHPMD\\Renderer\\JSONRenderer', 'PHP_PMD_Renderer_JSONRenderer'); class_alias('PHPMD\\Rule\\AbstractLocalVariable', 'PHP_PMD_Rule_AbstractLocalVariable'); class_alias('PHPMD\\Rule\\CyclomaticComplexity', 'PHP_PMD_Rule_CyclomaticComplexity'); class_alias('PHPMD\\Rule\\ClassAware', 'PHP_PMD_Rule_IClassAware'); class_alias('PHPMD\\Rule\\ExcessivePublicCount', 'PHP_PMD_Rule_ExcessivePublicCount'); class_alias('PHPMD\\Rule\\FunctionAware', 'PHP_PMD_Rule_IFunctionAware'); class_alias('PHPMD\\Rule\\InterfaceAware', 'PHP_PMD_Rule_IInterfaceAware'); class_alias('PHPMD\\Rule\\MethodAware', 'PHP_PMD_Rule_IMethodAware'); class_alias('PHPMD\\Rule\\UnusedFormalParameter', 'PHP_PMD_Rule_UnusedFormalParameter'); class_alias('PHPMD\\Rule\\UnusedLocalVariable', 'PHP_PMD_Rule_UnusedLocalVariable'); class_alias('PHPMD\\Rule\\UnusedPrivateField', 'PHP_PMD_Rule_UnusedPrivateField'); class_alias('PHPMD\\Rule\\UnusedPrivateMethod', 'PHP_PMD_Rule_UnusedPrivateMethod'); class_alias('PHPMD\\Rule\\CleanCode\\BooleanArgumentFlag', 'PHP_PMD_Rule_CleanCode_BooleanArgumentFlag'); class_alias('PHPMD\\Rule\\CleanCode\\ElseExpression', 'PHP_PMD_Rule_CleanCode_ElseExpression'); class_alias('PHPMD\\Rule\\CleanCode\\StaticAccess', 'PHP_PMD_Rule_CleanCode_StaticAccess'); class_alias('PHPMD\\Rule\\CleanCode\\UndefinedVariable', 'PHP_PMD_Rule_CleanCode_UndefinedVariable'); class_alias('PHPMD\\Rule\\Controversial\\CamelCaseClassName', 'PHP_PMD_Rule_Controversial_CamelCaseClassName'); class_alias('PHPMD\\Rule\\Controversial\\CamelCaseMethodName', 'PHP_PMD_Rule_Controversial_CamelCaseMethodName'); class_alias('PHPMD\\Rule\\Controversial\\CamelCaseParameterName', 'PHP_PMD_Rule_Controversial_CamelCaseParameterName'); class_alias('PHPMD\\Rule\\Controversial\\CamelCasePropertyName', 'PHP_PMD_Rule_Controversial_CamelCasePropertyName'); class_alias('PHPMD\\Rule\\Controversial\\CamelCaseVariableName', 'PHP_PMD_Rule_Controversial_CamelCaseVariableName'); class_alias('PHPMD\\Rule\\Controversial\\Superglobals', 'PHP_PMD_Rule_Controversial_Superglobals'); class_alias('PHPMD\\Rule\\Design\\CouplingBetweenObjects', 'PHP_PMD_Rule_Design_CouplingBetweenObjects'); class_alias('PHPMD\\Rule\\Design\\DepthOfInheritance', 'PHP_PMD_Rule_Design_DepthOfInheritance'); class_alias('PHPMD\\Rule\\Design\\EvalExpression', 'PHP_PMD_Rule_Design_EvalExpression'); class_alias('PHPMD\\Rule\\Design\\ExitExpression', 'PHP_PMD_Rule_Design_ExitExpression'); class_alias('PHPMD\\Rule\\Design\\GotoStatement', 'PHP_PMD_Rule_Design_GotoStatement'); class_alias('PHPMD\\Rule\\Design\\LongClass', 'PHP_PMD_Rule_Design_LongClass'); class_alias('PHPMD\\Rule\\Design\\LongMethod', 'PHP_PMD_Rule_Design_LongMethod'); class_alias('PHPMD\\Rule\\Design\\LongParameterList', 'PHP_PMD_Rule_Design_LongParameterList'); class_alias('PHPMD\\Rule\\Design\\NpathComplexity', 'PHP_PMD_Rule_Design_NpathComplexity'); class_alias('PHPMD\\Rule\\Design\\NumberOfChildren', 'PHP_PMD_Rule_Design_NumberOfChildren'); class_alias('PHPMD\\Rule\\Design\\TooManyFields', 'PHP_PMD_Rule_Design_TooManyFields'); class_alias('PHPMD\\Rule\\Design\\TooManyMethods', 'PHP_PMD_Rule_Design_TooManyMethods'); class_alias('PHPMD\\Rule\\Design\\WeightedMethodCount', 'PHP_PMD_Rule_Design_WeightedMethodCount'); class_alias('PHPMD\\Rule\\Naming\\BooleanGetMethodName', 'PHP_PMD_Rule_Naming_BooleanGetMethodName'); class_alias('PHPMD\\Rule\\Naming\\ConstantNamingConventions', 'PHP_PMD_Rule_Naming_ConstantNamingConventions'); class_alias('PHPMD\\Rule\\Naming\\ConstructorWithNameAsEnclosingClass', 'PHP_PMD_Rule_Naming_ConstructorWithNameAsEnclosingClass'); class_alias('PHPMD\\Rule\\Naming\\LongVariable', 'PHP_PMD_Rule_Naming_LongVariable'); class_alias('PHPMD\\Rule\\Naming\\ShortMethodName', 'PHP_PMD_Rule_Naming_ShortMethodName'); class_alias('PHPMD\\Rule\\Naming\\ShortVariable', 'PHP_PMD_Rule_Naming_ShortVariable'); class_alias('PHPMD\\TextUI\\Command', 'PHP_PMD_TextUI_Command'); class_alias('PHPMD\\TextUI\\CommandLineOptions', 'PHP_PMD_TextUI_CommandLineOptions'); class_alias('PHPMD\\Writer\\StreamWriter', 'PHP_PMD_Writer_Stream'); // Allow as much memory as possible by default if (extension_loaded('suhosin') && is_numeric(ini_get('suhosin.memory_limit'))) { $limit = ini_get('memory_limit'); if (preg_match('(^(\d+)([BKMGT]))', $limit, $match)) { $shift = array('B' => 0, 'K' => 10, 'M' => 20, 'G' => 30, 'T' => 40); $limit = ($match[1] * (1 << $shift[$match[2]])); } if (ini_get('suhosin.memory_limit') > $limit && $limit > -1) { ini_set('memory_limit', ini_get('suhosin.memory_limit')); } } else { ini_set('memory_limit', -1); } // Check php setup for cli arguments if (!isset($_SERVER['argv']) && !isset($argv)) { fwrite(STDERR, 'Please enable the "register_argc_argv" directive in your php.ini', PHP_EOL); exit(1); } else if (!isset($argv)) { $argv = $_SERVER['argv']; } // Run command line interface exit(Command::main($argv)); phpmd-2.8.1/src/bin/phpmd.bat000066400000000000000000000013231360164303200157660ustar00rootroot00000000000000@echo off REM This file is part of PHP Mess Detector. REM REM Copyright (c) Manuel Pichler . REM All rights reserved. REM REM Licensed under BSD License REM For full copyright and license information, please see the LICENSE file. REM Redistributions of files must retain the above copyright notice. REM REM @author Manuel Pichler REM @copyright Manuel Pichler. All rights reserved. REM @license https://opensource.org/licenses/bsd-license.php BSD License REM @link http://phpmd.org/ if "%PHPBIN%" == "" set PHPBIN=@php_bin@ if not exist "%PHPBIN%" if "%PHP_PEAR_PHP_BIN%" neq "" goto USE_PEAR_PATH GOTO RUN :USE_PEAR_PATH set PHPBIN=%PHP_PEAR_PHP_BIN% :RUN "%PHPBIN%" "@bin_dir@\phpmd" %* phpmd-2.8.1/src/conf/000077500000000000000000000000001360164303200143445ustar00rootroot00000000000000phpmd-2.8.1/src/conf/phar_bootstrap.stub000066400000000000000000000020371360164303200202740ustar00rootroot00000000000000#!/usr/bin/env php . * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ /** * Define global constant that marks this as PHPMD phar release. */ define('PHP_PMD_RELEASE', 'phar'); Phar::mapPhar('${archive.alias}'); // Configure include path to use this phar set_include_path('phar://${archive.alias}/' . PATH_SEPARATOR . get_include_path()); if (isset($argv) && realpath($argv[0]) === __FILE__) { // Load command line utility include_once 'phar://${archive.alias}/vendor/autoload.php'; // Run command line interface exit(\PHPMD\TextUI\Command::main($argv)); } __HALT_COMPILER(); phpmd-2.8.1/src/main/000077500000000000000000000000001360164303200143435ustar00rootroot00000000000000phpmd-2.8.1/src/main/php/000077500000000000000000000000001360164303200151325ustar00rootroot00000000000000phpmd-2.8.1/src/main/php/PHPMD/000077500000000000000000000000001360164303200160025ustar00rootroot00000000000000phpmd-2.8.1/src/main/php/PHPMD/AbstractNode.php000066400000000000000000000152721360164303200210730ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD; use PHPMD\Node\ASTNode; /** * This is an abstract base class for PHPMD code nodes, it is just a wrapper * around PDepend's object model. */ abstract class AbstractNode { /** * @var \PDepend\Source\AST\ASTArtifact|\PDepend\Source\AST\ASTNode $node */ private $node = null; /** * The collected metrics for this node. * * @var array */ private $metrics = null; /** * Constructs a new PHPMD node. * * @param \PDepend\Source\AST\ASTArtifact|\PDepend\Source\AST\ASTNode $node */ public function __construct($node) { $this->node = $node; } /** * The magic call method is used to pipe requests from rules direct * to the underlying PDepend AST node. * * @param string $name * @param array $args * @return mixed * @throws \BadMethodCallException When the underlying PDepend node * does not contain a method named $name. */ public function __call($name, array $args) { $node = $this->getNode(); if (!method_exists($node, $name)) { throw new \BadMethodCallException( sprintf('Invalid method %s() called.', $name) ); } return call_user_func_array(array($node, $name), $args); } /** * Returns the parent of this node or null when no parent node * exists. * * @return ASTNode */ public function getParent() { if (($node = $this->node->getParent()) === null) { return null; } return new ASTNode($node, $this->getFileName()); } /** * Returns a child node at the given index. * * @param integer $index The child offset. * @return \PHPMD\Node\ASTNode */ public function getChild($index) { return new ASTNode( $this->node->getChild($index), $this->getFileName() ); } /** * Returns the first child of the given type or null when this node * has no child of the given type. * * @param string $type The searched child type. * @return \PHPMD\AbstractNode */ public function getFirstChildOfType($type) { $node = $this->node->getFirstChildOfType('PDepend\Source\AST\AST' . $type); if ($node === null) { return null; } return new ASTNode($node, $this->getFileName()); } /** * Searches recursive for all children of this node that are of the given * type. * * @param string $type The searched child type. * @return \PHPMD\AbstractNode[] */ public function findChildrenOfType($type) { $children = $this->node->findChildrenOfType('PDepend\Source\AST\AST' . $type); $nodes = array(); foreach ($children as $child) { $nodes[] = new ASTNode($child, $this->getFileName()); } return $nodes; } /** * Tests if this node represents the the given type. * * @param string $type The expected node type. * @return boolean */ public function isInstanceOf($type) { $class = 'PDepend\Source\AST\AST' . $type; return ($this->node instanceof $class); } /** * Returns the image of the underlying node. * * @return string */ public function getImage() { return $this->node->getName(); } /** * Returns the source name for this node, maybe a class or interface name, * or a package, method, function name. * * @return string */ public function getName() { return $this->node->getName(); } /** * Returns the begin line for this node in the php source code file. * * @return integer */ public function getBeginLine() { return $this->node->getStartLine(); } /** * Returns the end line for this node in the php source code file. * * @return integer */ public function getEndLine() { return $this->node->getEndLine(); } /** * Returns the name of the declaring source file. * * @return string */ public function getFileName() { return (string) $this->node->getCompilationUnit()->getFileName(); } /** * Returns the wrapped PDepend node instance. * * @return \PDepend\Source\AST\ASTArtifact */ public function getNode() { return $this->node; } /** * Returns a textual representation/name for the concrete node type. * * @return string */ public function getType() { $type = explode('\\', get_class($this)); return preg_replace('(node$)', '', strtolower(array_pop($type))); } /** * This method will return the metric value for the given identifier or * null when no such metric exists. * * @param string $name The metric name or abbreviation. * @return mixed */ public function getMetric($name) { if (isset($this->metrics[$name])) { return $this->metrics[$name]; } return null; } /** * This method will set the metrics for this node. * * @param array $metrics The collected node metrics. * @return void */ public function setMetrics(array $metrics) { if ($this->metrics === null) { $this->metrics = $metrics; } } /** * Checks if this node has a suppressed annotation for the given rule * instance. * * @param \PHPMD\Rule $rule * @return boolean */ abstract public function hasSuppressWarningsAnnotationFor(Rule $rule); /** * Returns the full qualified name of a class, an interface, a method or * a function. * * @return string */ abstract public function getFullQualifiedName(); /** * Returns the name of the parent type or null when this node has no * parent type. * * @return string */ abstract public function getParentName(); /** * Returns the name of the parent package. * * @return string */ abstract public function getNamespaceName(); } phpmd-2.8.1/src/main/php/PHPMD/AbstractRenderer.php000066400000000000000000000035031360164303200217460ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD; /** * Abstract base class for PHPMD rendering engines. */ abstract class AbstractRenderer { /** * The associated output writer instance. * * @var \PHPMD\AbstractWriter */ private $writer = null; /** * Returns the associated output writer instance. * * @return \PHPMD\AbstractWriter */ public function getWriter() { return $this->writer; } /** * Returns the associated output writer instance. * * @param \PHPMD\AbstractWriter $writer * @return void */ public function setWriter(AbstractWriter $writer) { $this->writer = $writer; } /** * This method will be called on all renderers before the engine starts the * real report processing. * * @return void */ public function start() { // Just a hook } /** * This method will be called when the engine has finished the source analysis * phase. * * @param \PHPMD\Report $report * @return void */ abstract public function renderReport(Report $report); /** * This method will be called the engine has finished the report processing * for all registered renderers. * * @return void */ public function end() { // Just a hook } } phpmd-2.8.1/src/main/php/PHPMD/AbstractRule.php000066400000000000000000000216461360164303200211170ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD; use PHPMD\Node\ClassNode; /** * This is the abstract base class for pmd rules. * * @SuppressWarnings(PHPMD) */ abstract class AbstractRule implements Rule { /** * The name for this rule instance. * * @var string $_name */ private $name = ''; /** * The violation message text for this rule. * * @var string */ private $message = ''; /** * The version since when this rule is available. * * @var string */ private $since = null; /** * An url will external information for this rule. * * @var string */ private $externalInfoUrl = ''; /** * An optional description for this rule. * * @var string */ private $description = ''; /** * A list of code examples for this rule. * * @var array(string) */ private $examples = array(); /** * The name of the parent rule-set instance. * * @var string */ private $ruleSetName = ''; /** * The priority of this rule. * * @var integer */ private $priority = self::LOWEST_PRIORITY; /** * Configuration properties for this rule instance. * * @var array(string=>string) */ private $properties = array(); /** * The report for object for this rule. * * @var \PHPMD\Report */ private $report = null; /** * Returns the name for this rule instance. * * @return string */ public function getName() { return $this->name; } /** * Sets the name for this rule instance. * * @param string $name The rule name. * @return void */ public function setName($name) { $this->name = $name; } /** * Returns the version since when this rule is available or null. * * @return string */ public function getSince() { return $this->since; } /** * Sets the version since when this rule is available. * * @param string $since The version number. * @return void */ public function setSince($since) { $this->since = $since; } /** * Returns the violation message text for this rule. * * @return string */ public function getMessage() { return $this->message; } /** * Sets the violation message text for this rule. * * @param string $message The violation message * @return void */ public function setMessage($message) { $this->message = $message; } /** * Returns an url will external information for this rule. * * @return string */ public function getExternalInfoUrl() { return $this->externalInfoUrl; } /** * Sets an url will external information for this rule. * * @param string $externalInfoUrl The info url. * @return void */ public function setExternalInfoUrl($externalInfoUrl) { $this->externalInfoUrl = $externalInfoUrl; } /** * Returns the description text for this rule instance. * * @return string */ public function getDescription() { return $this->description; } /** * Sets the description text for this rule instance. * * @param string $description The description text. * @return void */ public function setDescription($description) { $this->description = $description; } /** * Returns a list of examples for this rule. * * @return string[] */ public function getExamples() { return $this->examples; } /** * Adds a code example for this rule. * * @param string $example The code example. * @return void */ public function addExample($example) { $this->examples[] = $example; } /** * Returns the priority of this rule. * * @return integer */ public function getPriority() { return $this->priority; } /** * Set the priority of this rule. * * @param integer $priority The rule priority * @return void */ public function setPriority($priority) { $this->priority = $priority; } /** * Returns the name of the parent rule-set instance. * * @return string */ public function getRuleSetName() { return $this->ruleSetName; } /** * Sets the name of the parent rule set instance. * * @param string $ruleSetName The rule-set name. * @return void */ public function setRuleSetName($ruleSetName) { $this->ruleSetName = $ruleSetName; } /** * Returns the violation report for this rule. * * @return \PHPMD\Report */ public function getReport() { return $this->report; } /** * Sets the violation report for this rule. * * @param \PHPMD\Report $report * @return void */ public function setReport(Report $report) { $this->report = $report; } /** * Adds a configuration property to this rule instance. * * @param string $name * @param string $value * @return void */ public function addProperty($name, $value) { $this->properties[$name] = $value; } /** * Returns the value of a configured property as a boolean or throws an * exception when no property with $name exists. * * @param string $name * @return boolean * @throws \OutOfBoundsException When no property for $name exists. */ public function getBooleanProperty($name) { if (isset($this->properties[$name])) { return in_array($this->properties[$name], array('true', 'on', 1)); } throw new \OutOfBoundsException('Property "' . $name . '" does not exist.'); } /** * Returns the value of a configured property as an integer or throws an * exception when no property with $name exists. * * @param string $name * @return integer * @throws \OutOfBoundsException When no property for $name exists. */ public function getIntProperty($name) { if (isset($this->properties[$name])) { return (int) $this->properties[$name]; } throw new \OutOfBoundsException('Property "' . $name . '" does not exist.'); } /** * Returns the raw string value of a configured property or throws an * exception when no property with $name exists. * * @param string $name * @return string * @throws \OutOfBoundsException When no property for $name exists. */ public function getStringProperty($name) { if (isset($this->properties[$name])) { return $this->properties[$name]; } throw new \OutOfBoundsException('Property "' . $name . '" does not exist.'); } /** * This method adds a violation to all reports for this violation type and * for the given $node instance. * * @param \PHPMD\AbstractNode $node * @param array $args * @param mixed $metric * @return void */ protected function addViolation( AbstractNode $node, array $args = array(), $metric = null ) { $search = array(); $replace = array(); foreach ($args as $index => $value) { $search[] = '{' . $index . '}'; $replace[] = $value; } $message = str_replace($search, $replace, $this->message); $ruleViolation = new RuleViolation($this, $node, $message, $metric); $this->report->addRuleViolation($ruleViolation); } /** * Apply the current rule on each method of a class node. * * @param ClassNode $node class node containing methods. */ protected function applyOnClassMethods(ClassNode $node) { foreach ($node->getMethods() as $method) { if ($method->hasSuppressWarningsAnnotationFor($this)) { continue; } $this->apply($method); } } /** * This method should implement the violation analysis algorithm of concrete * rule implementations. All extending classes must implement this method. * * @param \PHPMD\AbstractNode $node * @return void */ abstract public function apply(AbstractNode $node); } phpmd-2.8.1/src/main/php/PHPMD/AbstractWriter.php000066400000000000000000000014221360164303200214520ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD; /** * This is abstract base class for an output writer. */ abstract class AbstractWriter { /** * Writes a data string to the concrete output. * * @param string $data * @return void */ abstract public function write($data); } phpmd-2.8.1/src/main/php/PHPMD/Node/000077500000000000000000000000001360164303200166675ustar00rootroot00000000000000phpmd-2.8.1/src/main/php/PHPMD/Node/ASTNode.php000066400000000000000000000050371360164303200206420ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Node; use PHPMD\Rule; /** * Wrapper around a PHP_Depend ast node. */ class ASTNode extends \PHPMD\AbstractNode { /** * The source file of this node. * * @var string */ private $fileName = null; /** * Constructs a new ast node instance. * * @param \PDepend\Source\AST\ASTNode $node * @param string $fileName */ public function __construct(\PDepend\Source\AST\ASTNode $node, $fileName) { parent::__construct($node); $this->fileName = $fileName; } /** * Checks if this node has a suppressed annotation for the given rule * instance. * * @param \PHPMD\Rule $rule * @return boolean * @SuppressWarnings("PMD.UnusedFormalParameter") */ public function hasSuppressWarningsAnnotationFor(Rule $rule) { return false; } /** * Returns the source name for this node, maybe a class or interface name, * or a package, method, function name. * * @return string */ public function getName() { return $this->getImage(); } /** * Returns the image of the underlying node. * * @return string */ public function getImage() { return $this->getNode()->getImage(); } /** * Returns the name of the declaring source file. * * @return string */ public function getFileName() { return $this->fileName; } /** * Returns the name of the parent type or null when this node has no * parent type. * * @return string */ public function getParentName() { return null; } /** * Returns the name of the parent namespace. * * @return string */ public function getNamespaceName() { return null; } /** * Returns the full qualified name of a class, an interface, a method or * a function. * * @return string */ public function getFullQualifiedName() { return null; } } phpmd-2.8.1/src/main/php/PHPMD/Node/AbstractCallableNode.php000066400000000000000000000022201360164303200233650ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Node; use PDepend\Source\AST\AbstractASTCallable; /** * Abstract base class for PHP_Depend function and method wrappers. */ abstract class AbstractCallableNode extends AbstractNode { /** * Constructs a new callable wrapper. * * @param \PDepend\Source\AST\AbstractASTCallable $node */ public function __construct(AbstractASTCallable $node) { parent::__construct($node); } /** * Returns the number of parameters in the callable signature. * * @return integer */ public function getParameterCount() { return count($this->getNode()->getParameters()); } } phpmd-2.8.1/src/main/php/PHPMD/Node/AbstractNode.php000066400000000000000000000022741360164303200217560ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Node; use PHPMD\Rule; /** * Abstract base class for all code nodes. */ abstract class AbstractNode extends \PHPMD\AbstractNode { /** * Annotations associated with node instance. * * @var \PHPMD\Node\Annotations */ private $annotations = null; /** * Checks if this node has a suppressed annotation for the given rule * instance. * * @param \PHPMD\Rule $rule * @return boolean */ public function hasSuppressWarningsAnnotationFor(Rule $rule) { if ($this->annotations === null) { $this->annotations = new Annotations($this); } return $this->annotations->suppresses($rule); } } phpmd-2.8.1/src/main/php/PHPMD/Node/AbstractTypeNode.php000066400000000000000000000052431360164303200226170ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Node; use PDepend\Source\AST\AbstractASTClassOrInterface; /** * Abstract base class for classes and interfaces. */ abstract class AbstractTypeNode extends AbstractNode { /** * @var \PDepend\Source\AST\AbstractASTClassOrInterface */ private $node; /** * Constructs a new generic class or interface node. * * @param \PDepend\Source\AST\AbstractASTClassOrInterface $node */ public function __construct(AbstractASTClassOrInterface $node) { parent::__construct($node); $this->node = $node; } /** * Returns an array with all methods defined in the context class or * interface. * * @return \PHPMD\Node\MethodNode[] */ public function getMethods() { $methods = array(); foreach ($this->node->getMethods() as $method) { $methods[] = new MethodNode($method); } return $methods; } /** * Returns an array with the names of all methods within this class or * interface node. * * @return string[] */ public function getMethodNames() { $names = array(); foreach ($this->node->getMethods() as $method) { $names[] = $method->getName(); } return $names; } /** * Returns the number of constants declared in this type. * * @return integer */ public function getConstantCount() { return count($this->node->getConstants()); } /** * Returns the name of the parent namespace. * * @return string */ public function getNamespaceName() { return $this->node->getNamespace()->getName(); } /** * Returns the name of the parent type or null when this node has no * parent type. * * @return string */ public function getParentName() { return null; } /** * Returns the full qualified name of a class, an interface, a method or * a function. * * @return string */ public function getFullQualifiedName() { return sprintf('%s\\%s', $this->getNamespaceName(), $this->getName()); } } phpmd-2.8.1/src/main/php/PHPMD/Node/Annotation.php000066400000000000000000000037071360164303200215210ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Node; use PHPMD\Rule; /** * Simple code annotation class. */ class Annotation { /** * Name of the suppress warnings annotation. */ const SUPPRESS_ANNOTATION = 'suppressWarnings'; /** * The annotation name. * * @var string */ private $name = null; /** * The annotation value. * * @var string */ private $value = null; /** * Constructs a new annotation instance. * * @param string $name * @param string $value */ public function __construct($name, $value) { $this->name = $name; $this->value = trim($value, '" '); } /** * Checks if this annotation suppresses the given rule. * * @param \PHPMD\Rule $rule * @return boolean */ public function suppresses(Rule $rule) { if (lcfirst($this->name) === self::SUPPRESS_ANNOTATION) { return $this->isSuppressed($rule); } return false; } /** * Checks if this annotation suppresses the given rule. * * @param \PHPMD\Rule $rule * @return boolean */ private function isSuppressed(Rule $rule) { if (in_array($this->value, array('PHPMD', 'PMD'))) { return true; } elseif (preg_match('/^(PH)?PMD\.' . $rule->getName() . '/', $this->value)) { return true; } return (stripos($rule->getName(), $this->value) !== false); } } phpmd-2.8.1/src/main/php/PHPMD/Node/Annotations.php000066400000000000000000000033111360164303200216730ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Node; use PHPMD\Rule; /** * Collection of code annotations. */ class Annotations { /** * Detected annotations. * * @var \PHPMD\Node\Annotation[] */ private $annotations = array(); /** * Regexp used to extract code annotations. * * @var string */ private $regexp = '(@([a-z_][a-z0-9_]+)\(([^\)]+)\))i'; /** * Constructs a new collection instance. * * @param \PHPMD\AbstractNode $node */ public function __construct(\PHPMD\AbstractNode $node) { preg_match_all($this->regexp, $node->getDocComment(), $matches); foreach (array_keys($matches[0]) as $i) { $name = $matches[1][$i]; $value = trim($matches[2][$i], '" '); $this->annotations[] = new Annotation($name, $value); } } /** * Checks if one of the annotations suppresses the given rule. * * @param \PHPMD\Rule $rule * @return boolean */ public function suppresses(Rule $rule) { foreach ($this->annotations as $annotation) { if ($annotation->suppresses($rule)) { return true; } } return false; } } phpmd-2.8.1/src/main/php/PHPMD/Node/ClassNode.php000066400000000000000000000016711360164303200212600ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Node; use PDepend\Source\AST\ASTClass; /** * Wrapper around PHP_Depend's class objects. */ class ClassNode extends AbstractTypeNode { /** * The type of this class. */ const CLAZZ = __CLASS__; /** * Constructs a new class wrapper node. * * @param \PDepend\Source\AST\ASTClass $node */ public function __construct(ASTClass $node) { parent::__construct($node); } } phpmd-2.8.1/src/main/php/PHPMD/Node/FunctionNode.php000066400000000000000000000030601360164303200217720ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Node; use PDepend\Source\AST\ASTFunction; /** * Wrapper around a PDepend function node. */ class FunctionNode extends AbstractCallableNode { /** * Constructs a new function wrapper. * * @param \PDepend\Source\AST\ASTFunction $node */ public function __construct(ASTFunction $node) { parent::__construct($node); } /** * Returns the name of the parent package. * * @return string */ public function getNamespaceName() { return $this->getNode()->getNamespace()->getName(); } /** * Returns the name of the parent type or null when this node has no * parent type. * * @return string */ public function getParentName() { return null; } /** * Returns the full qualified name of a class, an interface, a method or * a function. * * @return string */ public function getFullQualifiedName() { return sprintf('%s\\%s()', $this->getNamespaceName(), $this->getName()); } } phpmd-2.8.1/src/main/php/PHPMD/Node/InterfaceNode.php000066400000000000000000000016101360164303200221040ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Node; use PDepend\Source\AST\ASTInterface; /** * Wrapper around PHP_Depend's interface objects. */ class InterfaceNode extends AbstractTypeNode { /** * Constructs a new interface wrapper instance. * * @param \PDepend\Source\AST\ASTInterface $node */ public function __construct(ASTInterface $node) { parent::__construct($node); } } phpmd-2.8.1/src/main/php/PHPMD/Node/MethodNode.php000066400000000000000000000076371360164303200214430ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Node; use PDepend\Source\AST\ASTMethod; use PDepend\Source\AST\ASTClass; use PDepend\Source\AST\ASTTrait; use PHPMD\Rule; /** * Wrapper around a PHP_Depend method node. * * Methods available on $node via PHPMD\AbstractNode::__call * * @method bool isPrivate() Returns true if this node is marked as private. */ class MethodNode extends AbstractCallableNode { /** * Constructs a new method wrapper. * * @param \PDepend\Source\AST\ASTMethod $node */ public function __construct(ASTMethod $node) { parent::__construct($node); } /** * Returns the name of the parent package. * * @return string */ public function getNamespaceName() { return $this->getNode()->getParent()->getNamespace()->getName(); } /** * Returns the name of the parent type or null when this node has no * parent type. * * @return string */ public function getParentName() { return $this->getNode()->getParent()->getName(); } /** * Returns the full qualified name of a class, an interface, a method or * a function. * * @return string */ public function getFullQualifiedName() { return sprintf( '%s\\%s::%s()', $this->getNamespaceName(), $this->getParentName(), $this->getName() ); } /** * Returns true when the underlying method is declared as abstract or * is declared as child of an interface. * * @return boolean */ public function isAbstract() { return $this->getNode()->isAbstract(); } /** * Checks if this node has a suppressed annotation for the given rule * instance. * * @param \PHPMD\Rule $rule * @return boolean */ public function hasSuppressWarningsAnnotationFor(Rule $rule) { if (parent::hasSuppressWarningsAnnotationFor($rule)) { return true; } return $this->getParentType()->hasSuppressWarningsAnnotationFor($rule); } /** * Returns the parent class or interface instance. * * @return \PHPMD\Node\AbstractTypeNode */ public function getParentType() { $parentNode = $this->getNode()->getParent(); if ($parentNode instanceof ASTTrait) { return new TraitNode($parentNode); } if ($parentNode instanceof ASTClass) { return new ClassNode($parentNode); } return new InterfaceNode($parentNode); } /** * Returns true when this method is the initial method declaration. * Otherwise this method will return false. * * @return boolean * @since 1.2.1 */ public function isDeclaration() { if ($this->isPrivate()) { return true; } $methodName = strtolower($this->getName()); $parentNode = $this->getNode()->getParent(); foreach ($parentNode->getInterfaces() as $parentType) { $methods = $parentType->getAllMethods(); if (isset($methods[$methodName])) { return false; } } if (is_object($parentType = $parentNode->getParentClass())) { $methods = $parentType->getAllMethods(); if (isset($methods[$methodName])) { return false; } } return true; } } phpmd-2.8.1/src/main/php/PHPMD/Node/TraitNode.php000066400000000000000000000015701360164303200212740ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Node; use PDepend\Source\AST\ASTTrait; /** * Wrapper around PHP_Depend's interface objects. */ class TraitNode extends AbstractTypeNode { /** * Constructs a new interface wrapper instance. * * @param \PDepend\Source\AST\ASTTrait $node */ public function __construct(ASTTrait $node) { parent::__construct($node); } } phpmd-2.8.1/src/main/php/PHPMD/PHPMD.php000066400000000000000000000117061360164303200173700ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD; /** * This is the main facade of the PHP PMD application */ class PHPMD { /** * The current PHPMD version. */ const VERSION = '@project.version@'; /** * List of valid file extensions for analyzed files. * * @var array(string) */ private $fileExtensions = array('php', 'php3', 'php4', 'php5', 'inc'); /** * List of exclude directory patterns. * * @var array(string) */ private $ignorePatterns = array('.git', '.svn', 'CVS', '.bzr', '.hg', 'SCCS'); /** * The input source file or directory. * * @var string */ private $input; /** * This property will be set to true when an error or a violation * was found in the processed source code. * * @var boolean * @since 0.2.5 */ private $violations = false; /** * Additional options for PHPMD or one of it's parser backends. * * @var array * @since 1.2.0 */ private $options = array(); /** * This method will return true when the processed source code * contains violations. * * @return boolean * @since 0.2.5 */ public function hasViolations() { return $this->violations; } /** * Returns the input source file or directory path. * * @return string */ public function getInput() { return $this->input; } /** * Returns an array with valid php source file extensions. * * @return string[] * @since 0.2.0 */ public function getFileExtensions() { return $this->fileExtensions; } /** * Sets a list of filename extensions for valid php source code files. * * @param array $fileExtensions Extensions without leading dot. * @return void */ public function setFileExtensions(array $fileExtensions) { $this->fileExtensions = $fileExtensions; } /** * Returns an array with string patterns that mark a file path as invalid. * * @return string[] * @since 0.2.0 */ public function getIgnorePattern() { return $this->ignorePatterns; } /** * Sets a list of ignore patterns that is used to exclude directories from * the source analysis. * * @param array $ignorePatterns List of ignore patterns. * @return void */ public function setIgnorePattern(array $ignorePatterns) { $this->ignorePatterns = array_merge( $this->ignorePatterns, $ignorePatterns ); } /** * Returns additional options for PHPMD or one of it's parser backends. * * @return array */ public function getOptions() { return $this->options; } /** * Sets additional options for PHPMD or one of it's parser backends. * * @param array $options Additional backend or PHPMD options. * @return void */ public function setOptions(array $options) { $this->options = $options; } /** * This method will process all files that can be found in the given input * path. It will apply rules defined in the comma-separated $ruleSets * argument. The result will be passed to all given renderer instances. * * @param string $inputPath * @param string $ruleSets * @param \PHPMD\AbstractRenderer[] $renderers * @param \PHPMD\RuleSetFactory $ruleSetFactory * @return void */ public function processFiles( $inputPath, $ruleSets, array $renderers, RuleSetFactory $ruleSetFactory ) { // Merge parsed excludes $this->ignorePatterns = array_merge($this->ignorePatterns, $ruleSetFactory->getIgnorePattern($ruleSets)); $this->input = $inputPath; $report = new Report(); $factory = new ParserFactory(); $parser = $factory->create($this); foreach ($ruleSetFactory->createRuleSets($ruleSets) as $ruleSet) { $parser->addRuleSet($ruleSet); } $report->start(); $parser->parse($report); $report->end(); foreach ($renderers as $renderer) { $renderer->start(); } foreach ($renderers as $renderer) { $renderer->renderReport($report); } foreach ($renderers as $renderer) { $renderer->end(); } $this->violations = !$report->isEmpty(); } } phpmd-2.8.1/src/main/php/PHPMD/Parser.php000066400000000000000000000156001360164303200177510ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD; use PDepend\Engine; use PDepend\Report\CodeAwareGenerator; use PDepend\Source\ASTVisitor\AbstractASTVisitor; use PDepend\Metrics\Analyzer; use PDepend\Source\AST\ASTClass; use PDepend\Source\AST\ASTMethod; use PDepend\Source\AST\ASTInterface; use PDepend\Source\AST\ASTFunction; use PDepend\Source\AST\ASTArtifactList; use PHPMD\Node\ClassNode; use PHPMD\Node\FunctionNode; use PHPMD\Node\InterfaceNode; use PHPMD\Node\MethodNode; /** * Simple wrapper around the php depend engine. */ class Parser extends AbstractASTVisitor implements CodeAwareGenerator { /** * The analysing rule-set instance. * * @var \PHPMD\RuleSet[] */ private $ruleSets = array(); /** * The metric containing analyzer instances. * * @var \PDepend\Metrics\AnalyzerNodeAware[] */ private $analyzers = array(); /** * The raw PDepend code nodes. * * @var \PDepend\Source\AST\ASTArtifactList */ private $artifacts = null; /** * The violation report used by this PDepend adapter. * * @var \PHPMD\Report */ private $report = null; /** * The wrapped PDepend Engine instance. * * @var \PDepend\Engine */ private $pdepend = null; /** * Constructs a new parser adapter instance. * * @param \PDepend\Engine $pdepend The context php depend instance. */ public function __construct(Engine $pdepend) { $this->pdepend = $pdepend; } /** * Parses the projects source and reports all detected errors and violations. * * @param \PHPMD\Report $report * @return void */ public function parse(Report $report) { $this->setReport($report); $this->pdepend->addReportGenerator($this); $this->pdepend->analyze(); foreach ($this->pdepend->getExceptions() as $exception) { $report->addError(new ProcessingError($exception->getMessage())); } } /** * Adds a new analysis rule-set to this adapter. * * @param \PHPMD\RuleSet $ruleSet * @return void */ public function addRuleSet(RuleSet $ruleSet) { $this->ruleSets[] = $ruleSet; } /** * Sets the violation report used by the rule-set. * * @param \PHPMD\Report $report * @return void */ public function setReport(Report $report) { $this->report = $report; } /** * Adds an analyzer to log. If this logger accepts the given analyzer it * with return true, otherwise the return value is false. * * @param \PDepend\Metrics\Analyzer $analyzer The analyzer to log. * @return void */ public function log(Analyzer $analyzer) { $this->analyzers[] = $analyzer; } /** * Closes the logger process and writes the output file. * * @return void * @throws \PDepend\Report\NoLogOutputException If the no log target exists. */ public function close() { // Set max nesting level, because we may get really deep data structures ini_set('xdebug.max_nesting_level', 8192); foreach ($this->artifacts as $node) { $node->accept($this); } } /** * Returns an array with accepted analyzer types. These types can be * concrete analyzer classes or one of the descriptive analyzer interfaces. * * @return string[] */ public function getAcceptedAnalyzers() { return array( 'pdepend.analyzer.cyclomatic_complexity', 'pdepend.analyzer.node_loc', 'pdepend.analyzer.npath_complexity', 'pdepend.analyzer.inheritance', 'pdepend.analyzer.node_count', 'pdepend.analyzer.hierarchy', 'pdepend.analyzer.crap_index', 'pdepend.analyzer.code_rank', 'pdepend.analyzer.coupling', 'pdepend.analyzer.class_level', 'pdepend.analyzer.cohesion', ); } /** * Visits a class node. * * @param \PDepend\Source\AST\ASTClass $node * @return void */ public function visitClass(ASTClass $node) { if (!$node->isUserDefined()) { return; } $this->apply(new ClassNode($node)); parent::visitClass($node); } /** * Visits a function node. * * @param \PDepend\Source\AST\ASTFunction $node * @return void */ public function visitFunction(ASTFunction $node) { if ($node->getCompilationUnit()->getFileName() === null) { return; } $this->apply(new FunctionNode($node)); } /** * Visits an interface node. * * @param \PDepend\Source\AST\ASTInterface $node * @return void */ public function visitInterface(ASTInterface $node) { if (!$node->isUserDefined()) { return; } $this->apply(new InterfaceNode($node)); parent::visitInterface($node); } /** * Visits a method node. * * @param \PDepend\Source\AST\ASTMethod $node * @return void */ public function visitMethod(ASTMethod $node) { if ($node->getCompilationUnit()->getFileName() === null) { return; } $this->apply(new MethodNode($node)); } /** * Sets the context code nodes. * * @param \PDepend\Source\AST\ASTArtifactList $artifacts * @return void */ public function setArtifacts(ASTArtifactList $artifacts) { $this->artifacts = $artifacts; } /** * Applies all rule-sets to the given $node instance. * * @param \PHPMD\AbstractNode $node * @return void */ private function apply(AbstractNode $node) { $this->collectMetrics($node); foreach ($this->ruleSets as $ruleSet) { $ruleSet->setReport($this->report); $ruleSet->apply($node); } } /** * Collects the collected metrics for the given node and adds them to the * $node. * * @param \PHPMD\AbstractNode $node * @return void */ private function collectMetrics(AbstractNode $node) { $metrics = array(); $pdepend = $node->getNode(); foreach ($this->analyzers as $analyzer) { $metrics = array_merge($metrics, $analyzer->getNodeMetrics($pdepend)); } $node->setMetrics($metrics); } } phpmd-2.8.1/src/main/php/PHPMD/ParserFactory.php000066400000000000000000000101741360164303200213020ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD; use PDepend\Application; use PDepend\Engine; use PDepend\Input\ExcludePathFilter; use PDepend\Input\ExtensionFilter; /** * Simple factory that is used to return a ready to use PDepend instance. */ class ParserFactory { /** * Mapping between phpmd option names and those used by pdepend. * * @var array */ private $phpmd2pdepend = array( 'coverage' => 'coverage-report' ); /** * Creates the used {@link \PHPMD\Parser} analyzer instance. * * @param \PHPMD\PHPMD $phpmd * @return \PHPMD\Parser */ public function create(PHPMD $phpmd) { $pdepend = $this->createInstance(); $pdepend = $this->init($pdepend, $phpmd); return new Parser($pdepend); } /** * Creates a clean php depend instance with some base settings. * * @return \PDepend\Engine */ private function createInstance() { $application = new Application(); if (file_exists(getcwd() . '/pdepend.xml')) { $application->setConfigurationFile(getcwd() . '/pdepend.xml'); } elseif (file_exists(getcwd() . '/pdepend.xml.dist')) { $application->setConfigurationFile(getcwd() . '/pdepend.xml.dist'); } return $application->getEngine(); } /** * Configures the given PDepend\Engine instance based on some user settings. * * @param \PDepend\Engine $pdepend * @param \PHPMD\PHPMD $phpmd * @return \PDepend\Engine */ private function init(Engine $pdepend, PHPMD $phpmd) { $this->initOptions($pdepend, $phpmd); $this->initInput($pdepend, $phpmd); $this->initIgnores($pdepend, $phpmd); $this->initExtensions($pdepend, $phpmd); return $pdepend; } /** * Configures the input source. * * @param \PDepend\Engine $pdepend * @param \PHPMD\PHPMD $phpmd * @return void */ private function initInput(Engine $pdepend, PHPMD $phpmd) { foreach (explode(',', $phpmd->getInput()) as $path) { $trimmedPath = trim($path); if (is_dir($trimmedPath)) { $pdepend->addDirectory($trimmedPath); continue; } $pdepend->addFile($trimmedPath); } } /** * Initializes the ignored files and path's. * * @param \PDepend\Engine $pdepend * @param \PHPMD\PHPMD $phpmd * @return void */ private function initIgnores(Engine $pdepend, PHPMD $phpmd) { if (count($phpmd->getIgnorePattern()) > 0) { $pdepend->addFileFilter( new ExcludePathFilter($phpmd->getIgnorePattern()) ); } } /** * Initializes the accepted php source file extensions. * * @param \PDepend\Engine $pdepend * @param \PHPMD\PHPMD $phpmd * @return void */ private function initExtensions(Engine $pdepend, PHPMD $phpmd) { if (count($phpmd->getFileExtensions()) > 0) { $pdepend->addFileFilter( new ExtensionFilter($phpmd->getFileExtensions()) ); } } /** * Initializes additional options for pdepend. * * @param \PDepend\Engine $pdepend * @param \PHPMD\PHPMD $phpmd * @return void */ private function initOptions(Engine $pdepend, PHPMD $phpmd) { $options = array(); foreach (array_filter($phpmd->getOptions()) as $name => $value) { if (isset($this->phpmd2pdepend[$name])) { $options[$this->phpmd2pdepend[$name]] = $value; } } $pdepend->setOptions($options); } } phpmd-2.8.1/src/main/php/PHPMD/ProcessingError.php000066400000000000000000000040171360164303200216430ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD; /** * Simple data class that we use to keep parsing errors for the report renderer. * @since 1.2.1 */ class ProcessingError { /** * The original processing error message. * * @var string */ private $message; /** * The source file where the processing error occurred. * * @var string */ private $file; /** * Constructs a new processing error instance. * * @param string $message */ public function __construct($message) { $this->message = $message; $this->file = $this->extractFile($message); } /** * Returns the source file where the processing error occurred. * * @return string */ public function getFile() { return $this->file; } /** * Returns the original processing error message. * * @return string */ public function getMessage() { return $this->message; } /** * Evil hack that extracts the source file from the original exception * message. This method should be removed once we have added the source file * as a mandatory property to PDepend's exceptions. * * @param string $message * @return string */ private function extractFile($message) { preg_match('(file: (.+)\.$| file "([^"]+)")', $message, $match); $match = array_values(array_filter($match)); if (isset($match[1])) { return $match[1]; } return ''; } } phpmd-2.8.1/src/main/php/PHPMD/Renderer/000077500000000000000000000000001360164303200175505ustar00rootroot00000000000000phpmd-2.8.1/src/main/php/PHPMD/Renderer/AnsiRenderer.php000066400000000000000000000077271360164303200226570ustar00rootroot00000000000000writeViolationsReport($report); $this->writeErrorsReport($report); $this->writeReportSummary($report); } /** * @param \PHPMD\Report $report * @return void */ private function writeViolationsReport(Report $report) { if ($report->isEmpty()) { return; } $padding = $this->getMaxLineNumberLength($report); $previousFile = null; foreach ($report->getRuleViolations() as $violation) { if ($violation->getFileName() !== $previousFile) { $this->writeViolationFileHeader($violation); } $this->writeViolationLine($violation, $padding); $previousFile = $violation->getFileName(); } } /** * @param \PHPMD\Report $report * @return int|null */ private function getMaxLineNumberLength(Report $report) { $maxLength = null; foreach ($report->getRuleViolations() as $violation) { if ($maxLength === null || strlen($violation->getBeginLine()) > $maxLength) { $maxLength = strlen($violation->getBeginLine()); } } return $maxLength; } /** * @param \PHPMD\RuleViolation $violation * @return void */ private function writeViolationFileHeader(RuleViolation $violation) { $fileHeader = sprintf( 'FILE: %s', $violation->getFileName() ); $this->getWriter()->write( PHP_EOL . $fileHeader . PHP_EOL . str_repeat('-', strlen($fileHeader)) . PHP_EOL ); } /** * @param \PHPMD\RuleViolation $violation * @param int $padding * @return void */ private function writeViolationLine(RuleViolation $violation, $padding) { $this->getWriter()->write(sprintf( " %s | \e[31mVIOLATION\e[0m | %s" . PHP_EOL, str_pad($violation->getBeginLine(), $padding, ' '), $violation->getDescription() )); } /** * @param \PHPMD\Report $report * @return void */ private function writeErrorsReport(Report $report) { if (!$report->hasErrors()) { return; } /** @var ProcessingError $error */ foreach ($report->getErrors() as $error) { $errorHeader = sprintf( "\e[33mERROR\e[0m while parsing %s", $error->getFile() ); $this->getWriter()->write( PHP_EOL . $errorHeader . PHP_EOL . str_repeat('-', strlen($errorHeader) - 9) . PHP_EOL ); $this->getWriter()->write(sprintf( '%s' . PHP_EOL, $error->getMessage() )); } } /** * @param \PHPMD\Report $report * @return void */ private function writeReportSummary(Report $report) { $this->getWriter()->write( sprintf( PHP_EOL . 'Found %s %s and %s %s in %sms' . PHP_EOL, count($report->getRuleViolations()), count($report->getRuleViolations()) !== 1 ? 'violations' : 'violation', iterator_count($report->getErrors()), iterator_count($report->getErrors()) !== 1 ? 'errors' : 'error', $report->getElapsedTimeInMillis() ) ); if (count($report->getRuleViolations()) === 0 && iterator_count($report->getErrors()) === 0) { $this->getWriter()->write(PHP_EOL . "\e[32mNo mess detected\e[0m" . PHP_EOL); } } } phpmd-2.8.1/src/main/php/PHPMD/Renderer/HTMLRenderer.php000066400000000000000000000111461360164303200225170ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Renderer; use PHPMD\AbstractRenderer; use PHPMD\Report; /** * This renderer output a simple html file with all found violations and suspect * software artifacts. */ class HTMLRenderer extends AbstractRenderer { /** * This method will be called on all renderers before the engine starts the * real report processing. * * @return void */ public function start() { $writer = $this->getWriter(); $writer->write('PHPMD'); $writer->write(PHP_EOL); $writer->write('

PHPMD report

'); $writer->write('

Problems found

'); $writer->write(PHP_EOL); $writer->write(''); $writer->write(''); $writer->write(''); $writer->write(''); $writer->write(PHP_EOL); } /** * This method will be called when the engine has finished the source analysis * phase. * * @param \PHPMD\Report $report * @return void */ public function renderReport(Report $report) { $index = 0; $writer = $this->getWriter(); foreach ($report->getRuleViolations() as $violation) { $writer->write('write(' bgcolor="lightgrey"'); } $writer->write('>'); $writer->write(PHP_EOL); $writer->write(''); $writer->write(PHP_EOL); $writer->write(''); $writer->write(PHP_EOL); $writer->write(''); $writer->write(PHP_EOL); $writer->write(''); $writer->write(PHP_EOL); $writer->write(''); $writer->write(PHP_EOL); } $writer->write('
#FileLineProblem
'); $writer->write($index); $writer->write(''); $writer->write(htmlentities($violation->getFileName())); $writer->write(''); $writer->write($violation->getBeginLine()); $writer->write(''); if ($violation->getRule()->getExternalInfoUrl()) { $writer->write(''); } $writer->write(htmlentities($violation->getDescription())); if ($violation->getRule()->getExternalInfoUrl()) { $writer->write(''); } $writer->write('
'); $this->glomProcessingErrors($report); } /** * This method will be called the engine has finished the report processing * for all registered renderers. * * @return void */ public function end() { $writer = $this->getWriter(); $writer->write(''); } /** * This method will render a html table with occurred processing errors. * * @param \PHPMD\Report $report * @return void * @since 1.2.1 */ private function glomProcessingErrors(Report $report) { if (false === $report->hasErrors()) { return; } $writer = $this->getWriter(); $writer->write('
'); $writer->write('

Processing errors

'); $writer->write(''); $writer->write(''); $index = 0; foreach ($report->getErrors() as $error) { $writer->write('write(' bgcolor="lightgrey"'); } $writer->write('>'); $writer->write(''); $writer->write(''); $writer->write('' . PHP_EOL); } $writer->write('
FileProblem
' . $error->getFile() . '' . htmlentities($error->getMessage()) . '
'); } } phpmd-2.8.1/src/main/php/PHPMD/Renderer/JSONRenderer.php000066400000000000000000000075461360164303200225350ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Renderer; use PHPMD\AbstractRenderer; use PHPMD\PHPMD; use PHPMD\Report; use PHPMD\RuleViolation; /** * This class will render a JSON report. */ class JSONRenderer extends AbstractRenderer { /** * {@inheritDoc} */ public function renderReport(Report $report) { $data = $this->initReportData(); $data = $this->addViolationsToReport($report, $data); $data = $this->addErrorsToReport($report, $data); $jsonData = $this->encodeReport($data); $writer = $this->getWriter(); $writer->write($jsonData . PHP_EOL); } /** * Create report data and add renderer meta properties * * @return array */ private function initReportData() { $data = array( 'version' => PHPMD::VERSION, 'package' => 'phpmd', 'timestamp' => date('c'), ); return $data; } /** * Add violations, if any, to the report data * * @param Report $report The report with potential violations. * @param array $data The report output to add the violations to. * @return array The report output with violations, if any. */ private function addViolationsToReport(Report $report, array $data) { $filesList = array(); /** @var RuleViolation $violation */ foreach ($report->getRuleViolations() as $violation) { $fileName = $violation->getFileName(); $rule = $violation->getRule(); $filesList[$fileName]['file'] = $fileName; $filesList[$fileName]['violations'][] = array( 'beginLine' => $violation->getBeginLine(), 'endLine' => $violation->getEndLine(), 'package' => $violation->getNamespaceName(), 'function' => $violation->getFunctionName(), 'class' => $violation->getClassName(), 'method' => $violation->getMethodName(), 'description' => $violation->getDescription(), 'rule' => $rule->getName(), 'ruleSet' => $rule->getRuleSetName(), 'externalInfoUrl' => $rule->getExternalInfoUrl(), 'priority' => $rule->getPriority(), ); } $data['files'] = array_values($filesList); return $data; } /** * Add errors, if any, to the report data * * @param Report $report The report with potential errors. * @param array $data The report output to add the errors to. * @return array The report output with errors, if any. */ private function addErrorsToReport(Report $report, array $data) { $errors = $report->getErrors(); if ($errors) { foreach ($errors as $error) { $data['errors'][] = array( 'fileName' => $error->getFile(), 'message' => $error->getMessage(), ); } } return $data; } /** * Encode report data to the JSON representation string * * @param array $data The report data * * @return string */ private function encodeReport($data) { $encodeOptions = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP | (defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0); return json_encode($data, $encodeOptions); } } phpmd-2.8.1/src/main/php/PHPMD/Renderer/TextRenderer.php000066400000000000000000000030711360164303200226750ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Renderer; use PHPMD\AbstractRenderer; use PHPMD\Report; /** * This renderer output a textual log with all found violations and suspect * software artifacts. */ class TextRenderer extends AbstractRenderer { /** * This method will be called when the engine has finished the source analysis * phase. * * @param \PHPMD\Report $report * @return void */ public function renderReport(Report $report) { $writer = $this->getWriter(); foreach ($report->getRuleViolations() as $violation) { $writer->write($violation->getFileName()); $writer->write(':'); $writer->write($violation->getBeginLine()); $writer->write("\t"); $writer->write($violation->getDescription()); $writer->write(PHP_EOL); } foreach ($report->getErrors() as $error) { $writer->write($error->getFile()); $writer->write("\t-\t"); $writer->write($error->getMessage()); $writer->write(PHP_EOL); } } } phpmd-2.8.1/src/main/php/PHPMD/Renderer/XMLRenderer.php000066400000000000000000000103011360164303200224030ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Renderer; use PHPMD\AbstractRenderer; use PHPMD\PHPMD; use PHPMD\Report; /** * This class will render a Java-PMD compatible xml-report. */ class XMLRenderer extends AbstractRenderer { /** * Temporary property that holds the name of the last rendered file, it is * used to detect the next processed file. * * @var string */ private $fileName = null; /** * This method will be called on all renderers before the engine starts the * real report processing. * * @return void */ public function start() { $this->getWriter()->write(''); $this->getWriter()->write(PHP_EOL); } /** * This method will be called when the engine has finished the source analysis * phase. * * @param \PHPMD\Report $report * @return void */ public function renderReport(Report $report) { $writer = $this->getWriter(); $writer->write('write('timestamp="' . date('c') . '">'); $writer->write(PHP_EOL); foreach ($report->getRuleViolations() as $violation) { $fileName = $violation->getFileName(); if ($this->fileName !== $fileName) { // Not first file if ($this->fileName !== null) { $writer->write(' ' . PHP_EOL); } // Store current file name $this->fileName = $fileName; $writer->write(' ' . PHP_EOL); } $rule = $violation->getRule(); $writer->write(' write(' beginline="' . $violation->getBeginLine() . '"'); $writer->write(' endline="' . $violation->getEndLine() . '"'); $writer->write(' rule="' . $rule->getName() . '"'); $writer->write(' ruleset="' . $rule->getRuleSetName() . '"'); $this->maybeAdd('package', $violation->getNamespaceName()); $this->maybeAdd('externalInfoUrl', $rule->getExternalInfoUrl()); $this->maybeAdd('function', $violation->getFunctionName()); $this->maybeAdd('class', $violation->getClassName()); $this->maybeAdd('method', $violation->getMethodName()); //$this->_maybeAdd('variable', $violation->getVariableName()); $writer->write(' priority="' . $rule->getPriority() . '"'); $writer->write('>' . PHP_EOL); $writer->write(' ' . htmlspecialchars($violation->getDescription()) . PHP_EOL); $writer->write(' ' . PHP_EOL); } // Last file and at least one violation if ($this->fileName !== null) { $writer->write(' ' . PHP_EOL); } foreach ($report->getErrors() as $error) { $writer->write(' ' . PHP_EOL); } $writer->write('' . PHP_EOL); } /** * This method will write a xml attribute named $attr to the output * when the given $value is not an empty string and is not null. * * @param string $attr The xml attribute name. * @param string $value The attribute value. * @return void */ private function maybeAdd($attr, $value) { if ($value === null || trim($value) === '') { return; } $this->getWriter()->write(' ' . $attr . '="' . $value . '"'); } } phpmd-2.8.1/src/main/php/PHPMD/Report.php000066400000000000000000000100111360164303200177570ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD; /** * The report class collects all found violations and further information about * a PHPMD run. */ class Report { /** * List of rule violations detected in the analyzed source code. * * @var array */ private $ruleViolations = array(); /** * The start time for this report. * * @var float */ private $startTime = 0.0; /** * The end time for this report. * * @var float */ private $endTime = 0.0; /** * Errors that occurred while parsing the source. * * @var array * @since 1.2.1 */ private $errors = array(); /** * Adds a rule violation to this report. * * @param \PHPMD\RuleViolation $violation * @return void */ public function addRuleViolation(RuleViolation $violation) { $fileName = $violation->getFileName(); if (!isset($this->ruleViolations[$fileName])) { $this->ruleViolations[$fileName] = array(); } $beginLine = $violation->getBeginLine(); if (!isset($this->ruleViolations[$fileName][$beginLine])) { $this->ruleViolations[$fileName][$beginLine] = array(); } $this->ruleViolations[$fileName][$beginLine][] = $violation; } /** * Returns true when this report does not contain any errors. * * @return boolean * @since 0.2.5 */ public function isEmpty() { return (count($this->ruleViolations) === 0); } /** * Returns an iterator with all occurred rule violations. * * @return \PHPMD\RuleViolation[] */ public function getRuleViolations() { // First sort by file name ksort($this->ruleViolations); $violations = array(); foreach ($this->ruleViolations as $violationInLine) { // Second sort is by line number ksort($violationInLine); foreach ($violationInLine as $violation) { $violations = array_merge($violations, $violation); } } return new \ArrayIterator($violations); } /** * Adds a processing error that occurred while parsing the source. * * @param \PHPMD\ProcessingError $error * @return void * @since 1.2.1 */ public function addError(ProcessingError $error) { $this->errors[] = $error; } /** * Returns true when the report contains at least one processing * error. Otherwise this method will return false. * * @return boolean * @since 1.2.1 */ public function hasErrors() { return count($this->errors) > 0; } /** * Returns an iterator with all {@link \PHPMD\ProcessingError} that were * added to this report. * * @return \Iterator * @since 1.2.1 */ public function getErrors() { return new \ArrayIterator($this->errors); } /** * Starts the time tracking of this report instance. * * @return void */ public function start() { $this->startTime = microtime(true) * 1000.0; } /** * Stops the time tracking of this report instance. * * @return void */ public function end() { $this->endTime = microtime(true) * 1000.0; } /** * Returns the total time elapsed for the source analysis. * * @return float */ public function getElapsedTimeInMillis() { return round($this->endTime - $this->startTime); } } phpmd-2.8.1/src/main/php/PHPMD/Rule.php000066400000000000000000000112231360164303200174210ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD; use PHPMD\Report; /** * Base interface for a PHPMD rule. * * @since 1.1.0 */ interface Rule { /** * The default lowest rule priority. */ const LOWEST_PRIORITY = 5; /** * The default highest rule priority. */ const HIGHEST_PRIORITY = 1; /** * Returns the name for this rule instance. * * @return string */ public function getName(); /** * Sets the name for this rule instance. * * @param string $name * @return void */ public function setName($name); /** * Returns the version since when this rule is available or null. * * @return string */ public function getSince(); /** * Sets the version since when this rule is available. * * @param string $since * @return void */ public function setSince($since); /** * Returns the violation message text for this rule. * * @return string */ public function getMessage(); /** * Sets the violation message text for this rule. * * @param string $message * @return void */ public function setMessage($message); /** * Returns an url will external information for this rule. * * @return string */ public function getExternalInfoUrl(); /** * Sets an url will external information for this rule. * * @param string $externalInfoUrl * @return void */ public function setExternalInfoUrl($externalInfoUrl); /** * Returns the description text for this rule instance. * * @return string */ public function getDescription(); /** * Sets the description text for this rule instance. * * @param string $description * @return void */ public function setDescription($description); /** * Returns a list of examples for this rule. * * @return array */ public function getExamples(); /** * Adds a code example for this rule. * * @param string $example * @return void */ public function addExample($example); /** * Returns the priority of this rule. * * @return integer */ public function getPriority(); /** * Set the priority of this rule. * * @param integer $priority * @return void */ public function setPriority($priority); /** * Returns the name of the parent rule-set instance. * * @return string */ public function getRuleSetName(); /** * Sets the name of the parent rule set instance. * * @param string $ruleSetName * @return void */ public function setRuleSetName($ruleSetName); /** * Returns the violation report for this rule. * * @return Report */ public function getReport(); /** * Sets the violation report for this rule. * * @param Report $report * @return void */ public function setReport(Report $report); /** * Adds a configuration property to this rule instance. * * @param string $name * @param string $value * @return void */ public function addProperty($name, $value); /** * Returns the value of a configured property as a boolean or throws an * exception when no property with $name exists. * * @param string $name * @return boolean * @throws \OutOfBoundsException When no property for $name exists. */ public function getBooleanProperty($name); /** * Returns the value of a configured property as an integer or throws an * exception when no property with $name exists. * * @param string $name * @return integer * @throws \OutOfBoundsException When no property for $name exists. */ public function getIntProperty($name); /** * This method should implement the violation analysis algorithm of concrete * rule implementations. All extending classes must implement this method. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node); } phpmd-2.8.1/src/main/php/PHPMD/Rule/000077500000000000000000000000001360164303200167115ustar00rootroot00000000000000phpmd-2.8.1/src/main/php/PHPMD/Rule/AbstractLocalVariable.php000066400000000000000000000114371360164303200236140ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Node\ASTNode; /** * Base class for rules that rely on local variables. * * @since 0.2.6 */ abstract class AbstractLocalVariable extends AbstractRule { /** * PHP super globals that are available in all php scopes, so that they * can never be unused local variables. * * @var array(string=>boolean) * @link http://php.net/manual/en/reserved.variables.php */ private static $superGlobals = array( '$argc' => true, '$argv' => true, '$_COOKIE' => true, '$_ENV' => true, '$_FILES' => true, '$_GET' => true, '$_POST' => true, '$_REQUEST' => true, '$_SERVER' => true, '$_SESSION' => true, '$GLOBALS' => true, '$HTTP_RAW_POST_DATA' => true, '$php_errormsg' => true, '$http_response_header' => true, ); /** * Tests if the given variable node represents a local variable or if it is * a static object property or something similar. * * @param \PHPMD\Node\ASTNode $variable The variable to check. * @return boolean */ protected function isLocal(ASTNode $variable) { return (false === $variable->isThis() && $this->isNotSuperGlobal($variable) && $this->isRegularVariable($variable) ); } /** * Tests if the given variable represents one of the PHP super globals * that are available in scopes. * * @param \PHPMD\AbstractNode $variable * @return boolean */ protected function isNotSuperGlobal(AbstractNode $variable) { return !isset(self::$superGlobals[$variable->getImage()]); } /** * Tests if the given variable node is a regular variable an not property * or method postfix. * * @param \PHPMD\Node\ASTNode $variable * @return boolean */ protected function isRegularVariable(ASTNode $variable) { $node = $this->stripWrappedIndexExpression($variable); $parent = $node->getParent(); if ($parent->isInstanceOf('PropertyPostfix')) { $primaryPrefix = $parent->getParent(); if ($primaryPrefix->getParent()->isInstanceOf('MemberPrimaryPrefix')) { return !$primaryPrefix->getParent()->isStatic(); } return ($parent->getChild(0)->getNode() !== $node->getNode() || !$primaryPrefix->isStatic() ); } return true; } /** * Removes all index expressions that are wrapped around the given node * instance. * * @param \PHPMD\Node\ASTNode $node * @return \PHPMD\Node\ASTNode */ protected function stripWrappedIndexExpression(ASTNode $node) { if (false === $this->isWrappedByIndexExpression($node)) { return $node; } $parent = $node->getParent(); if ($parent->getChild(0)->getNode() === $node->getNode()) { return $this->stripWrappedIndexExpression($parent); } return $node; } /** * Tests if the given variable node os part of an index expression. * * @param \PHPMD\Node\ASTNode $node * @return boolean */ protected function isWrappedByIndexExpression(ASTNode $node) { return ($node->getParent()->isInstanceOf('ArrayIndexExpression') || $node->getParent()->isInstanceOf('StringIndexExpression') ); } /** * PHP is case insensitive so we should compare function names case * insensitive. * * @param \PHPMD\AbstractNode $node * @param string $name * @return boolean */ protected function isFunctionNameEqual(AbstractNode $node, $name) { return (0 === strcasecmp(trim($node->getImage(), '\\'), $name)); } /** * AST puts namespace prefix to global functions called from a namespace. * This method checks if the last part of function fully qualified name is equal to $name * * @param \PHPMD\AbstractNode $node * @param string $name * @return boolean */ protected function isFunctionNameEndingWith(AbstractNode $node, $name) { $parts = explode('\\', trim($node->getImage(), '\\')); return (0 === strcasecmp(array_pop($parts), $name)); } } phpmd-2.8.1/src/main/php/PHPMD/Rule/ClassAware.php000066400000000000000000000011741360164303200214520ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule; /** * This interface is used to mark a rule implementation as class aware. */ interface ClassAware { } phpmd-2.8.1/src/main/php/PHPMD/Rule/CleanCode/000077500000000000000000000000001360164303200205265ustar00rootroot00000000000000phpmd-2.8.1/src/main/php/PHPMD/Rule/CleanCode/BooleanArgumentFlag.php000066400000000000000000000033231360164303200251140ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\CleanCode; use PDepend\Source\AST\ASTValue; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Rule\FunctionAware; use PHPMD\Rule\MethodAware; /** * Check for a boolean flag in the method/function signature. * * Boolean flags are signs for single responsibility principle violations. */ class BooleanArgumentFlag extends AbstractRule implements MethodAware, FunctionAware { /** * This method checks if a method/function has boolean flag arguments and warns about them. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { foreach ($node->findChildrenOfType('FormalParameter') as $param) { $declarator = $param->getFirstChildOfType('VariableDeclarator'); $value = $declarator->getValue(); if (false === $this->isBooleanValue($value)) { continue; } $this->addViolation($param, array($node->getImage(), $declarator->getImage())); } } private function isBooleanValue(ASTValue $value = null) { return $value && $value->isValueAvailable() && ($value->getValue() === true || $value->getValue() === false); } } phpmd-2.8.1/src/main/php/PHPMD/Rule/CleanCode/DuplicatedArrayKey.php000066400000000000000000000102331360164303200247640ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\CleanCode; use PDepend\Source\AST\AbstractASTNode; use PDepend\Source\AST\ASTArrayElement; use PDepend\Source\AST\ASTLiteral; use PDepend\Source\AST\ASTNode as PDependASTNode; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Node\ASTNode; use PHPMD\Rule\FunctionAware; use PHPMD\Rule\MethodAware; /** * Duplicated Array Key Rule * * This rule detects duplicated array keys. * * @author Rafał Wrzeszcz * @author Kamil Szymanaski */ class DuplicatedArrayKey extends AbstractRule implements MethodAware, FunctionAware { /** * Retrieves all arrays from single node and performs comparison logic on it * * @param AbstractNode $node * @return void */ public function apply(AbstractNode $node) { foreach ($node->findChildrenOfType('Array') as $arrayNode) { /** @var ASTNode $arrayNode */ $this->checkForDuplicatedArrayKeys($arrayNode); } } /** * This method checks if a given function or method contains an array literal * with duplicated entries for any key and emits a rule violation if so. * * @param ASTNode $node Array node. * @return void */ private function checkForDuplicatedArrayKeys(ASTNode $node) { $keys = array(); /** @var ASTArrayElement $arrayElement */ foreach ($node->getChildren() as $index => $arrayElement) { $arrayElement = $this->normalizeKey($arrayElement, $index); if (null === $arrayElement) { // skip everything that can't be resolved easily continue; } $key = $arrayElement->getImage(); if (isset($keys[$key])) { $this->addViolation($node, array($key, $arrayElement->getStartLine())); continue; } $keys[$key] = $arrayElement; } } /** * Changes key name to its string format. * * To compare keys, we have to cast them to string. * Non-associative keys have to use index as its key, * while boolean and nulls have to be casted respectively. * As current logic doesn't evaluate expressions nor constants, * statics, globals, etc. we simply skip them. * * @param AbstractASTNode $node Array key to evaluate. * @param int $index Fallback in case of non-associative arrays * @return AbstractASTNode Key name */ private function normalizeKey(AbstractASTNode $node, $index) { $childCount = count($node->getChildren()); // Skip, if there is no array key, just an array value if ($childCount === 1) { return null; } // non-associative - key name equals to its index if ($childCount === 0) { $node->setImage((string) $index); return $node; } $node = $node->getChild(0); if (!($node instanceof ASTLiteral)) { // skip expressions, method calls, globals and constants return null; } $node->setImage($this->castStringFromLiteral($node)); return $node; } /** * Cleans string literals and casts boolean and null values as PHP engine does * * @param PDependASTNode $key * @return string */ private function castStringFromLiteral(PDependASTNode $key) { $value = $key->getImage(); switch ($value) { case 'false': return '0'; case 'true': return '1'; case 'null': return ''; default: return trim($value, '\'""'); } } } phpmd-2.8.1/src/main/php/PHPMD/Rule/CleanCode/ElseExpression.php000066400000000000000000000044241360164303200242130ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\CleanCode; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Node\ASTNode; use PHPMD\Rule\FunctionAware; use PHPMD\Rule\MethodAware; /** * Check if there is an else expression somewhere in the method/function and * warn about it. * * Object Calisthenics teaches us, that an else expression can always be * avoided by simple guard clause or return statements. */ class ElseExpression extends AbstractRule implements MethodAware, FunctionAware { /** * This method checks if a method/function uses an else expression and add a violation for each one found. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { foreach ($node->findChildrenOfType('ScopeStatement') as $scope) { $parent = $scope->getParent(); if (false === $this->isIfOrElseIfStatement($parent)) { continue; } if (false === $this->isElseScope($scope, $parent)) { continue; } $this->addViolation($scope, array($node->getImage())); } } /** * Whether the given scope is an else clause * * @param AbstractNode $scope * @param ASTNode $parent * @return bool */ private function isElseScope(AbstractNode $scope, ASTNode $parent) { return ( count($parent->getChildren()) === 3 && $scope->getNode() === $parent->getChild(2)->getNode() ); } /** * Whether the parent node is an if or an elseif clause * * @param ASTNode $parent * @return bool */ private function isIfOrElseIfStatement(ASTNode $parent) { return ($parent->getName() === "if" || $parent->getName() === "elseif"); } } phpmd-2.8.1/src/main/php/PHPMD/Rule/CleanCode/IfStatementAssignment.php000066400000000000000000000101651360164303200255160ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\CleanCode; use PDepend\Source\AST\ASTAssignmentExpression; use PDepend\Source\AST\ASTExpression; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Node\ASTNode; use PHPMD\Rule\FunctionAware; use PHPMD\Rule\MethodAware; /** * If Statement Assignment Rule * * This rule covers the following cases: * - single assignment in an if clause * - multiple assignments in same if clause * - assignments in nested if clauses * - assignments in elseif clauses * - duplicated assignments (multiple conditions before and after *=* sign) * * Empty if clauses are skipped */ class IfStatementAssignment extends AbstractRule implements MethodAware, FunctionAware { /** * @var array List of statement types where to forbid assignation. */ protected $ifStatements = array( 'IfStatement', 'ElseIfStatement', ); /** * This method checks if method/function has if clauses * that use assignment instead of comparison. * * @param AbstractNode $node An instance of MethodNode or FunctionNode class * @return void */ public function apply(AbstractNode $node) { $statements = $this->getStatements($node); $expressions = $this->getExpressions($statements); $assignments = $this->getAssignments($expressions); $this->addViolations($node, $assignments); } /** * Extracts if and elseif statements from method/function body * * @param AbstractNode $node An instance of MethodNode or FunctionNode class * @return ASTNode[] */ private function getStatements(AbstractNode $node) { return call_user_func_array('array_merge', array_map(function ($type) use ($node) { return $node->findChildrenOfType($type); }, $this->ifStatements)); } /** * Extracts all expression from statements array * * @param ASTNode[] $statements Array of if and elseif clauses * @return ASTExpression[] */ private function getExpressions(array $statements) { return array_map(function (ASTNode $statement) { return $statement->getFirstChildOfType('Expression'); }, $statements); } /** * Extracts all assignments from expressions array * * @param ASTExpression[] $expressions Array of expressions * @return ASTAssignmentExpression[] */ private function getAssignments(array $expressions) { $assignments = array(); /** @var ASTNode $expression */ foreach ($expressions as $expression) { $assignments = array_merge($assignments, $expression->findChildrenOfType('AssignmentExpression')); } return $assignments; } /** * Signals if any violations have been found in given method or function * * @param AbstractNode $node An instance of MethodNode or FunctionNode class * @param ASTAssignmentExpression[] $assignments Array of assignments */ private function addViolations(AbstractNode $node, array $assignments) { $processesViolations = array(); /** @var \PDepend\Source\AST\AbstractASTNode $assignment */ foreach ($assignments as $assignment) { if (null === $assignment || $assignment->getImage() !== '=') { continue; } $uniqueHash = $assignment->getStartColumn() . ':' . $assignment->getStartLine(); if (!in_array($uniqueHash, $processesViolations)) { $processesViolations[] = $uniqueHash; $this->addViolation($node, array($assignment->getStartLine(), $assignment->getStartColumn())); } } } } phpmd-2.8.1/src/main/php/PHPMD/Rule/CleanCode/MissingImport.php000066400000000000000000000042711360164303200240470ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\CleanCode; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Node\ASTNode; use PHPMD\Rule\FunctionAware; use PHPMD\Rule\MethodAware; /** * Checks that all classes are imported * * This rule can be used to prevent use of fully qualified class names. */ class MissingImport extends AbstractRule implements MethodAware, FunctionAware { /** * @var array Self reference class names. */ protected $selfReferences = array('self', 'static'); /** * Checks for missing class imports and warns about it * * @param AbstractNode $node The node to check upon. * @return void */ public function apply(AbstractNode $node) { foreach ($node->findChildrenOfType('AllocationExpression') as $allocationNode) { if (!$allocationNode) { continue; } $classNode = $allocationNode->getChild(0); if ($this->isSelfReference($classNode)) { continue; } $classNameLength = $classNode->getEndColumn() - $classNode->getStartColumn() + 1; $fqcnLength = strlen($classNode->getImage()); if ($classNameLength === $fqcnLength) { $this->addViolation($classNode, array($classNode->getBeginLine(), $classNode->getStartColumn())); } } } /** * Check whether a given class node is a self reference * * @param ASTNode $classNode A class node to check. * @return bool Whether the given class node is a self reference. */ protected function isSelfReference(ASTNode $classNode) { return in_array($classNode->getImage(), $this->selfReferences, true); } } phpmd-2.8.1/src/main/php/PHPMD/Rule/CleanCode/StaticAccess.php000066400000000000000000000056471360164303200236240ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\CleanCode; use PDepend\Source\AST\ASTClassOrInterfaceReference; use PDepend\Source\AST\ASTMethodPostfix; use PDepend\Source\AST\ASTParentReference; use PDepend\Source\AST\ASTSelfReference; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Rule\FunctionAware; use PHPMD\Rule\MethodAware; /** * Check if static access is used in a method. * * Static access is known to cause hard dependencies between classes * and is a bad practice. */ class StaticAccess extends AbstractRule implements MethodAware, FunctionAware { /** * Method checks for use of static access and warns about it. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { $exceptions = $this->getExceptionsList(); $nodes = $node->findChildrenOfType('MemberPrimaryPrefix'); foreach ($nodes as $methodCall) { if (!$this->isStaticMethodCall($methodCall)) { continue; } $className = $methodCall->getChild(0)->getNode()->getImage(); if (in_array(trim($className, " \t\n\r\0\x0B\\"), $exceptions)) { continue; } $this->addViolation($methodCall, array($className, $node->getName())); } } private function isStaticMethodCall(AbstractNode $methodCall) { return $methodCall->getChild(0)->getNode() instanceof ASTClassOrInterfaceReference && $methodCall->getChild(1)->getNode() instanceof ASTMethodPostfix && !$this->isCallingParent($methodCall) && !$this->isCallingSelf($methodCall); } private function isCallingParent(AbstractNode $methodCall) { return $methodCall->getChild(0)->getNode() instanceof ASTParentReference; } private function isCallingSelf(AbstractNode $methodCall) { return $methodCall->getChild(0)->getNode() instanceof ASTSelfReference; } /** * Gets array of exceptions from property * * @return array */ private function getExceptionsList() { try { $exceptions = $this->getStringProperty('exceptions'); } catch (\OutOfBoundsException $e) { $exceptions = ''; } return array_map( function ($className) { return trim($className, " \t\n\r\0\x0B\\"); }, explode(',', $exceptions) ); } } phpmd-2.8.1/src/main/php/PHPMD/Rule/CleanCode/UndefinedVariable.php000066400000000000000000000171021360164303200246070ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\CleanCode; use PDepend\Source\AST\ASTVariable; use PDepend\Source\AST\State; use PHPMD\AbstractNode; use PHPMD\Node\AbstractCallableNode; use PHPMD\Node\ASTNode; use PHPMD\Node\MethodNode; use PHPMD\Rule\AbstractLocalVariable; use PHPMD\Rule\FunctionAware; use PHPMD\Rule\MethodAware; /** * This rule collects all undefined variables within a given function or method * that are used by any code in the analyzed source artifact. */ class UndefinedVariable extends AbstractLocalVariable implements FunctionAware, MethodAware { /** * Found variable images within a single method or function. * * @var array(string) */ private $images = array(); /** * This method checks that all local variables within the given function or * method are used at least one time. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { $this->images = array(); $this->collectPropertyPostfix($node); $this->collectClosureParameters($node); $this->collectForeachStatements($node); $this->collectListExpressions($node); $this->collectAssignments($node); $this->collectParameters($node); $this->collectExceptionCatches($node); $this->collectGlobalStatements($node); foreach ($node->findChildrenOfType('Variable') as $variable) { if (! $this->isNotSuperGlobal($variable)) { $this->addVariableDefinition($variable); } if (! $this->checkVariableDefined($variable, $node)) { $this->addViolation($variable, array($variable->getImage())); } } } /** * Stores the given literal node in an global of found variables. * * @param \PHPMD\Node\AbstractNode $node * @return void */ private function collectGlobalStatements(AbstractNode $node) { $globalStatements = $node->findChildrenOfType('GlobalStatement'); foreach ($globalStatements as $globalStatement) { foreach ($globalStatement->getChildren() as $variable) { $this->addVariableDefinition($variable); } } } /** * Stores the given literal node in an catch of found variables. * * @param \PHPMD\Node\AbstractCallableNode $node * @return void */ private function collectExceptionCatches(AbstractCallableNode $node) { $catchStatements = $node->findChildrenOfType('CatchStatement'); foreach ($catchStatements as $catchStatement) { foreach ($catchStatement->getChildren() as $children) { if ($children instanceof ASTVariable) { $this->addVariableDefinition($children); } } } } /** * Stores the given literal node in an internal list of found variables. * * @param \PHPMD\Node\AbstractCallableNode $node * @return void */ private function collectListExpressions(AbstractCallableNode $node) { $lists = $node->findChildrenOfType('ListExpression'); foreach ($lists as $listExpression) { foreach ($listExpression->getChildren() as $variable) { $this->addVariableDefinition($variable); } } } /** * Stores the given literal node in an internal foreach of found variables. * * @param \PHPMD\Node\AbstractCallableNode $node * @return void */ private function collectForeachStatements(AbstractCallableNode $node) { $foreachStatements = $node->findChildrenOfType('ForeachStatement'); foreach ($foreachStatements as $foreachStatement) { foreach ($foreachStatement->getChildren() as $children) { if ($children instanceof ASTVariable) { $this->addVariableDefinition($children); } } } } /** * Stores the given literal node in an internal closure of found variables. * * @param \PHPMD\Node\AbstractCallableNode $node * @return void */ private function collectClosureParameters(AbstractCallableNode $node) { $closures = $node->findChildrenOfType('Closure'); foreach ($closures as $closure) { $this->collectParameters($closure); } } /** * Check if the given variable was defined in the current context before usage. * * @param \PHPMD\Node\ASTNode $variable * @param \PHPMD\Node\AbstractCallableNode $parentNode * @return bool */ private function checkVariableDefined(ASTNode $variable, AbstractCallableNode $parentNode) { return isset($this->images[$variable->getImage()]) || $this->isNameAllowedInContext($parentNode, $variable); } /** * Collect parameter names of method/function. * * @param \PHPMD\Node\AbstractNode $node * @return void */ private function collectParameters(AbstractNode $node) { // Get formal parameter container $parameters = $node->getFirstChildOfType('FormalParameters'); // Now get all declarators in the formal parameters container $declarators = $parameters->findChildrenOfType('VariableDeclarator'); foreach ($declarators as $declarator) { $this->addVariableDefinition($declarator); } } /** * Collect assignments of variables. * * @param \PHPMD\Node\AbstractCallableNode $node * @return void */ private function collectAssignments(AbstractCallableNode $node) { foreach ($node->findChildrenOfType('AssignmentExpression') as $assignment) { $variable = $assignment->getChild(0); $this->addVariableDefinition($variable); } } /** * Collect postfix property. * * @param \PHPMD\Node\AbstractNode $node * @return void */ private function collectPropertyPostfix(AbstractNode $node) { $propertyes = $node->findChildrenOfType('PropertyPostfix'); foreach ($propertyes as $property) { foreach ($property->getChildren() as $children) { if ($children instanceof ASTVariable) { $this->addVariableDefinition($children); } } } } /** * Add the variable to images * * @param mixed $variable * @return void */ private function addVariableDefinition($variable) { if (! isset($this->images[$variable->getImage()])) { $this->images[$variable->getImage()] = $variable; } } /** * Checks if a short name is acceptable in the current context. * * @param \PHPMD\Node\AbstractCallableNode $node * @param \PHPMD\Node\ASTNode $variable * * @return boolean */ private function isNameAllowedInContext(AbstractCallableNode $node, ASTNode $variable) { return ( $node instanceof MethodNode && $variable->getImage() === '$this' && ($node->getModifiers() & State::IS_STATIC) === 0 ); } } phpmd-2.8.1/src/main/php/PHPMD/Rule/Controversial/000077500000000000000000000000001360164303200215435ustar00rootroot00000000000000phpmd-2.8.1/src/main/php/PHPMD/Rule/Controversial/CamelCaseClassName.php000066400000000000000000000025151360164303200256630ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Controversial; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Rule\ClassAware; use PHPMD\Rule\InterfaceAware; /** * This rule class detects classes not named in CamelCase. * * @author Francis Besset * @since 1.1.0 */ class CamelCaseClassName extends AbstractRule implements ClassAware, InterfaceAware { /** * This method checks if a class is not named in CamelCase * and emits a rule violation. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { if (!preg_match('/^[A-Z][a-zA-Z0-9]*$/', $node->getName())) { $this->addViolation( $node, array( $node->getName(), ) ); } } } phpmd-2.8.1/src/main/php/PHPMD/Rule/Controversial/CamelCaseMethodName.php000066400000000000000000000043061360164303200260360ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Controversial; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Rule\MethodAware; /** * This rule class detects methods not named in camelCase. * * @author Francis Besset * @since 1.1.0 */ class CamelCaseMethodName extends AbstractRule implements MethodAware { protected $ignoredMethods = array( '__construct', '__destruct', '__set', '__get', '__call', '__callStatic', '__isset', '__unset', '__sleep', '__wakeup', '__toString', '__invoke', '__set_state', '__clone', '__debugInfo', ); /** * This method checks if a method is not named in camelCase * and emits a rule violation. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { $methodName = $node->getName(); if (!in_array($methodName, $this->ignoredMethods)) { if (!$this->isValid($methodName)) { $this->addViolation( $node, array( $methodName, ) ); } } } private function isValid($methodName) { if ($this->getBooleanProperty('allow-underscore-test') && strpos($methodName, 'test') === 0) { return preg_match('/^test[a-zA-Z0-9]*([_][a-z][a-zA-Z0-9]*)?$/', $methodName); } if ($this->getBooleanProperty('allow-underscore')) { return preg_match('/^[_]?[a-z][a-zA-Z0-9]*$/', $methodName); } return preg_match('/^[a-z][a-zA-Z0-9]*$/', $methodName); } } phpmd-2.8.1/src/main/php/PHPMD/Rule/Controversial/CamelCaseParameterName.php000066400000000000000000000027071360164303200265410ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Controversial; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Rule\FunctionAware; use PHPMD\Rule\MethodAware; /** * This rule class detects parameters not named in camelCase. * * @author Francis Besset * @since 1.1.0 */ class CamelCaseParameterName extends AbstractRule implements MethodAware, FunctionAware { /** * This method checks if a parameter is not named in camelCase * and emits a rule violation. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { foreach ($node->getParameters() as $parameter) { if (!preg_match('/^\$[a-z][a-zA-Z0-9]*$/', $parameter->getName())) { $this->addViolation( $node, array( $parameter->getName(), ) ); } } } } phpmd-2.8.1/src/main/php/PHPMD/Rule/Controversial/CamelCasePropertyName.php000066400000000000000000000032171360164303200264420ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Controversial; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Rule\ClassAware; /** * This rule class detects properties not named in camelCase. * * @author Francis Besset * @since 1.1.0 */ class CamelCasePropertyName extends AbstractRule implements ClassAware { /** * This method checks if a property is not named in camelCase * and emits a rule violation. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { $allowUnderscore = $this->getBooleanProperty('allow-underscore'); $pattern = '/^\$[a-zA-Z][a-zA-Z0-9]*$/'; if ($allowUnderscore == true) { $pattern = '/^\$[_]?[a-zA-Z][a-zA-Z0-9]*$/'; } foreach ($node->getProperties() as $property) { $propertyName = $property->getName(); if (!preg_match($pattern, $propertyName)) { $this->addViolation( $node, array( $propertyName, ) ); } } } } phpmd-2.8.1/src/main/php/PHPMD/Rule/Controversial/CamelCaseVariableName.php000066400000000000000000000036241360164303200263450ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Controversial; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Rule\FunctionAware; use PHPMD\Rule\MethodAware; /** * This rule class detects variables not named in camelCase. * * @author Francis Besset * @since 1.1.0 */ class CamelCaseVariableName extends AbstractRule implements MethodAware, FunctionAware { /** * @var array */ private $exceptions = array( '$php_errormsg', '$http_response_header', '$GLOBALS', '$_SERVER', '$_GET', '$_POST', '$_FILES', '$_COOKIE', '$_SESSION', '$_REQUEST', '$_ENV', ); /** * This method checks if a variable is not named in camelCase * and emits a rule violation. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { foreach ($node->findChildrenOfType('Variable') as $variable) { $image = $variable->getImage(); if (in_array($image, $this->exceptions)) { continue; } if (preg_match('/^\$[a-z][a-zA-Z0-9]*$/', $image)) { continue; } if ($variable->getParent()->isInstanceOf('PropertyPostfix')) { continue; } $this->addViolation($node, array($image)); } } } phpmd-2.8.1/src/main/php/PHPMD/Rule/Controversial/Superglobals.php000066400000000000000000000035071360164303200247230ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Controversial; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Rule\FunctionAware; use PHPMD\Rule\MethodAware; /** * This rule class detects the usage of superglobals. * * @author Francis Besset * @since 1.1.0 */ class Superglobals extends AbstractRule implements MethodAware, FunctionAware { protected $superglobals = array( '$GLOBALS', '$_SERVER', '$HTTP_SERVER_VARS', '$_GET', '$HTTP_GET_VARS', '$_POST', '$HTTP_POST_VARS', '$_FILES', '$HTTP_POST_FILES', '$_COOKIE', '$HTTP_COOKIE_VARS', '$_SESSION', '$HTTP_SESSION_VARS', '$_REQUEST', '$_ENV', '$HTTP_ENV_VARS', ); /** * This method checks if a superglobal is used * and emits a rule violation. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { foreach ($node->findChildrenOfType('Variable') as $variable) { if (in_array($variable->getImage(), $this->superglobals)) { $this->addViolation( $node, array( $node->getName(), $variable->getImage() ) ); } } } } phpmd-2.8.1/src/main/php/PHPMD/Rule/CyclomaticComplexity.php000066400000000000000000000026001360164303200235650ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule; use PHPMD\AbstractNode; use PHPMD\AbstractRule; /** * This rule checks a given method or function against the configured cyclomatic * complexity threshold. */ class CyclomaticComplexity extends AbstractRule implements FunctionAware, MethodAware { /** * This method checks the cyclomatic complexity for the given node against * a configured threshold. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { $threshold = $this->getIntProperty('reportLevel'); $ccn = $node->getMetric('ccn2'); if ($ccn < $threshold) { return; } $this->addViolation( $node, array( $node->getType(), $node->getName(), $ccn, $threshold ) ); } } phpmd-2.8.1/src/main/php/PHPMD/Rule/Design/000077500000000000000000000000001360164303200201225ustar00rootroot00000000000000phpmd-2.8.1/src/main/php/PHPMD/Rule/Design/CountInLoopExpression.php000066400000000000000000000110531360164303200251240ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PDepend\Source\AST\AbstractASTNode; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Node\ASTNode; use PHPMD\Node\ClassNode; use PHPMD\Rule\ClassAware; /** * Count In Loop Expression Rule * * Performs a scan to check if loops use * count() or sizeof() in expressions. * * Checks for: * - for() loops * - while() loops * - do-while() loops * * @author Kamil Szymanski */ class CountInLoopExpression extends AbstractRule implements ClassAware { /** * List of functions to search against * * @var array */ private $unwantedFunctions = array('count', 'sizeof'); /** * List of already processed functions * * @var array */ protected $processedFunctions = array(); /** * Functions in classes tends to be name-spaced * * @var string */ protected $currentNamespace = ''; /** * Gets a list of loops in a node and iterates over them * * @param AbstractNode $node * @return void */ public function apply(AbstractNode $node) { if ($node instanceof ClassNode) { return $this->applyOnClassMethods($node); } $this->currentNamespace = $node->getNamespaceName() . '\\'; $loops = array_merge( $node->findChildrenOfType('ForStatement'), $node->findChildrenOfType('WhileStatement'), $node->findChildrenOfType('DoWhileStatement') ); /** @var AbstractNode $loop */ foreach ($loops as $loop) { $this->findViolations($loop); } } /** * Scans for expressions and count() or sizeof() functions inside, * if found, triggers a violation * * @param AbstractNode $loop Loop statement to look against */ protected function findViolations(AbstractNode $loop) { foreach ($loop->findChildrenOfType('Expression') as $expression) { if ($this->isDirectChild($loop, $expression)) { continue; } foreach ($expression->findChildrenOfType('FunctionPostfix') as $function) { if (!$this->isUnwantedFunction($function)) { continue; } $hash = $this->getHash($function->getNode()); if (isset($this->processedFunctions[$hash])) { continue; } $this->addViolation($loop, array($function->getImage(), $loop->getImage())); $this->processedFunctions[$hash] = true; } } } /** * Checks whether node in a direct child of the loop * * @param AbstractNode $loop * @param ASTNode $expression * @return bool */ protected function isDirectChild(AbstractNode $loop, ASTNode $expression) { return $this->getHash($expression->getParent()->getNode()) !== $this->getHash($loop->getNode()); } /** * Generates an unique hash for a given node * * PDepend method getChildrenOfType() iterates trough all children of a node. * As one function may be found more than once, we use a hash (which in reality * is a clone of the node's metadata) to check, if a given node hasn't * already been processed. * * Example hash: * 22:22:10:15:PHPMD\count * * @param AbstractASTNode $node * @return string */ protected function getHash(AbstractASTNode $node) { return sprintf( '%s:%s:%s:%s:%s', $node->getStartLine(), $node->getEndLine(), $node->getStartColumn(), $node->getEndColumn(), $node->getImage() ); } /** * Checks the given function against the list of unwanted functions * * @param ASTNode $function * @return bool */ protected function isUnwantedFunction(ASTNode $function) { $functionName = str_replace($this->currentNamespace, '', $function->getImage()); return in_array($functionName, $this->unwantedFunctions); } } phpmd-2.8.1/src/main/php/PHPMD/Rule/Design/CouplingBetweenObjects.php000066400000000000000000000024251360164303200252420ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Rule\ClassAware; /** * This rule class detects violations of Coupling Between Objects metric. * * @since 1.1.0 */ class CouplingBetweenObjects extends AbstractRule implements ClassAware { /** * This method should implement the violation analysis algorithm of concrete * rule implementations. All extending classes must implement this method. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { $cbo = $node->getMetric('cbo'); if ($cbo >= ($threshold = $this->getIntProperty('maximum'))) { $this->addViolation($node, array($node->getName(), $cbo, $threshold)); } } } phpmd-2.8.1/src/main/php/PHPMD/Rule/Design/DepthOfInheritance.php000066400000000000000000000031721360164303200243410ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Rule\ClassAware; /** * This rule will detect classes that are to deep in the inheritance tree. */ class DepthOfInheritance extends AbstractRule implements ClassAware { /** * This method checks the number of parents for the given class * node. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { try { $threshold = $this->getIntProperty('maximum'); $comparision = 1; } catch (\OutOfBoundsException $e) { $threshold = $this->getIntProperty('minimum'); $comparision = 2; } $dit = $node->getMetric('dit'); if (($comparision === 1 && $dit > $threshold) || ($comparision === 2 && $dit >= $threshold) ) { $this->addViolation( $node, array( $node->getType(), $node->getName(), $dit, $threshold ) ); } } } phpmd-2.8.1/src/main/php/PHPMD/Rule/Design/DevelopmentCodeFragment.php000066400000000000000000000046541360164303200254050ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Node\MethodNode; use PHPMD\Rule\FunctionAware; use PHPMD\Rule\MethodAware; /** * This rule class detects possible development code fragments that were left * into the code. * * @link https://github.com/phpmd/phpmd/issues/265 * @since 2.3.0 */ class DevelopmentCodeFragment extends AbstractRule implements MethodAware, FunctionAware { /** * This method checks if a given function or method contains an eval-expression * and emits a rule violation when it exists. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { $ignoreNS = $this->getBooleanProperty('ignore-namespaces'); $namespace = $node->getNamespaceName(); foreach ($node->findChildrenOfType('FunctionPostfix') as $postfix) { $fragment = $postfix->getImage(); if ($ignoreNS) { $fragment = str_replace("{$namespace}\\", "", $fragment); } $fragment = strtolower($fragment); if (false === in_array($fragment, $this->getSuspectImages())) { continue; } $image = $node->getImage(); if ($node instanceof MethodNode) { $image = sprintf('%s::%s', $node->getParentName(), $node->getImage()); } $this->addViolation($postfix, array($node->getType(), $image, $fragment)); } } /** * Returns an array with function images that are normally only used during * development. * * @return array */ private function getSuspectImages() { return array_map( 'strtolower', array_map( 'trim', explode( ',', $this->getStringProperty('unwanted-functions') ) ) ); } } phpmd-2.8.1/src/main/php/PHPMD/Rule/Design/EmptyCatchBlock.php000066400000000000000000000027101360164303200236470ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Rule\FunctionAware; use PHPMD\Rule\MethodAware; /** * This rule class detects empty catch blocks * * @author Grégoire Paris * @author Kamil Szymanski */ class EmptyCatchBlock extends AbstractRule implements MethodAware, FunctionAware { /** * This method checks if a given function or method contains an empty catch block * and emits a rule violation when it exists. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { foreach ($node->findChildrenOfType('CatchStatement') as $catchBlock) { $scope = $catchBlock->getFirstChildOfType('ScopeStatement'); if (count($scope->getChildren()) == 0) { $this->addViolation($catchBlock, array($node->getName())); } } } } phpmd-2.8.1/src/main/php/PHPMD/Rule/Design/EvalExpression.php000066400000000000000000000023311360164303200236010ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Rule\FunctionAware; use PHPMD\Rule\MethodAware; /** * This rule class detects the usage of PHP's eval-expression. */ class EvalExpression extends AbstractRule implements MethodAware, FunctionAware { /** * This method checks if a given function or method contains an eval-expression * and emits a rule violation when it exists. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { foreach ($node->findChildrenOfType('EvalExpression') as $eval) { $this->addViolation($eval, array($node->getType(), $node->getName())); } } } phpmd-2.8.1/src/main/php/PHPMD/Rule/Design/ExitExpression.php000066400000000000000000000023301360164303200236220ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Rule\FunctionAware; use PHPMD\Rule\MethodAware; /** * This rule class detects the usage of PHP's exit statement. */ class ExitExpression extends AbstractRule implements MethodAware, FunctionAware { /** * This method checks if a given function or method contains an exit-expression * and emits a rule violation when it exists. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { foreach ($node->findChildrenOfType('ExitExpression') as $exit) { $this->addViolation($exit, array($node->getType(), $node->getName())); } } } phpmd-2.8.1/src/main/php/PHPMD/Rule/Design/GotoStatement.php000066400000000000000000000024101360164303200234250ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Rule\FunctionAware; use PHPMD\Rule\MethodAware; /** * This rule class detects the usage of PHP's goto statement. * * @since 1.1.0 */ class GotoStatement extends AbstractRule implements MethodAware, FunctionAware { /** * This method should implement the violation analysis algorithm of concrete * rule implementations. All extending classes must implement this method. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { foreach ($node->findChildrenOfType('GotoStatement') as $goto) { $this->addViolation($goto, array($node->getType(), $node->getName())); } } } phpmd-2.8.1/src/main/php/PHPMD/Rule/Design/LongClass.php000066400000000000000000000025661360164303200225310ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Rule\ClassAware; /** * This rule class will detect excessive long classes. */ class LongClass extends AbstractRule implements ClassAware { /** * This method checks the length of the given class node against a configured * threshold. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { $threshold = $this->getIntProperty('minimum'); $loc = -1; if ($this->getBooleanProperty('ignore-whitespace')) { $loc = $node->getMetric('eloc'); } if (-1 === $loc) { $loc = $node->getMetric('loc'); } if ($loc < $threshold) { return; } $this->addViolation($node, array($node->getName(), $loc, $threshold)); } } phpmd-2.8.1/src/main/php/PHPMD/Rule/Design/LongMethod.php000066400000000000000000000032171360164303200226760ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Rule\FunctionAware; use PHPMD\Rule\MethodAware; /** * This rule will detect to long methods, those methods are unreadable and in * many cases the result of copy and paste coding. */ class LongMethod extends AbstractRule implements FunctionAware, MethodAware { /** * This method checks the lines of code length for the given function or * methode node against a configured threshold. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { $threshold = $this->getIntProperty('minimum'); $loc = -1; if ($this->getBooleanProperty('ignore-whitespace')) { $loc = $node->getMetric('eloc'); } if (-1 === $loc) { $loc = $node->getMetric('loc'); } if ($loc < $threshold) { return; } $this->addViolation( $node, array( $node->getType(), $node->getName(), $loc, $threshold ) ); } } phpmd-2.8.1/src/main/php/PHPMD/Rule/Design/LongParameterList.php000066400000000000000000000026731360164303200242370ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Rule\FunctionAware; use PHPMD\Rule\MethodAware; /** * This rule class checks for excessive long function and method parameter lists. */ class LongParameterList extends AbstractRule implements FunctionAware, MethodAware { /** * This method checks the number of arguments for the given function or method * node against a configured threshold. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { $threshold = $this->getIntProperty('minimum'); $count = $node->getParameterCount(); if ($count < $threshold) { return; } $this->addViolation( $node, array( $node->getType(), $node->getName(), $count, $threshold ) ); } } phpmd-2.8.1/src/main/php/PHPMD/Rule/Design/NpathComplexity.php000066400000000000000000000026741360164303200237740ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Rule\FunctionAware; use PHPMD\Rule\MethodAware; /** * This rule will check the NPath-complexity of a method or function against the * configured threshold. */ class NpathComplexity extends AbstractRule implements FunctionAware, MethodAware { /** * This method checks the acyclic complexity for the given node against a * configured threshold. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { $threshold = $this->getIntProperty('minimum'); $npath = $node->getMetric('npath'); if ($npath < $threshold) { return; } $this->addViolation( $node, array( $node->getType(), $node->getName(), $npath, $threshold ) ); } } phpmd-2.8.1/src/main/php/PHPMD/Rule/Design/NumberOfChildren.php000066400000000000000000000025461360164303200240300ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Rule\ClassAware; /** * This rule will detect class that have to much direct child classes. */ class NumberOfChildren extends AbstractRule implements ClassAware { /** * This method checks the number of classes derived from the given class * node. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { $nocc = $node->getMetric('nocc'); $threshold = $this->getIntProperty('minimum'); if ($nocc >= $threshold) { $this->addViolation( $node, array( $node->getType(), $node->getName(), $nocc, $threshold ) ); } } } phpmd-2.8.1/src/main/php/PHPMD/Rule/Design/TooManyFields.php000066400000000000000000000025711360164303200233550ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Rule\ClassAware; /** * This rule class will detect all classes with too much fields. */ class TooManyFields extends AbstractRule implements ClassAware { /** * This method checks the number of methods with in a given class and checks * this number against a configured threshold. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { $threshold = $this->getIntProperty('maxfields'); $vars = $node->getMetric('vars'); if ($vars <= $threshold) { return; } $this->addViolation( $node, array( $node->getType(), $node->getName(), $vars, $threshold ) ); } } phpmd-2.8.1/src/main/php/PHPMD/Rule/Design/TooManyMethods.php000066400000000000000000000042651360164303200235540ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Node\AbstractTypeNode; use PHPMD\Rule\ClassAware; /** * This rule class will detect all classes with too much methods. */ class TooManyMethods extends AbstractRule implements ClassAware { /** * Regular expression that filters all methods that are ignored by this rule. * * @var string */ private $ignoreRegexp; /** * This method checks the number of methods with in a given class and checks * this number against a configured threshold. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { $this->ignoreRegexp = $this->getStringProperty('ignorepattern'); $threshold = $this->getIntProperty('maxmethods'); if ($node->getMetric('nom') <= $threshold) { return; } /** @var AbstractTypeNode $node */ $nom = $this->countMethods($node); if ($nom <= $threshold) { return; } $this->addViolation( $node, array( $node->getType(), $node->getName(), $nom, $threshold ) ); } /** * Counts all methods within the given class/interface node. * * @param \PHPMD\Node\AbstractTypeNode $node * @return integer */ private function countMethods(AbstractTypeNode $node) { $count = 0; foreach ($node->getMethodNames() as $name) { if (preg_match($this->ignoreRegexp, $name) === 0) { ++$count; } } return $count; } } phpmd-2.8.1/src/main/php/PHPMD/Rule/Design/TooManyPublicMethods.php000066400000000000000000000043711360164303200247110ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Node\AbstractTypeNode; use PHPMD\Rule\ClassAware; /** * This rule class will detect all classes with too much public methods. */ class TooManyPublicMethods extends AbstractRule implements ClassAware { /** * Regular expression that filters all methods that are ignored by this rule. * * @var string */ private $ignoreRegexp; /** * This method checks the number of public methods with in a given class and checks * this number against a configured threshold. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { $this->ignoreRegexp = $this->getStringProperty('ignorepattern'); $threshold = $this->getIntProperty('maxmethods'); if ($node->getMetric('npm') <= $threshold) { return; } /** @var AbstractTypeNode $node */ $nom = $this->countMethods($node); if ($nom <= $threshold) { return; } $this->addViolation( $node, array( $node->getType(), $node->getName(), $nom, $threshold ) ); } /** * Counts public methods within the given class/interface node. * * @param \PHPMD\Node\AbstractTypeNode $node * @return integer */ private function countMethods(AbstractTypeNode $node) { $count = 0; foreach ($node->getMethods() as $method) { if ($method->getNode()->isPublic() && preg_match($this->ignoreRegexp, $method->getName()) === 0) { ++$count; } } return $count; } } phpmd-2.8.1/src/main/php/PHPMD/Rule/Design/WeightedMethodCount.php000066400000000000000000000024211360164303200245440ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Rule\ClassAware; /** * This rule checks a given class against a configured weighted method count * threshold. * * @since 0.2.5 */ class WeightedMethodCount extends AbstractRule implements ClassAware { /** * This method checks the weighted method count for the given class against * a configured threshold. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { $threshold = $this->getIntProperty('maximum'); $actual = $node->getMetric('wmc'); if ($actual >= $threshold) { $this->addViolation($node, array($node->getName(), $actual, $threshold)); } } } phpmd-2.8.1/src/main/php/PHPMD/Rule/ExcessivePublicCount.php000066400000000000000000000027031360164303200235320ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule; use PHPMD\AbstractNode; use PHPMD\AbstractRule; /** * This rule checks the number of public methods and fields in a given class. * Then it compares the number of public members against a configured threshold. */ class ExcessivePublicCount extends AbstractRule implements ClassAware { /** * This method checks the number of public fields and methods in the given * class and checks that value against a configured threshold. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { $threshold = $this->getIntProperty('minimum'); $cis = $node->getMetric('cis'); if ($cis < $threshold) { return; } $this->addViolation( $node, array( $node->getType(), $node->getName(), $cis, $threshold ) ); } } phpmd-2.8.1/src/main/php/PHPMD/Rule/FunctionAware.php000066400000000000000000000012021360164303200221620ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule; /** * This interface is used to mark a rule implementation as function aware. */ interface FunctionAware { } phpmd-2.8.1/src/main/php/PHPMD/Rule/InterfaceAware.php000066400000000000000000000011721360164303200223030ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule; /** * This interface marks a rule implementation as interface aware, */ interface InterfaceAware { } phpmd-2.8.1/src/main/php/PHPMD/Rule/MethodAware.php000066400000000000000000000011641360164303200216240ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule; /** * This interface marks a rule implementation as method aware, */ interface MethodAware { } phpmd-2.8.1/src/main/php/PHPMD/Rule/Naming/000077500000000000000000000000001360164303200201225ustar00rootroot00000000000000phpmd-2.8.1/src/main/php/PHPMD/Rule/Naming/BooleanGetMethodName.php000066400000000000000000000054061360164303200246210ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Naming; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Node\MethodNode; use PHPMD\Rule\MethodAware; /** * This rule tests that a method which returns a boolean value does not start * with get or _get for a getter. */ class BooleanGetMethodName extends AbstractRule implements MethodAware { /** * Extracts all variable and variable declarator nodes from the given node * and checks the variable name length against the configured minimum * length. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { /** @var $node MethodNode */ if ($this->isBooleanGetMethod($node)) { $this->addViolation($node, array($node->getImage())); } } /** * Tests if the given method matches all criteria to be an invalid * boolean get method. * * @param \PHPMD\Node\MethodNode $node * @return boolean */ private function isBooleanGetMethod(MethodNode $node) { return $this->isGetterMethodName($node) && $this->isReturnTypeBoolean($node) && $this->isParameterizedOrIgnored($node); } /** * Tests if the given method starts with get or _get. * * @param \PHPMD\Node\MethodNode $node * @return boolean */ private function isGetterMethodName(MethodNode $node) { return (preg_match('(^_?get)i', $node->getImage()) > 0); } /** * Tests if the given method is declared with return type boolean. * * @param \PHPMD\Node\MethodNode $node * @return boolean */ private function isReturnTypeBoolean(MethodNode $node) { $comment = $node->getDocComment(); return (preg_match('(\*\s*@return\s+bool(ean)?\s)i', $comment) > 0); } /** * Tests if the property $checkParameterizedMethods is set to true * or has no parameters. * * @param \PHPMD\Node\MethodNode $node * @return boolean */ private function isParameterizedOrIgnored(MethodNode $node) { if ($this->getBooleanProperty('checkParameterizedMethods')) { return $node->getParameterCount() === 0; } return true; } } phpmd-2.8.1/src/main/php/PHPMD/Rule/Naming/ConstantNamingConventions.php000066400000000000000000000025541360164303200260120ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Naming; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Rule\ClassAware; use PHPMD\Rule\InterfaceAware; /** * This rule detects class/interface constants that do not follow the upper * case convention. */ class ConstantNamingConventions extends AbstractRule implements ClassAware, InterfaceAware { /** * Extracts all constant declarations from the given node and tests that * the image only contains upper case characters. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { foreach ($node->findChildrenOfType('ConstantDeclarator') as $declarator) { if ($declarator->getImage() !== strtoupper($declarator->getImage())) { $this->addViolation($declarator, array($declarator->getImage())); } } } } phpmd-2.8.1/src/main/php/PHPMD/Rule/Naming/ConstructorWithNameAsEnclosingClass.php000066400000000000000000000030241360164303200277300ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Naming; use PDepend\Source\AST\ASTTrait; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Node\InterfaceNode; use PHPMD\Rule\MethodAware; /** * This rule class will detect methods that define a php4 style constructor * method while has the same name as the enclosing class. */ class ConstructorWithNameAsEnclosingClass extends AbstractRule implements MethodAware { /** * Is method has the same name as the enclosing class * (php4 style constructor). * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { if ($node->getNode()->getParent() instanceof ASTTrait) { return; } if (strcasecmp($node->getName(), $node->getParentName()) !== 0) { return; } if ($node->getParentType() instanceof InterfaceNode) { return; } if ($node->getNamespaceName() !== '+global') { return; } $this->addViolation($node); } } phpmd-2.8.1/src/main/php/PHPMD/Rule/Naming/LongVariable.php000066400000000000000000000112311360164303200231760ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Naming; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Rule\ClassAware; use PHPMD\Rule\FunctionAware; use PHPMD\Rule\MethodAware; /** * This rule class will detect variables, parameters and properties with really * long names. */ class LongVariable extends AbstractRule implements ClassAware, MethodAware, FunctionAware { /** * Temporary map holding variables that were already processed in the * current context. * * @var array(string=>boolean) */ private $processedVariables = array(); /** * Extracts all variable and variable declarator nodes from the given node * and checks the variable name length against the configured maximum * length. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { $this->resetProcessed(); if ($node->getType() === 'class') { $fields = $node->findChildrenOfType('FieldDeclaration'); foreach ($fields as $field) { $declarators = $field->findChildrenOfType('VariableDeclarator'); foreach ($declarators as $declarator) { $this->checkNodeImage($declarator); } } $this->resetProcessed(); return; } $declarators = $node->findChildrenOfType('VariableDeclarator'); foreach ($declarators as $declarator) { $this->checkNodeImage($declarator); } $variables = $node->findChildrenOfType('Variable'); foreach ($variables as $variable) { $this->checkNodeImage($variable); } $this->resetProcessed(); } /** * Checks if the variable name of the given node is smaller/equal to the * configured threshold. * * @param \PHPMD\AbstractNode $node * @return void */ protected function checkNodeImage(AbstractNode $node) { if ($this->isNotProcessed($node)) { $this->addProcessed($node); $this->checkMaximumLength($node); } } /** * Template method that performs the real node image check. * * @param \PHPMD\AbstractNode $node * @return void */ protected function checkMaximumLength(AbstractNode $node) { $threshold = $this->getIntProperty('maximum'); if ($threshold >= strlen($node->getImage()) - 1) { return; } if ($this->isNameAllowedInContext($node)) { return; } $this->addViolation($node, array($node->getImage(), $threshold)); } /** * Checks if a short name is acceptable in the current context. For the * moment the only context is a static member. * * @param \PHPMD\AbstractNode $node * @return boolean */ private function isNameAllowedInContext(AbstractNode $node) { return $this->isChildOf($node, 'MemberPrimaryPrefix'); } /** * Checks if the given node is a direct or indirect child of a node with * the given type. * * @param \PHPMD\AbstractNode $node * @param string $type * @return boolean */ private function isChildOf(AbstractNode $node, $type) { $parent = $node->getParent(); while (is_object($parent)) { if ($parent->isInstanceOf($type)) { return true; } $parent = $parent->getParent(); } return false; } /** * Resets the already processed nodes. * * @return void */ protected function resetProcessed() { $this->processedVariables = array(); } /** * Flags the given node as already processed. * * @param \PHPMD\AbstractNode $node * @return void */ protected function addProcessed(AbstractNode $node) { $this->processedVariables[$node->getImage()] = true; } /** * Checks if the given node was already processed. * * @param \PHPMD\AbstractNode $node * @return boolean */ protected function isNotProcessed(AbstractNode $node) { return !isset($this->processedVariables[$node->getImage()]); } } phpmd-2.8.1/src/main/php/PHPMD/Rule/Naming/ShortMethodName.php000066400000000000000000000036311360164303200236770ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Naming; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Rule\FunctionAware; use PHPMD\Rule\MethodAware; /** * This rule class will detect methods and functions with very short names. */ class ShortMethodName extends AbstractRule implements MethodAware, FunctionAware { /** * Extracts all variable and variable declarator nodes from the given node * and checks the variable name length against the configured minimum * length. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { $threshold = $this->getIntProperty('minimum'); if ($threshold <= strlen($node->getName())) { return; } $exceptions = $this->getExceptionsList(); if (in_array($node->getName(), $exceptions)) { return; } $this->addViolation( $node, array( $node->getParentName(), $node->getName(), $threshold ) ); } /** * Gets array of exceptions from property * * @return array */ private function getExceptionsList() { try { $exceptions = $this->getStringProperty('exceptions'); } catch (\OutOfBoundsException $e) { $exceptions = ''; } return explode(',', $exceptions); } } phpmd-2.8.1/src/main/php/PHPMD/Rule/Naming/ShortVariable.php000066400000000000000000000141341360164303200234030ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Naming; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Rule\ClassAware; use PHPMD\Rule\FunctionAware; use PHPMD\Rule\MethodAware; /** * This rule class will detect variables, parameters and properties with short * names. */ class ShortVariable extends AbstractRule implements ClassAware, MethodAware, FunctionAware { /** * Temporary map holding variables that were already processed in the * current context. * * @var array(string=>boolean) */ private $processedVariables = array(); /** * Extracts all variable and variable declarator nodes from the given node * * Checks the variable name length against the configured minimum * length. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { $this->resetProcessed(); if ($node->getType() === 'class') { $this->applyClass($node); return; } $this->applyNonClass($node); } /** * Extracts all variable and variable declarator nodes from the given class node * * Checks the variable name length against the configured minimum * length. * * @param AbstractNode $node * @return void */ private function applyClass(AbstractNode $node) { $fields = $node->findChildrenOfType('FieldDeclaration'); foreach ($fields as $field) { $declarators = $field->findChildrenOfType('VariableDeclarator'); foreach ($declarators as $declarator) { $this->checkNodeImage($declarator); } } $this->resetProcessed(); } /** * Extracts all variable and variable declarator nodes from the given non-class node * * Checks the variable name length against the configured minimum * length. * * @param AbstractNode $node * @return void */ private function applyNonClass(AbstractNode $node) { $declarators = $node->findChildrenOfType('VariableDeclarator'); foreach ($declarators as $declarator) { $this->checkNodeImage($declarator); } $variables = $node->findChildrenOfType('Variable'); foreach ($variables as $variable) { $this->checkNodeImage($variable); } $this->resetProcessed(); } /** * Checks if the variable name of the given node is greater/equal to the * configured threshold or if the given node is an allowed context. * * @param \PHPMD\AbstractNode $node * @return void */ protected function checkNodeImage(AbstractNode $node) { if ($this->isNotProcessed($node)) { $this->addProcessed($node); $this->checkMinimumLength($node); } } /** * Template method that performs the real node image check. * * @param \PHPMD\AbstractNode $node * @return void */ protected function checkMinimumLength(AbstractNode $node) { $threshold = $this->getIntProperty('minimum'); if ($threshold <= strlen($node->getImage()) - 1) { return; } if ($this->isNameAllowedInContext($node)) { return; } $exceptions = $this->getExceptionsList(); if (in_array(substr($node->getImage(), 1), $exceptions)) { return; } $this->addViolation($node, array($node->getImage(), $threshold)); } /** * Gets array of exceptions from property * * @return array */ private function getExceptionsList() { try { $exceptions = $this->getStringProperty('exceptions'); } catch (\OutOfBoundsException $e) { $exceptions = ''; } return explode(',', $exceptions); } /** * Checks if a short name is acceptable in the current context. For the * moment these contexts are the init section of a for-loop and short * variable names in catch-statements. * * @param \PHPMD\AbstractNode $node * @return boolean */ private function isNameAllowedInContext(AbstractNode $node) { return $this->isChildOf($node, 'CatchStatement') || $this->isChildOf($node, 'ForInit') || $this->isChildOf($node, 'ForeachStatement') || $this->isChildOf($node, 'MemberPrimaryPrefix'); } /** * Checks if the given node is a direct or indirect child of a node with * the given type. * * @param \PHPMD\AbstractNode $node * @param string $type * @return boolean */ private function isChildOf(AbstractNode $node, $type) { $parent = $node->getParent(); while (is_object($parent)) { if ($parent->isInstanceOf($type)) { return true; } $parent = $parent->getParent(); } return false; } /** * Resets the already processed nodes. * * @return void */ protected function resetProcessed() { $this->processedVariables = array(); } /** * Flags the given node as already processed. * * @param \PHPMD\AbstractNode $node * @return void */ protected function addProcessed(AbstractNode $node) { $this->processedVariables[$node->getImage()] = true; } /** * Checks if the given node was already processed. * * @param \PHPMD\AbstractNode $node * @return boolean */ protected function isNotProcessed(AbstractNode $node) { return !isset($this->processedVariables[$node->getImage()]); } } phpmd-2.8.1/src/main/php/PHPMD/Rule/UnusedFormalParameter.php000066400000000000000000000163201360164303200236710ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule; use PHPMD\AbstractNode; use PHPMD\Node\ASTNode; use PHPMD\Node\MethodNode; /** * This rule collects all formal parameters of a given function or method that * are not used in a statement of the artifact's body. */ class UnusedFormalParameter extends AbstractLocalVariable implements FunctionAware, MethodAware { /** * Collected ast nodes. * * @var \PHPMD\Node\ASTNode[] */ private $nodes = array(); /** * This method checks that all parameters of a given function or method are * used at least one time within the artifacts body. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { if ($this->isAbstractMethod($node)) { return; } // Magic methods should be ignored as invalid declarations are picked up by PHP. if ($this->isMagicMethod($node)) { return; } if ($this->isInheritedSignature($node)) { return; } if ($this->isNotDeclaration($node)) { return; } $this->nodes = array(); $this->collectParameters($node); $this->removeUsedParameters($node); foreach ($this->nodes as $node) { $this->addViolation($node, array($node->getImage())); } } /** * Returns true when the given node is an abstract method. * * @param \PHPMD\AbstractNode $node * @return boolean */ private function isAbstractMethod(AbstractNode $node) { if ($node instanceof MethodNode) { return $node->isAbstract(); } return false; } /** * Returns true when the given node is method with signature declared as inherited using * {@inheritdoc} annotation. * * @param \PHPMD\AbstractNode $node * @return boolean */ private function isInheritedSignature(AbstractNode $node) { if ($node instanceof MethodNode) { return preg_match('/\@inheritdoc/i', $node->getDocComment()); } return false; } /** * Returns true when the given node is a magic method signature * @param AbstractNode $node * @return boolean */ private function isMagicMethod(AbstractNode $node) { static $names = array( 'call', 'callStatic', 'get', 'set', 'isset', 'unset', 'set_state' ); if ($node instanceof MethodNode) { return preg_match('/\__(?:' . implode("|", $names) . ')/i', $node->getName()); } return false; } /** * Tests if the given $node is a method and if this method is also * the initial declaration. * * @param \PHPMD\AbstractNode $node * @return boolean * @since 1.2.1 */ private function isNotDeclaration(AbstractNode $node) { if ($node instanceof MethodNode) { return !$node->isDeclaration(); } return false; } /** * This method extracts all parameters for the given function or method node * and it stores the parameter images in the $_images property. * * @param \PHPMD\AbstractNode $node * @return void */ private function collectParameters(AbstractNode $node) { // First collect the formal parameters container $parameters = $node->getFirstChildOfType('FormalParameters'); // Now get all declarators in the formal parameters container $declarators = $parameters->findChildrenOfType('VariableDeclarator'); foreach ($declarators as $declarator) { $this->nodes[$declarator->getImage()] = $declarator; } } /** * This method collects all local variables in the body of the currently * analyzed method or function and removes those parameters that are * referenced by one of the collected variables. * * @param \PHPMD\AbstractNode $node * @return void */ private function removeUsedParameters(AbstractNode $node) { $this->removeRegularVariables($node); $this->removeCompoundVariables($node); $this->removeVariablesUsedByFuncGetArgs($node); } /** * Removes all the regular variables from a given node * * @param \PHPMD\AbstractNode $node The node to remove the regular variables from. * @return void */ private function removeRegularVariables(AbstractNode $node) { $variables = $node->findChildrenOfType('Variable'); foreach ($variables as $variable) { /** @var $variable ASTNode */ if ($this->isRegularVariable($variable)) { unset($this->nodes[$variable->getImage()]); } } } /** * Removes all the compound variables from a given node * * Such as * * * // ------ * Foo::${BAR}(); * // ------ * * // ------ * Foo::$${BAR}(); * // ------ * * * @param \PHPMD\AbstractNode $node The node to remove the compound variables from. * @return void */ private function removeCompoundVariables(AbstractNode $node) { $compoundVariables = $node->findChildrenOfType('CompoundVariable'); foreach ($compoundVariables as $compoundVariable) { $variablePrefix = $compoundVariable->getImage(); foreach ($compoundVariable->findChildrenOfType('Expression') as $child) { $variableImage = $variablePrefix . $child->getImage(); if (isset($this->nodes[$variableImage])) { unset($this->nodes[$variableImage]); } } } } /** * Removes all the variables from a given node, if func_get_args() is called within * * If the given method calls func_get_args() then all parameters are automatically referenced. * * @param \PHPMD\AbstractNode $node The node to remove the referneced variables from. * @return void */ private function removeVariablesUsedByFuncGetArgs(AbstractNode $node) { $functionCalls = $node->findChildrenOfType('FunctionPostfix'); foreach ($functionCalls as $functionCall) { if ($this->isFunctionNameEqual($functionCall, 'func_get_args')) { $this->nodes = array(); } if ($this->isFunctionNameEndingWith($functionCall, 'compact')) { foreach ($functionCall->findChildrenOfType('Literal') as $literal) { unset($this->nodes['$' . trim($literal->getImage(), '"\'')]); } } } } } phpmd-2.8.1/src/main/php/PHPMD/Rule/UnusedLocalVariable.php000066400000000000000000000172321360164303200233130ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule; use PHPMD\AbstractNode; use PHPMD\Node\AbstractCallableNode; use PHPMD\Node\ASTNode; /** * This rule collects all local variables within a given function or method * that are not used by any code in the analyzed source artifact. */ class UnusedLocalVariable extends AbstractLocalVariable implements FunctionAware, MethodAware { /** * Found variable images within a single method or function. * * @var array(string) */ private $images = array(); /** * This method checks that all local variables within the given function or * method are used at least one time. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { $this->images = array(); /** @var $node AbstractCallableNode */ $this->collectVariables($node); $this->removeParameters($node); foreach ($this->images as $nodes) { if (count($nodes) === 1) { $this->doCheckNodeImage($nodes[0]); } } } /** * This method removes all variables from the $_images property that * are also found in the formal parameters of the given method or/and * function node. * * @param \PHPMD\Node\AbstractCallableNode $node * @return void */ private function removeParameters(AbstractCallableNode $node) { // Get formal parameter container $parameters = $node->getFirstChildOfType('FormalParameters'); // Now get all declarators in the formal parameters container $declarators = $parameters->findChildrenOfType('VariableDeclarator'); foreach ($declarators as $declarator) { unset($this->images[$declarator->getImage()]); } } /** * This method collects all local variable instances from the given * method/function node and stores their image in the $_images * property. * * * @param \PHPMD\Node\AbstractCallableNode $node * @return void */ private function collectVariables(AbstractCallableNode $node) { foreach ($node->findChildrenOfType('Variable') as $variable) { /** @var $variable ASTNode */ if ($this->isLocal($variable)) { $this->collectVariable($variable); } } foreach ($node->findChildrenOfType('CompoundVariable') as $variable) { $this->collectCompoundVariableInString($variable); } foreach ($node->findChildrenOfType('VariableDeclarator') as $variable) { $this->collectVariable($variable); } foreach ($node->findChildrenOfType('FunctionPostfix') as $func) { if ($this->isFunctionNameEndingWith($func, 'compact')) { foreach ($func->findChildrenOfType('Literal') as $literal) { /** @var $literal ASTNode */ $this->collectLiteral($literal); } } } } /** * Stores the given compound variable node in an internal list of found variables. * * @param \PHPMD\Node\ASTNode $node * @return void */ private function collectCompoundVariableInString(ASTNode $node) { $parentNode = $node->getParent()->getNode(); $candidateParentNodes = $node->getParentsOfType('PDepend\Source\AST\ASTString'); if (in_array($parentNode, $candidateParentNodes)) { $variablePrefix = $node->getImage(); foreach ($node->findChildrenOfType('Expression') as $child) { $variableName = $child->getImage(); $variableImage = $variablePrefix . $variableName; $this->storeImage($variableImage, $node); } } } /** * Stores the given variable node in an internal list of found variables. * * @param \PHPMD\Node\ASTNode $node * @return void */ private function collectVariable(ASTNode $node) { $imageName = $node->getImage(); $this->storeImage($imageName, $node); } /** * Safely add node to $this->images. * * @param string $imageName the name to store the node as * @param \PHPMD\Node\ASTNode $node the node being stored * @return void */ private function storeImage($imageName, ASTNode $node) { if (!isset($this->images[$imageName])) { $this->images[$imageName] = array(); } $this->images[$imageName][] = $node; } /** * Stores the given literal node in an internal list of found variables. * * @param \PHPMD\Node\ASTNode $node * @return void */ private function collectLiteral(ASTNode $node) { $variable = '$' . trim($node->getImage(), '\''); if (!isset($this->images[$variable])) { $this->images[$variable] = array(); } $this->images[$variable][] = $node; } /** * Template method that performs the real node image check. * * @param ASTNode $node * @return void */ protected function doCheckNodeImage(ASTNode $node) { if ($this->isNameAllowedInContext($node)) { return; } if ($this->isUnusedForeachVariableAllowed($node)) { return; } $exceptions = $this->getExceptionsList(); if (in_array(substr($node->getImage(), 1), $exceptions)) { return; } $this->addViolation($node, array($node->getImage())); } /** * Checks if a short name is acceptable in the current context. For the * moment these contexts are the init section of a for-loop and short * variable names in catch-statements. * * @param \PHPMD\AbstractNode $node * @return boolean */ private function isNameAllowedInContext(AbstractNode $node) { return $this->isChildOf($node, 'CatchStatement'); } /** * Checks if an unused foreach variable (key or variable) is allowed. * * If it's not a foreach variable, it returns always false. * * @param \PHPMD\Node\ASTNode $variable The variable to check. * @return bool True if allowed, else false. */ private function isUnusedForeachVariableAllowed(ASTNode $variable) { $isForeachVariable = $this->isChildOf($variable, 'ForeachStatement'); if (!$isForeachVariable) { return false; } return $this->getBooleanProperty('allow-unused-foreach-variables'); } /** * Checks if the given node is a direct or indirect child of a node with * the given type. * * @param \PHPMD\AbstractNode $node * @param string $type * @return boolean */ private function isChildOf(AbstractNode $node, $type) { $parent = $node->getParent(); return $parent->isInstanceOf($type); } /** * Gets array of exceptions from property * * @return array */ private function getExceptionsList() { try { $exceptions = $this->getStringProperty('exceptions'); } catch (\OutOfBoundsException $e) { $exceptions = ''; } return explode(',', $exceptions); } } phpmd-2.8.1/src/main/php/PHPMD/Rule/UnusedPrivateField.php000066400000000000000000000136241360164303200231720ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Node\ASTNode; use PHPMD\Node\ClassNode; /** * This rule collects all private fields in a class that aren't used in any * method of the analyzed class. */ class UnusedPrivateField extends AbstractRule implements ClassAware { /** * Collected private fields/variable declarators in the currently processed * class. * * @var \PHPMD\Node\ASTNode[] */ private $fields = array(); /** * This method checks that all private class properties are at least accessed * by one method. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { /** @var ClassNode $field */ foreach ($this->collectUnusedPrivateFields($node) as $field) { $this->addViolation($field, array($field->getImage())); } } /** * This method collects all private fields that aren't used by any class * method. * * @param \PHPMD\Node\ClassNode $class * @return \PHPMD\AbstractNode[] */ private function collectUnusedPrivateFields(ClassNode $class) { $this->fields = array(); $this->collectPrivateFields($class); $this->removeUsedFields($class); return $this->fields; } /** * This method collects all private fields in the given class and stores * them in the $_fields property. * * @param \PHPMD\Node\ClassNode $class * @return void */ private function collectPrivateFields(ClassNode $class) { foreach ($class->findChildrenOfType('FieldDeclaration') as $declaration) { /** @var ASTNode $declaration */ if ($declaration->isPrivate()) { $this->collectPrivateField($declaration); } } } /** * This method extracts all variable declarators from the given field * declaration and stores them in the $_fields property. * * @param \PHPMD\Node\ASTNode $declaration * @return void */ private function collectPrivateField(ASTNode $declaration) { $fields = $declaration->findChildrenOfType('VariableDeclarator'); foreach ($fields as $field) { $this->fields[$field->getImage()] = $field; } } /** * This method extracts all property postfix nodes from the given class and * removes all fields from the $_fields property that are accessed by * one of the postfix nodes. * * @param \PHPMD\Node\ClassNode $class * @return void */ private function removeUsedFields(ClassNode $class) { foreach ($class->findChildrenOfType('PropertyPostfix') as $postfix) { /** @var $postfix ASTNode */ if ($this->isInScopeOfClass($class, $postfix)) { $this->removeUsedField($postfix); } } } /** * This method removes the field from the $_fields property that is * accessed through the given property postfix node. * * @param \PHPMD\Node\ASTNode $postfix * @return void */ private function removeUsedField(ASTNode $postfix) { $image = '$'; $child = $postfix->getFirstChildOfType('Identifier'); if ($postfix->getParent()->isStatic()) { $image = ''; $child = $postfix->getFirstChildOfType('Variable'); } if ($this->isValidPropertyNode($child)) { unset($this->fields[$image . $child->getImage()]); } } /** * Checks if the given node is a valid property node. * * @param \PHPMD\Node\ASTNode $node * @return boolean * @since 0.2.6 */ protected function isValidPropertyNode(ASTNode $node = null) { if ($node === null) { return false; } $parent = $node->getParent(); while (!$parent->isInstanceOf('PropertyPostfix')) { if ($parent->isInstanceOf('CompoundVariable')) { return false; } $parent = $parent->getParent(); if (is_null($parent)) { return false; } } return true; } /** * This method checks that the given property postfix is accessed on an * instance or static reference to the given class. * * @param \PHPMD\Node\ClassNode $class * @param \PHPMD\Node\ASTNode $postfix * @return boolean */ protected function isInScopeOfClass(ClassNode $class, ASTNode $postfix) { $owner = $this->getOwner($postfix); return ( $owner->isInstanceOf('SelfReference') || $owner->isInstanceOf('StaticReference') || strcasecmp($owner->getImage(), '$this') === 0 || strcasecmp($owner->getImage(), $class->getImage()) === 0 ); } /** * Looks for owner of the given variable. * * @param \PHPMD\Node\ASTNode $postfix * @return \PHPMD\Node\ASTNode */ protected function getOwner(ASTNode $postfix) { $owner = $postfix->getParent()->getChild(0); if ($owner->isInstanceOf('PropertyPostfix')) { $owner = $owner->getParent()->getParent()->getChild(0); } if ($owner->getParent()->isInstanceOf('ArrayIndexExpression')) { $owner = $owner->getParent()->getParent()->getChild(0); } return $owner; } } phpmd-2.8.1/src/main/php/PHPMD/Rule/UnusedPrivateMethod.php000066400000000000000000000102351360164303200233620ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Node\ASTNode; use PHPMD\Node\ClassNode; use PHPMD\Node\MethodNode; /** * This rule collects all private methods in a class that aren't used in any * method of the analyzed class. */ class UnusedPrivateMethod extends AbstractRule implements ClassAware { /** * This method checks that all private class methods are at least accessed * by one method. * * @param \PHPMD\AbstractNode $class * @return void */ public function apply(AbstractNode $class) { /** @var ClassNode $node */ foreach ($this->collectUnusedPrivateMethods($class) as $node) { $this->addViolation($node, array($node->getImage())); } } /** * This method collects all methods in the given class that are declared * as private and are not used in the same class' context. * * @param \PHPMD\Node\ClassNode $class * @return \PHPMD\AbstractNode[] */ private function collectUnusedPrivateMethods(ClassNode $class) { $methods = $this->collectPrivateMethods($class); return $this->removeUsedMethods($class, $methods); } /** * Collects all private methods declared in the given class node. * * @param \PHPMD\Node\ClassNode $class * @return \PHPMD\AbstractNode[] */ private function collectPrivateMethods(ClassNode $class) { $methods = array(); foreach ($class->getMethods() as $method) { if ($this->acceptMethod($class, $method)) { $methods[strtolower($method->getImage())] = $method; } } return $methods; } /** * Returns true when the given method should be used for this rule's * analysis. * * @param \PHPMD\Node\ClassNode $class * @param \PHPMD\Node\MethodNode $method * @return boolean */ private function acceptMethod(ClassNode $class, MethodNode $method) { return ( $method->isPrivate() && false === $method->hasSuppressWarningsAnnotationFor($this) && strcasecmp($method->getImage(), $class->getImage()) !== 0 && strcasecmp($method->getImage(), '__construct') !== 0 && strcasecmp($method->getImage(), '__destruct') !== 0 && strcasecmp($method->getImage(), '__clone') !== 0 ); } /** * This method removes all used methods from the given methods array. * * @param \PHPMD\Node\ClassNode $class * @param \PHPMD\Node\MethodNode[] $methods * @return \PHPMD\AbstractNode[] */ private function removeUsedMethods(ClassNode $class, array $methods) { foreach ($class->findChildrenOfType('MethodPostfix') as $postfix) { /** @var $postfix ASTNode */ if ($this->isClassScope($class, $postfix)) { unset($methods[strtolower($postfix->getImage())]); } } return $methods; } /** * This method checks that the given method postfix is accessed on an * instance or static reference to the given class. * * @param \PHPMD\Node\ClassNode $class * @param \PHPMD\Node\ASTNode $postfix * @return boolean */ private function isClassScope(ClassNode $class, ASTNode $postfix) { $owner = $postfix->getParent()->getChild(0); return ( $owner->isInstanceOf('MethodPostfix') || $owner->isInstanceOf('SelfReference') || $owner->isInstanceOf('StaticReference') || strcasecmp($owner->getImage(), '$this') === 0 || strcasecmp($owner->getImage(), $class->getImage()) === 0 ); } } phpmd-2.8.1/src/main/php/PHPMD/RuleClassFileNotFoundException.php000066400000000000000000000017411360164303200245470ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD; /** * This type of exception is thrown when the class file for a configured rule * does not exist within php's include path. */ class RuleClassFileNotFoundException extends \RuntimeException { /** * Constructs a new class file not found exception. * * @param string $className The rule class name. */ public function __construct($className) { parent::__construct('Cannot load source file for class: ' . $className); } } phpmd-2.8.1/src/main/php/PHPMD/RuleClassNotFoundException.php000066400000000000000000000016331360164303200237470ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD; /** * When a configured rule class does not exist. */ class RuleClassNotFoundException extends \RuntimeException { /** * Constructs a new class not found exception. * * @param string $className The configured but not found ruke class name. */ public function __construct($className) { parent::__construct('Cannot find rule class: ' . $className); } } phpmd-2.8.1/src/main/php/PHPMD/RuleSet.php000066400000000000000000000137611360164303200201060ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD; /** * This class is a collection of concrete source analysis rules. */ class RuleSet implements \IteratorAggregate { /** * Should this rule set force the strict mode. * * @var boolean * @since 1.2.0 */ private $strict = false; /** * The name of the file where this set is specified. * * @var string */ private $fileName = ''; /** * The name of this rule-set. * * @var string */ private $name = ''; /** * An optional description for this rule-set. * * @var string */ private $description = ''; /** * The violation report used by the rule-set. * * @var \PHPMD\Report */ private $report; /** * Mapping between marker interfaces and concrete context code node classes. * * @var array(string=>string) */ private $applyTo = array( 'PHPMD\\Rule\\ClassAware' => 'PHPMD\\Node\\ClassNode', 'PHPMD\\Rule\\FunctionAware' => 'PHPMD\\Node\\FunctionNode', 'PHPMD\\Rule\\InterfaceAware' => 'PHPMD\\Node\\InterfaceNode', 'PHPMD\\Rule\\MethodAware' => 'PHPMD\\Node\\MethodNode', ); /** * Mapping of rules that apply to a concrete code node type. * * @var array(string=>array) */ private $rules = array( 'PHPMD\\Node\\ClassNode' => array(), 'PHPMD\\Node\\FunctionNode' => array(), 'PHPMD\\Node\\InterfaceNode' => array(), 'PHPMD\\Node\\MethodNode' => array(), ); /** * Returns the file name where the definition of this rule-set comes from. * * @return string */ public function getFileName() { return $this->fileName; } /** * Sets the file name where the definition of this rule-set comes from. * * @param string $fileName The file name. * @return void */ public function setFileName($fileName) { $this->fileName = $fileName; } /** * Returns the name of this rule-set. * * @return string */ public function getName() { return $this->name; } /** * Sets the name of this rule-set. * * @param string $name The name of this rule-set. * @return void */ public function setName($name) { $this->name = $name; } /** * Returns the description text for this rule-set instance. * * @return string */ public function getDescription() { return $this->description; } /** * Sets the description text for this rule-set instance. * * @param string $description The description text. * @return void */ public function setDescription($description) { $this->description = $description; } /** * Activates the strict mode for this rule set instance. * * @return void * @since 1.2.0 */ public function setStrict() { $this->strict = true; } /** * Returns the violation report used by the rule-set. * * @return \PHPMD\Report */ public function getReport() { return $this->report; } /** * Sets the violation report used by the rule-set. * * @param \PHPMD\Report $report * @return void */ public function setReport(Report $report) { $this->report = $report; } /** * This method returns a rule by its name or null if it doesn't exist. * * @param string $name * @return \PHPMD\Rule */ public function getRuleByName($name) { foreach ($this->getRules() as $rule) { if ($rule->getName() === $name) { return $rule; } } return null; } /** * This method returns an iterator will all rules that belong to this * rule-set. * * @return \Iterator */ public function getRules() { $result = array(); foreach ($this->rules as $rules) { foreach ($rules as $rule) { if (in_array($rule, $result, true) === false) { $result[] = $rule; } } } return new \ArrayIterator($result); } /** * Adds a new rule to this rule-set. * * @param \PHPMD\Rule $rule * @return void */ public function addRule(Rule $rule) { foreach ($this->applyTo as $applyTo => $type) { if ($rule instanceof $applyTo) { $this->rules[$type][] = $rule; } } } /** * Applies all registered rules that match against the concrete node type. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { // Current node type $className = get_class($node); // Check for valid node type if (!isset($this->rules[$className])) { return; } // Apply all rules to this node foreach ($this->rules[$className] as $rule) { /** @var $rule Rule */ if ($node->hasSuppressWarningsAnnotationFor($rule) && !$this->strict) { continue; } $rule->setReport($this->report); $rule->apply($node); } } /** * Returns an iterator with all rules that are part of this rule-set. * * @return \Iterator */ public function getIterator() { return $this->getRules(); } } phpmd-2.8.1/src/main/php/PHPMD/RuleSetFactory.php000066400000000000000000000436351360164303200214410ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD; /** * This factory class is used to create the {@link \PHPMD\RuleSet} instance * that PHPMD will use to analyze the source code. */ class RuleSetFactory { /** * Is the strict mode active? * * @var boolean * @since 1.2.0 */ private $strict = false; /** * The data directory set by PEAR or a dynamic property set within the class * constructor. * * @var string */ private $location = '@data_dir@'; /** * The minimum priority for rules to load. * * @var integer */ private $minimumPriority = Rule::LOWEST_PRIORITY; /** * The maximum priority for rules to load. * * @var integer */ private $maximumPriority = Rule::HIGHEST_PRIORITY; /** * Constructs a new default rule-set factory instance. */ public function __construct() { // PEAR installer workaround if (strpos($this->location, '@data_dir') === 0) { $this->location = __DIR__ . '/../../resources'; return; } $this->location .= '/PHPMD/resources'; } /** * Activates the strict mode for all rule sets. * * @return void * @since 1.2.0 */ public function setStrict() { $this->strict = true; } /** * Sets the minimum priority that a rule must have. * * @param integer $minimumPriority The minimum priority value. * @return void */ public function setMinimumPriority($minimumPriority) { $this->minimumPriority = $minimumPriority; } /** * Sets the maximum priority that a rule must have. * * @param integer $maximumPriority The maximum priority value. * @return void */ public function setMaximumPriority($maximumPriority) { $this->maximumPriority = $maximumPriority; } /** * Creates an array of rule-set instances for the given argument. * * @param string $ruleSetFileNames Comma-separated string of rule-set filenames or identifier. * @return \PHPMD\RuleSet[] */ public function createRuleSets($ruleSetFileNames) { $ruleSets = array(); $ruleSetFileName = strtok($ruleSetFileNames, ','); while ($ruleSetFileName !== false) { $ruleSets[] = $this->createSingleRuleSet($ruleSetFileName); $ruleSetFileName = strtok(','); } return $ruleSets; } /** * Creates a single rule-set instance for the given filename or identifier. * * @param string $ruleSetOrFileName The rule-set filename or identifier. * @return \PHPMD\RuleSet */ public function createSingleRuleSet($ruleSetOrFileName) { $fileName = $this->createRuleSetFileName($ruleSetOrFileName); return $this->parseRuleSetNode($fileName); } /** * Lists available rule-set identifiers. * * @return string[] */ public function listAvailableRuleSets() { return array_merge( self::listRuleSetsInDirectory($this->location . '/rulesets/'), self::listRuleSetsInDirectory(getcwd() . '/rulesets/') ); } /** * This method creates the filename for a rule-set identifier or it returns * the input when it is already a filename. * * @param string $ruleSetOrFileName The rule-set filename or identifier. * @return string Path to rule set file name * @throws RuleSetNotFoundException Thrown if no readable file found */ private function createRuleSetFileName($ruleSetOrFileName) { foreach ($this->filePaths($ruleSetOrFileName) as $filePath) { if ($this->isReadableFile($filePath)) { return $filePath; } } throw new RuleSetNotFoundException($ruleSetOrFileName); } /** * Lists available rule-set identifiers in given directory. * * @param string $directory The directory to scan for rule-sets. * @return string[] */ private static function listRuleSetsInDirectory($directory) { $ruleSets = array(); if (is_dir($directory)) { foreach (scandir($directory) as $file) { $matches = array(); if (is_file($directory . $file) && preg_match('/^(.*)\.xml$/', $file, $matches)) { $ruleSets[] = $matches[1]; } } } return $ruleSets; } /** * This method parses the rule-set definition in the given file. * * @param string $fileName * @return \PHPMD\RuleSet */ private function parseRuleSetNode($fileName) { // Hide error messages $libxml = libxml_use_internal_errors(true); $xml = simplexml_load_string(file_get_contents($fileName)); if ($xml === false) { // Reset error handling to previous setting libxml_use_internal_errors($libxml); throw new \RuntimeException(trim(libxml_get_last_error()->message)); } $ruleSet = new RuleSet(); $ruleSet->setFileName($fileName); $ruleSet->setName((string) $xml['name']); if ($this->strict) { $ruleSet->setStrict(); } foreach ($xml->children() as $node) { /** @var $node \SimpleXMLElement */ if ($node->getName() === 'php-includepath') { $includePath = (string) $node; if (is_dir(dirname($fileName) . DIRECTORY_SEPARATOR . $includePath)) { $includePath = dirname($fileName) . DIRECTORY_SEPARATOR . $includePath; $includePath = realpath($includePath); } $includePath = get_include_path() . PATH_SEPARATOR . $includePath; set_include_path($includePath); } } foreach ($xml->children() as $node) { if ($node->getName() === 'description') { $ruleSet->setDescription((string) $node); } elseif ($node->getName() === 'rule') { $this->parseRuleNode($ruleSet, $node); } } return $ruleSet; } /** * This method parses a single rule xml node. Bases on the structure of the * xml node this method delegates the parsing process to another method in * this class. * * @param \PHPMD\RuleSet $ruleSet * @param \SimpleXMLElement $node * @return void */ private function parseRuleNode(RuleSet $ruleSet, \SimpleXMLElement $node) { if (substr($node['ref'], -3, 3) === 'xml') { $this->parseRuleSetReferenceNode($ruleSet, $node); return; } if ('' === (string) $node['ref']) { $this->parseSingleRuleNode($ruleSet, $node); return; } $this->parseRuleReferenceNode($ruleSet, $node); } /** * This method parses a complete rule set that was includes a reference in * the currently parsed ruleset. * * @param \PHPMD\RuleSet $ruleSet * @param \SimpleXMLElement $ruleSetNode * @return void */ private function parseRuleSetReferenceNode(RuleSet $ruleSet, \SimpleXMLElement $ruleSetNode) { $rules = $this->parseRuleSetReference($ruleSetNode); foreach ($rules as $rule) { if ($this->isIncluded($rule, $ruleSetNode)) { $ruleSet->addRule($rule); } } } /** * Parses a rule-set xml file referenced by the given rule-set xml element. * * @param \SimpleXMLElement $ruleSetNode * @return \PHPMD\RuleSet * @since 0.2.3 */ private function parseRuleSetReference(\SimpleXMLElement $ruleSetNode) { $ruleSetFactory = new RuleSetFactory(); $ruleSetFactory->setMinimumPriority($this->minimumPriority); $ruleSetFactory->setMaximumPriority($this->maximumPriority); return $ruleSetFactory->createSingleRuleSet((string) $ruleSetNode['ref']); } /** * Checks if the given rule is included/not excluded by the given rule-set * reference node. * * @param \PHPMD\Rule $rule * @param \SimpleXMLElement $ruleSetNode * @return boolean * @since 0.2.3 */ private function isIncluded(Rule $rule, \SimpleXMLElement $ruleSetNode) { foreach ($ruleSetNode->exclude as $exclude) { if ($rule->getName() === (string) $exclude['name']) { return false; } } return true; } /** * This method will create a single rule instance and add it to the given * {@link \PHPMD\RuleSet} object. * * @param \PHPMD\RuleSet $ruleSet * @param \SimpleXMLElement $ruleNode * @return void * @throws \PHPMD\RuleClassFileNotFoundException * @throws \PHPMD\RuleClassNotFoundException */ private function parseSingleRuleNode(RuleSet $ruleSet, \SimpleXMLElement $ruleNode) { $fileName = ""; $ruleSetFolderPath = dirname($ruleSet->getFileName()); if (isset($ruleNode['file'])) { if (is_readable((string) $ruleNode['file'])) { $fileName = (string) $ruleNode['file']; } elseif (is_readable($ruleSetFolderPath . DIRECTORY_SEPARATOR . (string) $ruleNode['file'])) { $fileName = $ruleSetFolderPath . DIRECTORY_SEPARATOR . (string) $ruleNode['file']; } } $className = (string) $ruleNode['class']; if (!is_readable($fileName)) { $fileName = strtr($className, '\\', '/') . '.php'; } if (!is_readable($fileName)) { $fileName = str_replace(array('\\', '_'), '/', $className) . '.php'; } if (class_exists($className) === false) { $handle = @fopen($fileName, 'r', true); if ($handle === false) { throw new RuleClassFileNotFoundException($className); } fclose($handle); include_once $fileName; if (class_exists($className) === false) { throw new RuleClassNotFoundException($className); } } /* @var $rule \PHPMD\Rule */ $rule = new $className(); $rule->setName((string) $ruleNode['name']); $rule->setMessage((string) $ruleNode['message']); $rule->setExternalInfoUrl((string) $ruleNode['externalInfoUrl']); $rule->setRuleSetName($ruleSet->getName()); if (trim($ruleNode['since']) !== '') { $rule->setSince((string) $ruleNode['since']); } foreach ($ruleNode->children() as $node) { /** @var $node \SimpleXMLElement */ if ($node->getName() === 'description') { $rule->setDescription((string) $node); } elseif ($node->getName() === 'example') { $rule->addExample((string) $node); } elseif ($node->getName() === 'priority') { $rule->setPriority((integer) $node); } elseif ($node->getName() === 'properties') { $this->parsePropertiesNode($rule, $node); } } if ($rule->getPriority() <= $this->minimumPriority && $rule->getPriority() >= $this->maximumPriority) { $ruleSet->addRule($rule); } } /** * This method parses a single rule that was included from a different * rule-set. * * @param \PHPMD\RuleSet $ruleSet * @param \SimpleXMLElement $ruleNode * @return void */ private function parseRuleReferenceNode(RuleSet $ruleSet, \SimpleXMLElement $ruleNode) { $ref = (string) $ruleNode['ref']; $fileName = substr($ref, 0, strpos($ref, '.xml/') + 4); $fileName = $this->createRuleSetFileName($fileName); $ruleName = substr($ref, strpos($ref, '.xml/') + 5); $ruleSetFactory = new RuleSetFactory(); $ruleSetRef = $ruleSetFactory->createSingleRuleSet($fileName); $rule = $ruleSetRef->getRuleByName($ruleName); if (trim($ruleNode['name']) !== '') { $rule->setName((string) $ruleNode['name']); } if (trim($ruleNode['message']) !== '') { $rule->setMessage((string) $ruleNode['message']); } if (trim($ruleNode['externalInfoUrl']) !== '') { $rule->setExternalInfoUrl((string) $ruleNode['externalInfoUrl']); } foreach ($ruleNode->children() as $node) { /** @var $node \SimpleXMLElement */ if ($node->getName() === 'description') { $rule->setDescription((string) $node); } elseif ($node->getName() === 'example') { $rule->addExample((string) $node); } elseif ($node->getName() === 'priority') { $rule->setPriority((integer) $node); } elseif ($node->getName() === 'properties') { $this->parsePropertiesNode($rule, $node); } } if ($rule->getPriority() <= $this->minimumPriority && $rule->getPriority() >= $this->maximumPriority) { $ruleSet->addRule($rule); } } /** * This method parses a xml properties structure and adds all found properties * to the given $rule object. * * * ... * * * * ... * * ... * * * @param \PHPMD\Rule $rule * @param \SimpleXMLElement $propertiesNode * @return void */ private function parsePropertiesNode(Rule $rule, \SimpleXMLElement $propertiesNode) { foreach ($propertiesNode->children() as $node) { /** @var $node \SimpleXMLElement */ if ($node->getName() === 'property') { $this->addProperty($rule, $node); } } } /** * Adds an additional property to the given $rule instance. * * @param \PHPMD\Rule $rule * @param \SimpleXMLElement $node * @return void */ private function addProperty(Rule $rule, \SimpleXMLElement $node) { $name = trim($node['name']); $value = trim($this->getPropertyValue($node)); if ($name !== '' && $value !== '') { $rule->addProperty($name, $value); } } /** * Returns the value of a property node. This value can be expressed in * two different notations. First version is an attribute named value * and the second valid notation is a child element named value that * contains the value as character data. * * @param \SimpleXMLElement $propertyNode * @return string * @since 0.2.5 */ private function getPropertyValue(\SimpleXMLElement $propertyNode) { if (isset($propertyNode->value)) { return (string) $propertyNode->value; } return (string) $propertyNode['value']; } /** * Returns an array of path exclude patterns in format described at * * http://pmd.sourceforge.net/pmd-5.0.4/howtomakearuleset.html#Excluding_files_from_a_ruleset * * @param string $fileName The filename of a rule-set definition. * @return array|null * @throws \RuntimeException Thrown if file is not proper xml * @throws RuleSetNotFoundException Thrown if no readable file found */ public function getIgnorePattern($fileName) { $excludes = array(); foreach (array_map('trim', explode(',', $fileName)) as $ruleSetFileName) { $ruleSetFileName = $this->createRuleSetFileName($ruleSetFileName); // Hide error messages $libxml = libxml_use_internal_errors(true); $xml = simplexml_load_string(file_get_contents($ruleSetFileName)); if ($xml === false) { // Reset error handling to previous setting libxml_use_internal_errors($libxml); throw new \RuntimeException(trim(libxml_get_last_error()->message)); } foreach ($xml->children() as $node) { /** @var $node \SimpleXMLElement */ if ($node->getName() === 'exclude-pattern') { $excludes[] = '' . $node; } } return $excludes; } return null; } /** * Checks if given file path exists, is file (or symlink to file) * and is readable by current user * * @param string $filePath File path to check against * @return bool True if file exists and is readable, false otherwise */ private function isReadableFile($filePath) { if (is_readable($filePath) && is_file($filePath)) { return true; } return false; } /** * Returns list of possible file paths to search against code rules * * @param string $fileName Rule set file name * @return array Array of possible file locations */ private function filePaths($fileName) { $filePathParts = array( array($fileName), array($this->location, $fileName), array($this->location, 'rulesets', $fileName . '.xml'), array(getcwd(), 'rulesets', $fileName . '.xml'), ); foreach (explode(PATH_SEPARATOR, get_include_path()) as $includePath) { $filePathParts[] = array($includePath, $fileName); $filePathParts[] = array($includePath, $fileName . '.xml'); } return array_map('implode', array_fill(0, count($filePathParts), DIRECTORY_SEPARATOR), $filePathParts); } } phpmd-2.8.1/src/main/php/PHPMD/RuleSetNotFoundException.php000066400000000000000000000017311360164303200234340ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD; /** * This type of exception is thrown when a not existing rule-set was specified. */ class RuleSetNotFoundException extends \RuntimeException { /** * Constructs a new exception for the given rule-set identifier or file name. * * @param string $ruleSet The rule-set identifier or file name. */ public function __construct($ruleSet) { parent::__construct('Cannot find specified rule-set "' . $ruleSet . '".'); } } phpmd-2.8.1/src/main/php/PHPMD/RuleViolation.php000066400000000000000000000111171360164303200213100ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD; use PHPMD\Node\AbstractTypeNode; use PHPMD\Node\FunctionNode; use PHPMD\Node\MethodNode; /** * This class is used as container for a single rule violation related to a source * node. */ class RuleViolation { /** * The rule that causes this violation. * * @var \PHPMD\Rule */ private $rule; /** * The context code node for this rule violation. * * @var \PHPMD\AbstractNode */ private $node; /** * The description/message text that describes the violation. * * @var string */ private $description; /** * The raw metric value which caused this rule violation. * * @var mixed */ private $metric; /** * Name of the owning/context class or interface of this violation. * * @var string */ private $className = null; /** * The name of a method or null when this violation has no method * context. * * @var string */ private $methodName = null; /** * The name of a function or null when this violation has no function * context. * * @var string */ private $functionName = null; /** * Constructs a new rule violation instance. * * @param \PHPMD\Rule $rule * @param \PHPMD\AbstractNode $node * @param string $violationMessage * @param mixed $metric */ public function __construct(Rule $rule, AbstractNode $node, $violationMessage, $metric = null) { $this->rule = $rule; $this->node = $node; $this->metric = $metric; $this->description = $violationMessage; if ($node instanceof AbstractTypeNode) { $this->className = $node->getName(); } elseif ($node instanceof MethodNode) { $this->className = $node->getParentName(); $this->methodName = $node->getName(); } elseif ($node instanceof FunctionNode) { $this->functionName = $node->getName(); } } /** * Returns the rule that causes this violation. * * @return \PHPMD\Rule */ public function getRule() { return $this->rule; } /** * Returns the description/message text that describes the violation. * * @return string */ public function getDescription() { return $this->description; } /** * Returns the raw metric value which caused this rule violation. * * @return mixed|null */ public function getMetric() { return $this->metric; } /** * Returns the file name where this rule violation was detected. * * @return string */ public function getFileName() { return $this->node->getFileName(); } /** * Returns the first line of the node that causes this rule violation. * * @return integer */ public function getBeginLine() { return $this->node->getBeginLine(); } /** * Returns the last line of the node that causes this rule violation. * * @return integer */ public function getEndLine() { return $this->node->getEndLine(); } /** * Returns the name of the package that contains this violation. * * @return string */ public function getNamespaceName() { return $this->node->getNamespaceName(); } /** * Returns the name of the parent class or interface or null when there * is no parent class. * * @return string */ public function getClassName() { return $this->className; } /** * Returns the name of a method or null when this violation has no * method context. * * @return string */ public function getMethodName() { return $this->methodName; } /** * Returns the name of a function or null when this violation has no * function context. * * @return string */ public function getFunctionName() { return $this->functionName; } } phpmd-2.8.1/src/main/php/PHPMD/TextUI/000077500000000000000000000000001360164303200171645ustar00rootroot00000000000000phpmd-2.8.1/src/main/php/PHPMD/TextUI/Command.php000066400000000000000000000110311360164303200212470ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\TextUI; use PHPMD\PHPMD; use PHPMD\RuleSetFactory; use PHPMD\Writer\StreamWriter; /** * This class provides a command line interface for PHPMD */ class Command { /** * Exit codes used by the phpmd command line tool. */ const EXIT_SUCCESS = 0, EXIT_EXCEPTION = 1, EXIT_VIOLATION = 2; /** * This method creates a PHPMD instance and configures this object based * on the user's input, then it starts the source analysis. * * The return value of this method can be used as an exit code. A value * equal to EXIT_SUCCESS means that no violations or errors were * found in the analyzed code. Otherwise this method will return a value * equal to EXIT_VIOLATION. * * The use of flag --ignore-violations-on-exit will result to a * EXIT_SUCCESS even if any violation is found. * * @param \PHPMD\TextUI\CommandLineOptions $opts * @param \PHPMD\RuleSetFactory $ruleSetFactory * @return integer */ public function run(CommandLineOptions $opts, RuleSetFactory $ruleSetFactory) { if ($opts->hasVersion()) { fwrite(STDOUT, sprintf('PHPMD %s', $this->getVersion()) . PHP_EOL); return self::EXIT_SUCCESS; } // Create a report stream $stream = $opts->getReportFile() ? $opts->getReportFile() : STDOUT; // Create renderer and configure output $renderer = $opts->createRenderer(); $renderer->setWriter(new StreamWriter($stream)); $renderers = array($renderer); foreach ($opts->getReportFiles() as $reportFormat => $reportFile) { $reportRenderer = $opts->createRenderer($reportFormat); $reportRenderer->setWriter(new StreamWriter($reportFile)); $renderers[] = $reportRenderer; } // Configure a rule set factory $ruleSetFactory->setMinimumPriority($opts->getMinimumPriority()); $ruleSetFactory->setMaximumPriority($opts->getMaximumPriority()); if ($opts->hasStrict()) { $ruleSetFactory->setStrict(); } $phpmd = new PHPMD(); $phpmd->setOptions( array_filter( array( 'coverage' => $opts->getCoverageReport() ) ) ); $extensions = $opts->getExtensions(); if ($extensions !== null) { $phpmd->setFileExtensions(explode(',', $extensions)); } $ignore = $opts->getIgnore(); if ($ignore !== null) { $phpmd->setIgnorePattern(explode(',', $ignore)); } $phpmd->processFiles( $opts->getInputPath(), $opts->getRuleSets(), $renderers, $ruleSetFactory ); if ($phpmd->hasViolations() && !$opts->ignoreViolationsOnExit()) { return self::EXIT_VIOLATION; } return self::EXIT_SUCCESS; } /** * Returns the current version number. * * @return string */ private function getVersion() { $build = __DIR__ . '/../../../../../build.properties'; $version = '@package_version@'; if (file_exists($build)) { $data = @parse_ini_file($build); $version = $data['project.version']; } return $version; } /** * The main method that can be used by a calling shell script, the return * value can be used as exit code. * * @param array $args The raw command line arguments array. * @return integer */ public static function main(array $args) { try { $ruleSetFactory = new RuleSetFactory(); $options = new CommandLineOptions($args, $ruleSetFactory->listAvailableRuleSets()); $command = new Command(); $exitCode = $command->run($options, $ruleSetFactory); } catch (\Exception $e) { fwrite(STDERR, $e->getMessage() . PHP_EOL); $exitCode = self::EXIT_EXCEPTION; } return $exitCode; } } phpmd-2.8.1/src/main/php/PHPMD/TextUI/CommandLineOptions.php000066400000000000000000000363711360164303200234510ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\TextUI; use PHPMD\Renderer\AnsiRenderer; use PHPMD\Renderer\HTMLRenderer; use PHPMD\Renderer\JSONRenderer; use PHPMD\Renderer\TextRenderer; use PHPMD\Renderer\XMLRenderer; use PHPMD\Rule; /** * This is a helper class that collects the specified cli arguments and puts them * into accessible properties. * * @SuppressWarnings(PHPMD.LongVariable) */ class CommandLineOptions { /** * Error code for invalid input */ const INPUT_ERROR = 23; /** * The minimum rule priority. * * @var integer */ protected $minimumPriority = Rule::LOWEST_PRIORITY; /** * The maximum rule priority. * * @var integer */ protected $maximumPriority = Rule::HIGHEST_PRIORITY; /** * A php source code filename or directory. * * @var string */ protected $inputPath; /** * The specified report format. * * @var string */ protected $reportFormat; /** * An optional filename for the generated report. * * @var string */ protected $reportFile; /** * Additional report files. * * @var array */ protected $reportFiles = array(); /** * A ruleset filename or a comma-separated string of ruleset filenames. * * @var string */ protected $ruleSets; /** * File name of a PHPUnit code coverage report. * * @var string */ protected $coverageReport; /** * A string of comma-separated extensions for valid php source code filenames. * * @var string */ protected $extensions; /** * A string of comma-separated pattern that is used to exclude directories. * * @var string */ protected $ignore; /** * Should the shell show the current phpmd version? * * @var boolean */ protected $version = false; /** * Should PHPMD run in strict mode? * * @var boolean * @since 1.2.0 */ protected $strict = false; /** * Should PHPMD exit without error code even if violation is found? * * @var boolean */ protected $ignoreViolationsOnExit = false; /** * List of available rule-sets. * * @var array(string) */ protected $availableRuleSets = array(); /** * Constructs a new command line options instance. * * @param array $args * @param array $availableRuleSets * @throws \InvalidArgumentException */ public function __construct(array $args, array $availableRuleSets = array()) { // Remove current file name array_shift($args); $this->availableRuleSets = $availableRuleSets; $arguments = array(); while (($arg = array_shift($args)) !== null) { switch ($arg) { case '--min-priority': case '--minimum-priority': case '--minimumpriority': $this->minimumPriority = (int)array_shift($args); break; case '--max-priority': case '--maximum-priority': case '--maximumpriority': $this->maximumPriority = (int)array_shift($args); break; case '--report-file': case '--reportfile': $this->reportFile = array_shift($args); break; case '--input-file': case '--inputfile': array_unshift($arguments, $this->readInputFile(array_shift($args))); break; case '--coverage': $this->coverageReport = array_shift($args); break; case '--extensions': $this->logDeprecated('extensions', 'suffixes'); /* Deprecated: We use the suffixes option now */ $this->extensions = array_shift($args); break; case '--suffixes': $this->extensions = array_shift($args); break; case '--ignore': $this->logDeprecated('ignore', 'exclude'); /* Deprecated: We use the exclude option now */ $this->ignore = array_shift($args); break; case '--exclude': $this->ignore = array_shift($args); break; case '--version': $this->version = true; return; case '--strict': $this->strict = true; break; case '--not-strict': $this->strict = false; break; case '--ignore-violations-on-exit': $this->ignoreViolationsOnExit = true; break; case '--reportfile-html': case '--reportfile-text': case '--reportfile-xml': case '--reportfile-json': preg_match('(^\-\-reportfile\-(xml|html|text|json)$)', $arg, $match); $this->reportFiles[$match[1]] = array_shift($args); break; default: $arguments[] = $arg; break; } } if (count($arguments) < 3) { throw new \InvalidArgumentException($this->usage(), self::INPUT_ERROR); } $this->inputPath = (string)array_shift($arguments); $this->reportFormat = (string)array_shift($arguments); $this->ruleSets = (string)array_shift($arguments); } /** * Returns a php source code filename or directory. * * @return string */ public function getInputPath() { return $this->inputPath; } /** * Returns the specified report format. * * @return string */ public function getReportFormat() { return $this->reportFormat; } /** * Returns the output filename for a generated report or null when * the report should be displayed in STDOUT. * * @return string */ public function getReportFile() { return $this->reportFile; } /** * Returns a hash with report files specified for different renderers. The * key represents the report format and the value the report file location. * * @return array */ public function getReportFiles() { return $this->reportFiles; } /** * Returns a ruleset filename or a comma-separated string of ruleset * * @return string */ public function getRuleSets() { return $this->ruleSets; } /** * Returns the minimum rule priority. * * @return integer */ public function getMinimumPriority() { return $this->minimumPriority; } /** * Returns the maximum rule priority. * * @return integer */ public function getMaximumPriority() { return $this->maximumPriority; } /** * Returns the file name of a supplied code coverage report or NULL * if the user has not supplied the --coverage option. * * @return string */ public function getCoverageReport() { return $this->coverageReport; } /** * Returns a string of comma-separated extensions for valid php source code * filenames or null when this argument was not set. * * @return string */ public function getExtensions() { return $this->extensions; } /** * Returns string of comma-separated pattern that is used to exclude * directories or null when this argument was not set. * * @return string */ public function getIgnore() { return $this->ignore; } /** * Was the --version passed to PHPMD's command line interface? * * @return boolean */ public function hasVersion() { return $this->version; } /** * Was the --strict option passed to PHPMD's command line interface? * * @return boolean * @since 1.2.0 */ public function hasStrict() { return $this->strict; } /** * Was the --ignore-violations-on-exit passed to PHPMD's command line interface? * * @return boolean */ public function ignoreViolationsOnExit() { return $this->ignoreViolationsOnExit; } /** * Creates a report renderer instance based on the user's command line * argument. * * Valid renderers are: *
    *
  • xml
  • *
  • html
  • *
  • text
  • *
  • json
  • *
* * @param string $reportFormat * @return \PHPMD\AbstractRenderer * @throws \InvalidArgumentException When the specified renderer does not exist. */ public function createRenderer($reportFormat = null) { $reportFormat = $reportFormat ?: $this->reportFormat; switch ($reportFormat) { case 'xml': return $this->createXmlRenderer(); case 'html': return $this->createHtmlRenderer(); case 'text': return $this->createTextRenderer(); case 'json': return $this->createJsonRenderer(); case 'ansi': return $this->createAnsiRenderer(); default: return $this->createCustomRenderer(); } } /** * @return \PHPMD\Renderer\XMLRenderer */ protected function createXmlRenderer() { return new XMLRenderer(); } /** * @return \PHPMD\Renderer\TextRenderer */ protected function createTextRenderer() { return new TextRenderer(); } /** * @return \PHPMD\Renderer\AnsiRenderer */ protected function createAnsiRenderer() { return new AnsiRenderer(); } /** * @return \PHPMD\Renderer\HTMLRenderer */ protected function createHtmlRenderer() { return new HTMLRenderer(); } /** * @return \PHPMD\Renderer\JSONRenderer */ protected function createJsonRenderer() { return new JSONRenderer(); } /** * @return \PHPMD\AbstractRenderer * @throws \InvalidArgumentException */ protected function createCustomRenderer() { if ('' === $this->reportFormat) { throw new \InvalidArgumentException( 'Can\'t create report with empty format.', self::INPUT_ERROR ); } if (class_exists($this->reportFormat)) { return new $this->reportFormat(); } // Try to load a custom renderer $fileName = strtr($this->reportFormat, '_\\', '//') . '.php'; $fileHandle = @fopen($fileName, 'r', true); if (is_resource($fileHandle) === false) { throw new \InvalidArgumentException( sprintf( 'Can\'t find the custom report class: %s', $this->reportFormat ), self::INPUT_ERROR ); } @fclose($fileHandle); include_once $fileName; return new $this->reportFormat(); } /** * Returns usage information for the PHPMD command line interface. * * @return string */ public function usage() { $availableRenderers = $this->getListOfAvailableRenderers(); return 'Mandatory arguments:' . \PHP_EOL . '1) A php source code filename or directory. Can be a comma-' . 'separated string' . \PHP_EOL . '2) A report format' . \PHP_EOL . '3) A ruleset filename or a comma-separated string of ruleset' . 'filenames' . \PHP_EOL . \PHP_EOL . 'Example: phpmd /path/to/source format ruleset' . \PHP_EOL . \PHP_EOL . 'Available formats: ' . $availableRenderers . '.' . \PHP_EOL . 'Available rulesets: ' . implode(', ', $this->availableRuleSets) . '.' . \PHP_EOL . \PHP_EOL . 'Optional arguments that may be put after the mandatory arguments:' . \PHP_EOL . '--minimumpriority: rule priority threshold; rules with lower ' . 'priority than this will not be used' . \PHP_EOL . '--reportfile: send report output to a file; default to STDOUT' . \PHP_EOL . '--suffixes: comma-separated string of valid source code ' . 'filename extensions, e.g. php,phtml' . \PHP_EOL . '--exclude: comma-separated string of patterns that are used to ' . 'ignore directories' . \PHP_EOL . '--strict: also report those nodes with a @SuppressWarnings ' . 'annotation' . \PHP_EOL . '--ignore-violations-on-exit: will exit with a zero code, ' . 'even if any violations are found' . \PHP_EOL; } /** * Get a list of available renderers * * @return string The list of renderers found. */ protected function getListOfAvailableRenderers() { $renderersDirPathName=__DIR__.'/../Renderer'; $renderers = array(); foreach (scandir($renderersDirPathName) as $rendererFileName) { if (preg_match('/^(\w+)Renderer.php$/i', $rendererFileName, $rendererName)) { $renderers[] = strtolower($rendererName[1]); } } sort($renderers); if (count($renderers) > 1) { return implode(', ', $renderers); } return array_pop($renderers); } /** * Logs a deprecated option to the current user interface. * * @param string $deprecatedName * @param string $newName * @return void */ protected function logDeprecated($deprecatedName, $newName) { $message = sprintf( 'The --%s option is deprecated, please use --%s instead.', $deprecatedName, $newName ); fwrite(STDERR, $message . PHP_EOL . PHP_EOL); } /** * This method takes the given input file, reads the newline separated paths * from that file and creates a comma separated string of the file paths. If * the given $inputFile not exists, this method will throw an * exception. * * @param string $inputFile Specified input file name. * @return string * @throws \InvalidArgumentException If the specified input file does not exist. * @since 1.1.0 */ protected function readInputFile($inputFile) { if (file_exists($inputFile)) { return join(',', array_map('trim', file($inputFile))); } throw new \InvalidArgumentException("Input file '{$inputFile}' not exists."); } } phpmd-2.8.1/src/main/php/PHPMD/Writer/000077500000000000000000000000001360164303200172565ustar00rootroot00000000000000phpmd-2.8.1/src/main/php/PHPMD/Writer/StreamWriter.php000066400000000000000000000037111360164303200224210ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Writer; use PHPMD\AbstractWriter; /** * This writer uses PHP's stream api as its output target. */ class StreamWriter extends AbstractWriter { /** * The stream resource handle * * @var resource */ private $stream = null; /** * Constructs a new stream writer instance. * * @param resource|string $streamResourceOrUri */ public function __construct($streamResourceOrUri) { if (is_resource($streamResourceOrUri) === true) { $this->stream = $streamResourceOrUri; return; } $dirName = dirname($streamResourceOrUri); if (file_exists($dirName) === false) { mkdir($dirName, 0777, true); } if (file_exists($dirName) === false) { $message = 'Cannot find output directory "' . $dirName . '".'; throw new \RuntimeException($message); } $this->stream = fopen($streamResourceOrUri, 'wb'); } /** * The dtor closes the open output resource. */ public function __destruct() { if ($this->stream !== STDOUT && is_resource($this->stream) === true) { @fclose($this->stream); } $this->stream = null; } /** * Writes the given $data fragment to the wrapper output stream. * * @param string $data * @return void */ public function write($data) { fwrite($this->stream, $data); } } phpmd-2.8.1/src/main/resources/000077500000000000000000000000001360164303200163555ustar00rootroot00000000000000phpmd-2.8.1/src/main/resources/rulesets/000077500000000000000000000000001360164303200202235ustar00rootroot00000000000000phpmd-2.8.1/src/main/resources/rulesets/cleancode.xml000066400000000000000000000150501360164303200226630ustar00rootroot00000000000000 The Clean Code ruleset contains rules that enforce a clean code base. This includes rules from SOLID and object calisthenics. 1 1 1 1 2 'associative 0-element', // applied false => 'associative 0-element', // applied 'foo' => 'bar', // not applied "foo" => 'baz', // applied ]; } ]]> 1 Detects when a variable is used that has not been defined before. 3 phpmd-2.8.1/src/main/resources/rulesets/codesize.xml000066400000000000000000000346661360164303200225710ustar00rootroot00000000000000 The Code Size Ruleset contains a collection of rules that find code size related problems. 3 The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity. 3 Violations of this rule usually indicate that the method is doing too much. Try to reduce the method size by creating helper methods and removing any copy/pasted code. 3 Long Class files are indications that the class may be trying to do too much. Try to break it down, and reduce the size to something manageable. 3 Long parameter lists can indicate that a new object should be created to wrap the numerous parameters. Basically, try to group the parameters together. 3 A large number of public methods and attributes declared in a class can indicate the class may need to be broken up as increased effort will be required to thoroughly test it. 3 Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field. 3 3 3 3 phpmd-2.8.1/src/main/resources/rulesets/controversial.xml000066400000000000000000000113401360164303200236360ustar00rootroot00000000000000 This ruleset contains a collection of controversial rules. 1 1 1 1 1 1 phpmd-2.8.1/src/main/resources/rulesets/design.xml000066400000000000000000000216221360164303200222210ustar00rootroot00000000000000 The Design Ruleset contains a collection of rules that find software design related problems. 1 1 1 2 2 2 2 $item) { // … if ('qafoo' == $item) var_dump($i); // … } } } ]]> 2 2 phpmd-2.8.1/src/main/resources/rulesets/naming.xml000066400000000000000000000300301360164303200222120ustar00rootroot00000000000000 The Naming Ruleset contains a collection of rules about names - too long, too short, and so forth. Detects when a field, local, or parameter has a very short name. 3 q; // VIOLATION - Local for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR) $r += $this->q; } } } ]]> Detects when a field, formal or local variable is declared with a long name. 3 Detects when very short method names are used. 3 A constructor method should not have the same name as the enclosing class, consider to use the PHP 5 __construct method. 3 Class/Interface constant names should always be defined in uppercase. 4 Looks for methods named 'getX()' with 'boolean' as the return type. The convention is to name these methods 'isX()' or 'hasX()'. 4 phpmd-2.8.1/src/main/resources/rulesets/unusedcode.xml000066400000000000000000000061351360164303200231100ustar00rootroot00000000000000 The Unused Code Ruleset contains a collection of rules that find unused code. Detects when a private field is declared and/or assigned a value, but not used. 3 j++; } } ]]> Detects when a local variable is declared and/or assigned, but not used. 3 Unused Private Method detects when a private method is declared but is unused. 3 Avoid passing parameters to methods or constructors and then not using those parameters. 3 phpmd-2.8.1/src/test/000077500000000000000000000000001360164303200143765ustar00rootroot00000000000000phpmd-2.8.1/src/test/php/000077500000000000000000000000001360164303200151655ustar00rootroot00000000000000phpmd-2.8.1/src/test/php/PHPMD/000077500000000000000000000000001360164303200160355ustar00rootroot00000000000000phpmd-2.8.1/src/test/php/PHPMD/AbstractTest.php000066400000000000000000000441441360164303200211600ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD; use PDepend\Source\AST\ASTClass; use PDepend\Source\AST\ASTFunction; use PDepend\Source\AST\ASTMethod; use PDepend\Source\Language\PHP\PHPBuilder; use PDepend\Source\Language\PHP\PHPParserGeneric; use PDepend\Source\Language\PHP\PHPTokenizerInternal; use PDepend\Util\Cache\Driver\MemoryCacheDriver; use PHPMD\Node\ClassNode; use PHPMD\Node\FunctionNode; use PHPMD\Node\InterfaceNode; use PHPMD\Node\MethodNode; use PHPMD\Node\TraitNode; use PHPMD\Rule\Design\TooManyFields; use PHPMD\Stubs\RuleStub; use PHPUnit_Framework_MockObject_MockBuilder; /** * Abstract base class for PHPMD test cases. */ abstract class AbstractTest extends \PHPUnit_Framework_TestCase { /** * Directory with test files. * * @var string $_filesDirectory */ private static $filesDirectory = null; /** * Original directory is used to reset a changed working directory. * * @return void */ private static $originalWorkingDirectory = null; /** * Temporary files created by a test. * * @var array(string) */ private static $tempFiles = array(); /** * Resets a changed working directory. * * @return void */ protected function tearDown() { if (self::$originalWorkingDirectory !== null) { chdir(self::$originalWorkingDirectory); } self::$originalWorkingDirectory = null; foreach (self::$tempFiles as $tempFile) { unlink($tempFile); } self::$tempFiles = array(); parent::tearDown(); } /** * Returns the first class found in a source file related to the calling * test method. * * @return \PHPMD\Node\ClassNode */ protected function getClass() { return new ClassNode( $this->getNodeForCallingTestCase( $this->parseTestCaseSource()->getClasses() ) ); } /** * Returns the first interface found in a source file related to the calling * test method. * * @return \PHPMD\Node\InterfaceNode */ protected function getInterface() { return new InterfaceNode( $this->getNodeForCallingTestCase( $this->parseTestCaseSource()->getInterfaces() ) ); } /** * @return \PHPMD\Node\InterfaceNode */ protected function getTrait() { return new TraitNode( $this->getNodeForCallingTestCase( $this->parseTestCaseSource()->getTraits() ) ); } /** * Returns the first method found in a source file related to the calling * test method. * * @return \PHPMD\Node\MethodNode */ protected function getMethod() { return new MethodNode( $this->getNodeForCallingTestCase( $this->parseTestCaseSource() ->getTypes() ->current() ->getMethods() ) ); } /** * Returns the first function found in a source files related to the calling * test method. * * @return \PHPMD\Node\FunctionNode */ protected function getFunction() { return new FunctionNode( $this->getNodeForCallingTestCase( $this->parseTestCaseSource()->getFunctions() ) ); } /** * Returns the absolute path for a test resource for the current test. * * @return string * @since 1.1.0 */ protected static function createCodeResourceUriForTest() { $frame = self::getCallingTestCase(); return self::createResourceUriForTest($frame['function'] . '.php'); } /** * Returns the absolute path for a test resource for the current test. * * @param string $localPath The local/relative file location * @return string * @since 1.1.0 */ protected static function createResourceUriForTest($localPath) { $frame = self::getCallingTestCase(); $regexp = '([a-z]([0-9]+)Test$)i'; if (preg_match($regexp, $frame['class'], $match)) { $parts = explode('\\', $frame['class']); $testPath = $parts[count($parts) - 2] . '/' . $match[1]; } else { $testPath = strtr(substr($frame['class'], 6, -4), '\\', '/'); } return sprintf( '%s/../../resources/files/%s/%s', dirname(__FILE__), $testPath, $localPath ); } /** * Parses the source code for the calling test method and returns the first * package node found in the parsed file. * * @return PHP_Depend_Code_Package */ private function parseTestCaseSource() { return $this->parseSource($this->createCodeResourceUriForTest()); } /** * Returns the trace frame of the calling test case. * * @return array * @throws \ErrorException */ private static function getCallingTestCase() { foreach (debug_backtrace() as $frame) { if (strpos($frame['function'], 'test') === 0) { return $frame; } } throw new \ErrorException('Cannot locate calling test case.'); } /** * Returns the PHP_Depend node for the calling test case. * * @param \Iterator $nodes * @return PHP_Depend_Code_AbstractItem * @throws \ErrorException */ private function getNodeForCallingTestCase(\Iterator $nodes) { $frame = $this->getCallingTestCase(); foreach ($nodes as $node) { if ($node->getName() === $frame['function']) { return $node; } } throw new \ErrorException('Cannot locate node for test case.'); } /** * Parses the source of the given file and returns the first package found * in that file. * * @param string $sourceFile * @return \PDepend\Source\AST\ASTNamespace * @throws \ErrorException */ private function parseSource($sourceFile) { if (file_exists($sourceFile) === false) { throw new \ErrorException('Cannot locate source file: ' . $sourceFile); } $tokenizer = new PHPTokenizerInternal(); $tokenizer->setSourceFile($sourceFile); $builder = new PHPBuilder(); $parser = new PHPParserGeneric( $tokenizer, $builder, new MemoryCacheDriver() ); $parser->parse(); return $builder->getNamespaces()->current(); } /** * Creates a mocked class node instance. * * @param string $metric * @param mixed $value * @return \PHPMD\Node\ClassNode */ protected function getClassMock($metric = null, $value = null) { $class = $this->getMockFromBuilder( $this->getMockBuilder('PHPMD\\Node\\ClassNode') ->setConstructorArgs(array(new ASTClass('FooBar'))) ); if ($metric !== null) { $class->expects($this->atLeastOnce()) ->method('getMetric') ->with($this->equalTo($metric)) ->will($this->returnValue($value)); } return $class; } /** * Creates a mocked method node instance. * * @param string $metric * @param mixed $value * @return \PHPMD\Node\MethodNode */ protected function getMethodMock($metric = null, $value = null) { return $this->initFunctionOrMethod( $this->getMockFromBuilder( $this->getMockBuilder('PHPMD\\Node\\MethodNode') ->setConstructorArgs(array(new ASTMethod('fooBar'))) ), $metric, $value ); } /** * Creates a mocked function node instance. * * @param string $metric The metric acronym used by PHP_Depend. * @param mixed $value The expected metric return value. * @return \PHPMD\Node\FunctionNode */ protected function createFunctionMock($metric = null, $value = null) { return $this->initFunctionOrMethod( $this->getMockFromBuilder( $this->getMockBuilder('PHPMD\\Node\\FunctionNode') ->setConstructorArgs(array(new ASTFunction('fooBar'))) ), $metric, $value ); } /** * Initializes the getMetric() method of the given function or method node. * * @param \PHPMD\Node\FunctionNode|\PHPMD\Node\MethodNode $mock * @param string $metric * @param mixed $value * @return \PHPMD\Node\FunctionNode|\PHPMD\Node\MethodNode */ protected function initFunctionOrMethod($mock, $metric, $value) { if ($metric === null) { return $mock; } $mock->expects($this->atLeastOnce()) ->method('getMetric') ->with($this->equalTo($metric)) ->will($this->returnValue($value)); return $mock; } /** * Creates a mocked report instance. * * @param integer $expectedInvokes Number of expected invokes. * @return \PHPMD\Report */ protected function getReportMock($expectedInvokes = -1) { if ($expectedInvokes < 0) { $expects = $this->atLeastOnce(); } elseif ($expectedInvokes === 0) { $expects = $this->never(); } elseif ($expectedInvokes === 1) { $expects = $this->once(); } else { $expects = $this->exactly($expectedInvokes); } $report = $this->getMockFromBuilder($this->getMockBuilder('PHPMD\\Report')); $report->expects($expects) ->method('addRuleViolation'); return $report; } protected function getMockFromBuilder(PHPUnit_Framework_MockObject_MockBuilder $builder) { if (version_compare(phpversion(), '7.4.0-dev', '<')) { return $builder->getMock(); } return @$builder->getMock(); } /** * Creates a mocked {@link \PHPMD\AbstractRule} instance. * * @return \PHPMD\AbstractRule */ protected function getRuleMock() { if (version_compare(phpversion(), '7.4.0-dev', '<')) { return $this->getMockForAbstractClass('PHPMD\\AbstractRule'); } return @$this->getMockForAbstractClass('PHPMD\\AbstractRule'); } /** * Creates a mocked rule-set instance. * * @param string $expectedClass Optional class name for apply() expected at least once. * @param mixed $count How often should apply() be called? * @return \PHPMD\RuleSet */ protected function getRuleSetMock($expectedClass = null, $count = '*') { $ruleSet = $this->getMockFromBuilder($this->getMockBuilder('PHPMD\RuleSet')); if ($expectedClass === null) { $ruleSet->expects($this->never())->method('apply'); } else { $ruleSet->expects( $count === '*' ? $this->atLeastOnce() : $this->exactly($count) ) ->method('apply') ->with($this->isInstanceOf($expectedClass)); } return $ruleSet; } /** * Creates a mocked rule violation instance. * * @param string $fileName The filename to use. * @param integer $beginLine The begin of violation line number to use. * @param integer $endLine The end of violation line number to use. * @param null|object $rule The rule object to use. * @param null|string $description The violation description to use. * @return \PHPUnit_Framework_MockObject_MockObject */ protected function getRuleViolationMock( $fileName = '/foo/bar.php', $beginLine = 23, $endLine = 42, $rule = null, $description = null ) { $ruleViolation = $this->getMockFromBuilder( $this->getMockBuilder('PHPMD\\RuleViolation') ->setConstructorArgs(array(new TooManyFields(), new FunctionNode(new ASTFunction('fooBar')), 'Hello')) ); if ($rule === null) { $rule = new RuleStub(); } if ($description === null) { $description = 'Test description'; } $ruleViolation->expects($this->any()) ->method('getRule') ->will($this->returnValue($rule)); $ruleViolation->expects($this->any()) ->method('getFileName') ->will($this->returnValue($fileName)); $ruleViolation->expects($this->any()) ->method('getBeginLine') ->will($this->returnValue($beginLine)); $ruleViolation->expects($this->any()) ->method('getEndLine') ->will($this->returnValue($endLine)); $ruleViolation->expects($this->any()) ->method('getNamespaceName') ->will($this->returnValue('TestStubPackage')); $ruleViolation->expects($this->any()) ->method('getDescription') ->will($this->returnValue($description)); return $ruleViolation; } /** * Creates a mocked rul violation instance. * * @param string $file * @param string $message * @return \PHPMD\ProcessingError */ protected function getErrorMock( $file = '/foo/baz.php', $message = 'Error in file "/foo/baz.php"') { $processingError = $this->getMockFromBuilder( $this->getMockBuilder('PHPMD\\ProcessingError') ->setConstructorArgs(array(null)) ->setMethods(array('getFile', 'getMessage')) ); $processingError->expects($this->any()) ->method('getFile') ->will($this->returnValue($file)); $processingError->expects($this->any()) ->method('getMessage') ->will($this->returnValue($message)); return $processingError; } /** * Asserts the actual xml output matches against the expected file. * * @param string $actualOutput Generated xml output. * @param string $expectedFileName File with expected xml result. * @return void */ public static function assertXmlEquals($actualOutput, $expectedFileName) { $actual = simplexml_load_string($actualOutput); // Remove dynamic timestamp and duration attribute if (isset($actual['timestamp'])) { $actual['timestamp'] = ''; } if (isset($actual['duration'])) { $actual['duration'] = ''; } if (isset($actual['version'])) { $actual['version'] = '@package_version@'; } $expected = str_replace( '#{rootDirectory}', self::$filesDirectory, file_get_contents(self::createFileUri($expectedFileName)) ); $expected = str_replace('_DS_', DIRECTORY_SEPARATOR, $expected); self::assertXmlStringEqualsXmlString($expected, $actual->saveXML()); } /** * Asserts the actual JSON output matches against the expected file. * * @param string $actualOutput Generated JSON output. * @param string $expectedFileName File with expected JSON result. * * @return void */ public static function assertJsonEquals($actualOutput, $expectedFileName) { $actual = json_decode($actualOutput, true); // Remove dynamic timestamp and duration attribute if (isset($actual['timestamp'])) { $actual['timestamp'] = ''; } if (isset($actual['duration'])) { $actual['duration'] = ''; } if (isset($actual['version'])) { $actual['version'] = '@package_version@'; } $expected = str_replace( '#{rootDirectory}', self::$filesDirectory, file_get_contents(self::createFileUri($expectedFileName)) ); $expected = str_replace('_DS_', DIRECTORY_SEPARATOR, $expected); self::assertJsonStringEqualsJsonString($expected, json_encode($actual)); } /** * This method initializes the test environment, it configures the files * directory and sets the include_path for svn versions. * * @return void */ public static function setUpBeforeClass() { self::$filesDirectory = realpath(__DIR__ . '/../../resources/files'); if (false === strpos(get_include_path(), self::$filesDirectory)) { set_include_path( sprintf( '%s%s%s%s%s', get_include_path(), PATH_SEPARATOR, self::$filesDirectory, PATH_SEPARATOR, realpath(__DIR__ . '/../') ) ); } // Prevent timezone warnings if no default TZ is set (PHP > 5.1.0) date_default_timezone_set('UTC'); } /** * Changes the working directory for a single test. * * @param string $localPath The temporary working directory. * @return void */ protected static function changeWorkingDirectory($localPath = '') { self::$originalWorkingDirectory = getcwd(); if (0 === preg_match('(^([A-Z]:|/))', $localPath)) { $localPath = self::createFileUri($localPath); } chdir($localPath); } /** * Creates a full filename for a test content in the _files directory. * * @param string $localPath * @return string */ protected static function createFileUri($localPath = '') { return self::$filesDirectory . '/' . $localPath; } /** * Creates a file uri for a temporary test file. * * @return string */ protected static function createTempFileUri() { return (self::$tempFiles[] = tempnam(sys_get_temp_dir(), 'phpmd.')); } } phpmd-2.8.1/src/test/php/PHPMD/Integration/000077500000000000000000000000001360164303200203205ustar00rootroot00000000000000phpmd-2.8.1/src/test/php/PHPMD/Integration/CommandLineInputFileOptionTest.php000066400000000000000000000041461360164303200270750ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Integration; use PHPMD\AbstractTest; use PHPMD\TextUI\Command; /** * Integration tests for the command line option --inputfile. * * @since 1.1.0 */ class CommandLineInputFileOptionTest extends AbstractTest { /** * testReportContainsExpectedRuleViolationWarning * * @return void * @outputBuffering enabled */ public function testReportContainsExpectedRuleViolationWarning() { self::assertContains( "Avoid unused local variables such as '\$foo'.", self::runCommandLine() ); } /** * testReportNotContainsRuleViolationWarningForFileNotInList * * @return void * @outputBuffering enabled */ public function testReportNotContainsRuleViolationWarningForFileNotInList() { self::assertNotContains( "Avoid unused local variables such as '\$bar'.", self::runCommandLine() ); } /** * Runs the PHPMD command line interface and returns the report content. * * @return string */ protected static function runCommandLine() { $inputfile = self::createResourceUriForTest('inputfile.txt'); $reportfile = self::createTempFileUri(); self::changeWorkingDirectory(dirname($inputfile)); Command::main( array( __FILE__, 'text', 'unusedcode', '--reportfile', $reportfile, '--inputfile', $inputfile ) ); return file_get_contents($reportfile); } } phpmd-2.8.1/src/test/php/PHPMD/Integration/CouplingBetweenObjectsIntegrationTest.php000066400000000000000000000027031360164303200305030ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Integration; use PHPMD\AbstractTest; use PHPMD\TextUI\Command; /** * Integration tests for the coupling between objects rule class. * * @since 1.1.0 */ class CouplingBetweenObjectsIntegrationTest extends AbstractTest { /** * testReportContainsCouplingBetweenObjectsWarning * * @return void * @outputBuffering enabled */ public function testReportContainsCouplingBetweenObjectsWarning() { $file = self::createTempFileUri(); Command::main( array( __FILE__, $this->createCodeResourceUriForTest(), 'text', 'design', '--reportfile', $file ) ); self::assertContains( 'has a coupling between objects value of 14. ' . 'Consider to reduce the number of dependencies under 13.', file_get_contents($file) ); } } phpmd-2.8.1/src/test/php/PHPMD/Integration/GotoStatementIntegrationTest.php000066400000000000000000000024541360164303200266770ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Integration; use PHPMD\AbstractTest; use PHPMD\TextUI\Command; /** * Test case for the goto statement GotoStatementIntegrationTest. * * @since 1.1.0 */ class GotoStatementIntegrationTest extends AbstractTest { /** * testReportContainsGotoStatementWarning * * @return void * @outputBuffering enabled */ public function testReportContainsGotoStatementWarning() { $file = self::createTempFileUri(); Command::main( array( __FILE__, $this->createCodeResourceUriForTest(), 'text', 'design', '--reportfile', $file ) ); self::assertContains('utilizes a goto statement.', file_get_contents($file)); } } phpmd-2.8.1/src/test/php/PHPMD/Node/000077500000000000000000000000001360164303200167225ustar00rootroot00000000000000phpmd-2.8.1/src/test/php/PHPMD/Node/ASTNodeTest.php000066400000000000000000000057451360164303200215430ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Node; use PHPMD\AbstractTest; /** * Test case for the {@link \PHPMD\Node\ASTNode} class. * * @covers \PHPMD\Node\ASTNode */ class ASTNodeTest extends AbstractTest { /** * testGetImageDelegatesToGetImageMethodOfWrappedNode * * @return void */ public function testGetImageDelegatesToGetImageMethodOfWrappedNode() { $mock = $this->getMockFromBuilder($this->getMockBuilder('PDepend\Source\AST\ASTNode')); $mock->expects($this->once()) ->method('getImage'); $node = new ASTNode($mock, __FILE__); $node->getImage(); } /** * testGetNameDelegatesToGetImageMethodOfWrappedNode * * @return void */ public function testGetNameDelegatesToGetImageMethodOfWrappedNode() { $mock = $this->getMockFromBuilder($this->getMockBuilder('PDepend\Source\AST\ASTNode')); $mock->expects($this->once()) ->method('getImage'); $node = new ASTNode($mock, __FILE__); $node->getName(); } /** * testHasSuppressWarningsAnnotationForAlwaysReturnsFalse * * @return void */ public function testHasSuppressWarningsAnnotationForAlwaysReturnsFalse() { $mock = $this->getMockFromBuilder($this->getMockBuilder('PDepend\Source\AST\ASTNode')); $node = new ASTNode($mock, __FILE__); $rule = $this->getRuleMock(); $this->assertFalse($node->hasSuppressWarningsAnnotationFor($rule)); } /** * testGetParentNameReturnsNull * * @return void */ public function testGetParentNameReturnsNull() { $mock = $this->getMockFromBuilder($this->getMockBuilder('PDepend\Source\AST\ASTNode')); $node = new ASTNode($mock, __FILE__); $this->assertNull($node->getParentName()); } /** * testGetNamespaceNameReturnsNull * * @return void */ public function testGetNamespaceNameReturnsNull() { $mock = $this->getMockFromBuilder($this->getMockBuilder('PDepend\Source\AST\ASTNode')); $node = new ASTNode($mock, __FILE__); $this->assertNull($node->getNamespaceName()); } /** * testGetFullQualifiedNameReturnsNull * * @return void */ public function testGetFullQualifiedNameReturnsNull() { $mock = $this->getMockFromBuilder($this->getMockBuilder('PDepend\Source\AST\ASTNode')); $node = new ASTNode($mock, __FILE__); $this->assertNull($node->getFullQualifiedName()); } } phpmd-2.8.1/src/test/php/PHPMD/Node/AnnotationTest.php000066400000000000000000000073171360164303200224150ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Node; use PHPMD\AbstractTest; /** * Test case for the {@link \PHPMD\Node\Annotation} class. * * @covers \PHPMD\Node\Annotation */ class AnnotationTest extends AbstractTest { /** * testAnnotationReturnsFalseWhenNoSuppressWarningAnnotationExists * * @return void */ public function testAnnotationReturnsFalseWhenNoSuppressWarningAnnotationExists() { $annotation = new Annotation('NoSuppressWarning', 'PMD'); $this->assertFalse($annotation->suppresses($this->getRuleMock())); } /** * testAnnotationReturnsFalseWhenSuppressWarningContainsInvalidValue * * @return void */ public function testAnnotationReturnsFalseWhenSuppressWarningContainsInvalidValue() { $annotation = new Annotation('SuppressWarnings', 'PHP'); $this->assertFalse($annotation->suppresses($this->getRuleMock())); } /** * testAnnotationReturnsTrueWhenSuppressWarningContainsWithPMD * * @return void */ public function testAnnotationReturnsTrueWhenSuppressWarningContainsWithPMD() { $annotation = new Annotation('SuppressWarnings', 'PMD'); $this->assertTrue($annotation->suppresses($this->getRuleMock())); } /** * testAnnotationReturnsTrueWhenSuppressWarningContainsWithPHPMD * * @return void */ public function testAnnotationReturnsTrueWhenSuppressWarningContainsWithPHPMD() { $annotation = new Annotation('SuppressWarnings', 'PHPMD'); $this->assertTrue($annotation->suppresses($this->getRuleMock())); } /** * testAnnotationReturnsTrueWhenSuppressWarningContainsWithPHPMDLCFirst * * @return void */ public function testAnnotationReturnsTrueWhenSuppressWarningContainsWithPHPMDLCFirst() { $annotation = new Annotation('suppressWarnings', 'PHPMD'); $this->assertTrue($annotation->suppresses($this->getRuleMock())); } /** * testAnnotationReturnsTrueWhenSuppressWarningContainsPMDPlusRuleName * * @return void */ public function testAnnotationReturnsTrueWhenSuppressWarningContainsPMDPlusRuleName() { $rule = $this->getRuleMock(); $rule->setName('UnusedCodeRule'); $annotation = new Annotation('SuppressWarnings', 'PMD.UnusedCodeRule'); $this->assertTrue($annotation->suppresses($rule)); } /** * testAnnotationReturnsTrueWhenSuppressWarningContainsPHPMDPlusRuleName * * @return void */ public function testAnnotationReturnsTrueWhenSuppressWarningContainsPHPMDPlusRuleName() { $rule = $this->getRuleMock(); $rule->setName('UnusedCodeRule'); $annotation = new Annotation('SuppressWarnings', 'PHPMD.UnusedCodeRule'); $this->assertTrue($annotation->suppresses($rule)); } /** * testAnnotationReturnsTrueWhenSuppressWarningContainsPartialRuleName * * @return void */ public function testAnnotationReturnsTrueWhenSuppressWarningContainsPartialRuleName() { $rule = $this->getRuleMock(); $rule->setName('UnusedCodeRule'); $annotation = new Annotation('SuppressWarnings', 'unused'); $this->assertTrue($annotation->suppresses($rule)); } } phpmd-2.8.1/src/test/php/PHPMD/Node/AnnotationsTest.php000066400000000000000000000060131360164303200225700ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Node; use PHPMD\AbstractTest; /** * Test case for the {@link \PHPMD\Node\Annotations} class. * * @covers \PHPMD\Node\Annotations */ class AnnotationsTest extends AbstractTest { /** * testCollectionReturnsFalseWhenNoAnnotationExists * * @return void */ public function testCollectionReturnsFalseWhenNoAnnotationExists() { $annotations = new Annotations($this->getClassMock()); $this->assertFalse($annotations->suppresses($this->getRuleMock())); } /** * testCollectionReturnsFalseWhenNoMatchingAnnotationExists * * @return void */ public function testCollectionReturnsFalseWhenNoMatchingAnnotationExists() { $class = $this->getClassMock(); $class->expects($this->once()) ->method('__call') ->with($this->equalTo('getDocComment')) ->will( $this->returnValue( '/** * @SuppressWarnings("Foo") * @SuppressWarnings("Bar") * @SuppressWarnings("Baz") */' ) ); $annotations = new Annotations($class); $this->assertFalse($annotations->suppresses($this->getRuleMock())); } /** * testCollectionReturnsTrueWhenMatchingAnnotationExists * * @return void */ public function testCollectionReturnsTrueWhenMatchingAnnotationExists() { $class = $this->getClassMock(); $class->expects($this->once()) ->method('__call') ->with($this->equalTo('getDocComment')) ->will($this->returnValue('/** @SuppressWarnings("PMD") */')); $annotations = new Annotations($class); $this->assertTrue($annotations->suppresses($this->getRuleMock())); } /** * testCollectionReturnsTrueWhenOneMatchingAnnotationExists * * @return void */ public function testCollectionReturnsTrueWhenOneMatchingAnnotationExists() { $class = $this->getClassMock(); $class->expects($this->once()) ->method('__call') ->with($this->equalTo('getDocComment')) ->will( $this->returnValue( '/** * @SuppressWarnings("FooBar") * @SuppressWarnings("PMD") */' ) ); $annotations = new Annotations($class); $this->assertTrue($annotations->suppresses($this->getRuleMock())); } } phpmd-2.8.1/src/test/php/PHPMD/Node/ClassNodeTest.php000066400000000000000000000053431360164303200221530ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Node; use PDepend\Source\AST\ASTClass; use PDepend\Source\AST\ASTMethod; use PDepend\Source\AST\ASTNamespace; use PHPMD\AbstractTest; /** * Test case for the class node implementation. * * @covers \PHPMD\Node\ClassNode * @covers \PHPMD\Node\AbstractTypeNode */ class ClassNodeTest extends AbstractTest { /** * testGetMethodNamesReturnsExpectedResult * * @return void */ public function testGetMethodNamesReturnsExpectedResult() { $class = new ASTClass(null); $class->addMethod(new ASTMethod(__CLASS__)); $class->addMethod(new ASTMethod(__FUNCTION__)); $node = new ClassNode($class); $this->assertEquals(array(__CLASS__, __FUNCTION__), $node->getMethodNames()); } /** * testHasSuppressWarningsAnnotationForReturnsTrue * * @return void */ public function testHasSuppressWarningsAnnotationForReturnsTrue() { $class = new ASTClass(null); $class->setComment('/** @SuppressWarnings("PMD") */'); $rule = $this->getMockFromBuilder($this->getMockBuilder('PHPMD\\AbstractRule')); $node = new ClassNode($class); $this->assertTrue($node->hasSuppressWarningsAnnotationFor($rule)); } /** * testGetFullQualifiedNameReturnsExpectedValue * * @return void */ public function testGetFullQualifiedNameReturnsExpectedValue() { $class = new ASTClass('MyClass'); $class->setNamespace(new ASTNamespace('Sindelfingen')); $node = new ClassNode($class); $this->assertSame('Sindelfingen\\MyClass', $node->getFullQualifiedName()); } /** * @return void */ public function testGetConstantCountReturnsZeroByDefault() { $class = new ClassNode(new ASTClass('MyClass')); $this->assertSame(0, $class->getConstantCount()); } /** * @return void */ public function testGetConstantCount() { $class = $this->getClass(); $this->assertSame(3, $class->getConstantCount()); } /** * @return void */ public function testGetParentNameReturnsNull() { $class = new ClassNode(new ASTClass('MyClass')); $this->assertNull($class->getParentName()); } } phpmd-2.8.1/src/test/php/PHPMD/Node/FunctionTest.php000066400000000000000000000031351360164303200220620ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Node; use PDepend\Source\AST\ASTFunction; use PHPMD\AbstractTest; /** * Test case for the function node implementation. * * @covers \PHPMD\Node\FunctionNode * @covers \PHPMD\Node\AbstractCallableNode */ class FunctionNodeTest extends AbstractTest { /** * testMagicCallDelegatesToWrappedPHPDependFunction * * @return void */ public function testMagicCallDelegatesToWrappedPHPDependFunction() { $function = $this->getMockFromBuilder( $this->getMockBuilder('PDepend\\Source\\AST\\ASTFunction') ->setConstructorArgs(array(null)) ); $function->expects($this->once()) ->method('getStartLine'); $node = new FunctionNode($function); $node->getStartLine(); } /** * testMagicCallThrowsExceptionWhenNoMatchingMethodExists * * @return void * @expectedException BadMethodCallException */ public function testMagicCallThrowsExceptionWhenNoMatchingMethodExists() { $node = new FunctionNode(new ASTFunction(null)); $node->getFooBar(); } } phpmd-2.8.1/src/test/php/PHPMD/Node/InterfaceNodeTest.php000066400000000000000000000035721360164303200230100ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Node; use PDepend\Source\AST\ASTInterface; use PDepend\Source\AST\ASTNamespace; use PHPMD\AbstractTest; /** * Test case for the interface node implementation. * @covers \PHPMD\Node\InterfaceNode * @covers \PHPMD\Node\AbstractTypeNode */ class InterfaceNodeTest extends AbstractTest { /** * testGetFullQualifiedNameReturnsExpectedValue * * @return void */ public function testGetFullQualifiedNameReturnsExpectedValue() { $interface = new ASTInterface('MyInterface'); $interface->setNamespace(new ASTNamespace('Sindelfingen')); $node = new InterfaceNode($interface); $this->assertSame('Sindelfingen\\MyInterface', $node->getFullQualifiedName()); } /** * @return void */ public function testGetConstantCountReturnsZeroByDefault() { $interface = new InterfaceNode(new ASTInterface('MyInterface')); $this->assertSame(0, $interface->getConstantCount()); } /** * @return void */ public function testGetConstantCount() { $class = $this->getInterface(); $this->assertSame(3, $class->getConstantCount()); } /** * @return void */ public function testGetParentNameReturnsNull() { $interface = new InterfaceNode(new ASTInterface('MyInterface')); $this->assertNull($interface->getParentName()); } } phpmd-2.8.1/src/test/php/PHPMD/Node/MethodNodeTest.php000066400000000000000000000142101360164303200223170ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Node; use PDepend\Source\AST\ASTClass; use PDepend\Source\AST\ASTMethod; use PDepend\Source\AST\ASTNamespace; use PHPMD\AbstractTest; /** * Test case for the method node implementation. * * @covers \PHPMD\Node\MethodNode * @covers \PHPMD\Node\AbstractCallableNode */ class MethodNodeTest extends AbstractTest { /** * testMagicCallDelegatesToWrappedPHPDependMethod * * @return void */ public function testMagicCallDelegatesToWrappedPHPDependMethod() { $method = $this->getMockFromBuilder( $this->getMockBuilder('PDepend\\Source\\AST\\ASTMethod') ->setConstructorArgs(array(null)) ); $method->expects($this->once()) ->method('getStartLine'); $node = new MethodNode($method); $node->getStartLine(); } /** * testMagicCallThrowsExceptionWhenNoMatchingMethodExists * * @return void * @expectedException \BadMethodCallException */ public function testMagicCallThrowsExceptionWhenNoMatchingMethodExists() { $node = new MethodNode(new ASTMethod(null)); $node->getFooBar(); } /** * testGetParentTypeReturnsInterfaceForInterfaceMethod * * @return void */ public function testGetParentTypeReturnsInterfaceForInterfaceMethod() { $this->assertInstanceOf( 'PHPMD\\Node\\InterfaceNode', $this->getMethod()->getParentType() ); } /** * testGetParentTypeReturnsClassForClassMethod * * @return void */ public function testGetParentTypeReturnsClassForClassMethod() { $this->assertInstanceOf( 'PHPMD\\Node\\ClassNode', $this->getMethod()->getParentType() ); } /** * @return void */ public function testGetParentTypeReturnsTrait() { $this->assertInstanceOf( 'PHPMD\\Node\\TraitNode', $this->getMethod()->getParentType() ); } /** * testHasSuppressWarningsExecutesDefaultImplementation * * @return void */ public function testHasSuppressWarningsExecutesDefaultImplementation() { $rule = $this->getRuleMock(); $rule->setName('FooBar'); $method = $this->getMethod(); $this->assertTrue($method->hasSuppressWarningsAnnotationFor($rule)); } /** * testHasSuppressWarningsDelegatesToParentClassMethod * * @return void */ public function testHasSuppressWarningsDelegatesToParentClassMethod() { $rule = $this->getRuleMock(); $rule->setName('FooBar'); $method = $this->getMethod(); $this->assertTrue($method->hasSuppressWarningsAnnotationFor($rule)); } /** * testHasSuppressWarningsDelegatesToParentInterfaceMethod * * @return void */ public function testHasSuppressWarningsDelegatesToParentInterfaceMethod() { $rule = $this->getRuleMock(); $rule->setName('FooBar'); $method = $this->getMethod(); $this->assertTrue($method->hasSuppressWarningsAnnotationFor($rule)); } /** * testHasSuppressWarningsIgnoresCaseFirstLetter * * @return void */ public function testHasSuppressWarningsIgnoresCaseFirstLetter() { $rule = $this->getRuleMock(); $rule->setName('FooBar'); $method = $this->getMethod(); $this->assertTrue($method->hasSuppressWarningsAnnotationFor($rule)); } /** * testIsDeclarationReturnsTrueForMethodDeclaration * * @return void * @since 1.2.1 */ public function testIsDeclarationReturnsTrueForMethodDeclaration() { $method = $this->getMethod(); $this->assertTrue($method->isDeclaration()); } /** * testIsDeclarationReturnsTrueForMethodDeclarationWithParent * * @return void * @since 1.2.1 */ public function testIsDeclarationReturnsTrueForMethodDeclarationWithParent() { $method = $this->getMethod(); $this->assertTrue($method->isDeclaration()); } /** * testIsDeclarationReturnsFalseForInheritMethodDeclaration * * @return void * @since 1.2.1 */ public function testIsDeclarationReturnsFalseForInheritMethodDeclaration() { $method = $this->getMethod(); $this->assertFalse($method->isDeclaration()); } /** * testIsDeclarationReturnsFalseForImplementedAbstractMethod * * @return void * @since 1.2.1 */ public function testIsDeclarationReturnsFalseForImplementedAbstractMethod() { $method = $this->getMethod(); $this->assertFalse($method->isDeclaration()); } /** * testIsDeclarationReturnsFalseForImplementedInterfaceMethod * * @return void * @since 1.2.1 */ public function testIsDeclarationReturnsFalseForImplementedInterfaceMethod() { $method = $this->getMethod(); $this->assertFalse($method->isDeclaration()); } /** * @return void */ public function testIsDeclarationReturnsTrueForPrivateMethod() { $method = $this->getMethod(); $this->assertTrue($method->isDeclaration()); } /** * testGetFullQualifiedNameReturnsExpectedValue * * @return void */ public function testGetFullQualifiedNameReturnsExpectedValue() { $class = new ASTClass('MyClass'); $class->setNamespace(new ASTNamespace('Sindelfingen')); $method = new ASTMethod('beer'); $method->setParent($class); $node = new MethodNode($method); $this->assertSame('Sindelfingen\\MyClass::beer()', $node->getFullQualifiedName()); } } phpmd-2.8.1/src/test/php/PHPMD/Node/TraitNodeTest.php000066400000000000000000000031531360164303200221660ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Node; use PDepend\Source\AST\ASTTrait; use PDepend\Source\AST\ASTNamespace; use PHPMD\AbstractTest; /** * Test case for the trait node implementation. * * @covers \PHPMD\Node\TraitNode * @covers \PHPMD\Node\AbstractTypeNode */ class TraitNodeTest extends AbstractTest { /** * testGetFullQualifiedNameReturnsExpectedValue * * @return void */ public function testGetFullQualifiedNameReturnsExpectedValue() { $trait = new ASTTrait('MyTrait'); $trait->setNamespace(new ASTNamespace('Sindelfingen')); $node = new TraitNode($trait); $this->assertSame('Sindelfingen\\MyTrait', $node->getFullQualifiedName()); } /** * @return void */ public function testGetConstantCountReturnsZeroByDefault() { $trait = new TraitNode(new ASTTrait('MyTrait')); $this->assertSame(0, $trait->getConstantCount()); } /** * @return void */ public function testGetParentNameReturnsNull() { $trait = new TraitNode(new ASTTrait('MyTrait')); $this->assertNull($trait->getParentName()); } } phpmd-2.8.1/src/test/php/PHPMD/PHPMDTest.php000066400000000000000000000100241360164303200202530ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD; use PHPMD\Renderer\XMLRenderer; use PHPMD\Stubs\WriterStub; /** * Test case for the main PHPMD class. * * @covers \PHPMD\PHPMD */ class PHPMDTest extends AbstractTest { /** * Tests the main PHPMD interface with default settings an a xml-renderer. * * @return void */ public function testRunWithDefaultSettingsAndXmlRenderer() { self::changeWorkingDirectory(); $writer = new WriterStub(); $renderer = new XMLRenderer(); $renderer->setWriter($writer); $phpmd = new PHPMD(); $phpmd->processFiles( self::createFileUri('source/ccn_function.php'), 'pmd-refset1', array($renderer), new RuleSetFactory() ); $this->assertXmlEquals($writer->getData(), 'pmd/default-xml.xml'); } /** * testRunWithDefaultSettingsAndXmlRendererAgainstSingleFile * * @return void */ public function testRunWithDefaultSettingsAndXmlRendererAgainstDirectory() { self::changeWorkingDirectory(); $writer = new WriterStub(); $renderer = new XMLRenderer(); $renderer->setWriter($writer); $phpmd = new PHPMD(); $phpmd->processFiles( self::createFileUri('source'), 'pmd-refset1', array($renderer), new RuleSetFactory() ); $this->assertXmlEquals($writer->getData(), 'pmd/single-directory.xml'); } /** * testRunWithDefaultSettingsAndXmlRendererAgainstSingleFile * * @return void */ public function testRunWithDefaultSettingsAndXmlRendererAgainstSingleFile() { self::changeWorkingDirectory(); $writer = new WriterStub(); $renderer = new XMLRenderer(); $renderer->setWriter($writer); $phpmd = new PHPMD(); $phpmd->processFiles( self::createFileUri('source/ccn_function.php'), 'pmd-refset1', array($renderer), new RuleSetFactory() ); $this->assertXmlEquals($writer->getData(), 'pmd/single-file.xml'); } /** * testHasViolationsReturnsFalseByDefault * * @return void */ public function testHasViolationsReturnsFalseByDefault() { $phpmd = new PHPMD(); $this->assertFalse($phpmd->hasViolations()); } /** * testHasViolationsReturnsFalseForSourceWithoutViolations * * @return void */ public function testHasViolationsReturnsFalseForSourceWithoutViolations() { self::changeWorkingDirectory(); $renderer = new XMLRenderer(); $renderer->setWriter(new WriterStub()); $phpmd = new PHPMD(); $phpmd->processFiles( self::createFileUri('source/source_without_violations.php'), 'pmd-refset1', array($renderer), new RuleSetFactory() ); $this->assertFalse($phpmd->hasViolations()); } /** * testHasViolationsReturnsTrueForSourceWithViolation * * @return void */ public function testHasViolationsReturnsTrueForSourceWithViolation() { self::changeWorkingDirectory(); $renderer = new XMLRenderer(); $renderer->setWriter(new WriterStub()); $phpmd = new PHPMD(); $phpmd->processFiles( self::createFileUri('source/source_with_npath_violation.php'), 'pmd-refset1', array($renderer), new RuleSetFactory() ); $this->assertTrue($phpmd->hasViolations()); } } phpmd-2.8.1/src/test/php/PHPMD/ParserFactoryTest.php000066400000000000000000000121761360164303200222010ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD; /** * Test case for the parser factory class. * * @covers \PHPMD\ParserFactory */ class ParserFactoryTest extends AbstractTest { /** * testFactoryConfiguresInputDirectory * * @return void */ public function testFactoryConfiguresInputDirectory() { $factory = new ParserFactory(); $uri = $this->createFileUri('ParserFactory/Directory'); $phpmd = $this->getMockFromBuilder( $this->getMockBuilder('PHPMD\\PHPMD') ->setMethods(array('getInput')) ); $phpmd->expects($this->once()) ->method('getInput') ->will($this->returnValue($uri)); $ruleSet = $this->getRuleSetMock('PHPMD\\Node\\ClassNode'); $parser = $factory->create($phpmd); $parser->addRuleSet($ruleSet); $parser->parse($this->getReportMock(0)); } /** * testFactoryConfiguresInputFile * * @return void */ public function testFactoryConfiguresInputFile() { $factory = new ParserFactory(); $uri = $this->createFileUri('ParserFactory/File/Test.php'); $phpmd = $this->getMockFromBuilder( $this->getMockBuilder('PHPMD\\PHPMD') ->setMethods(array('getInput')) ); $phpmd->expects($this->once()) ->method('getInput') ->will($this->returnValue($uri)); $ruleSet = $this->getRuleSetMock('PHPMD\\Node\\ClassNode'); $parser = $factory->create($phpmd); $parser->addRuleSet($ruleSet); $parser->parse($this->getReportMock(0)); } /** * testFactoryConfiguresMultipleInputDirectories * * @return void */ public function testFactoryConfiguresMultipleInputDirectories() { $factory = new ParserFactory(); $uri1 = $this->createFileUri('ParserFactory/File'); $uri2 = $this->createFileUri('ParserFactory/Directory'); $phpmd = $this->getMockFromBuilder( $this->getMockBuilder('PHPMD\\PHPMD') ->setMethods(array('getInput')) ); $phpmd->expects($this->once()) ->method('getInput') ->will($this->returnValue($uri1 . ',' . $uri2)); $ruleSet = $this->getRuleSetMock('PHPMD\\Node\\ClassNode', 2); $parser = $factory->create($phpmd); $parser->addRuleSet($ruleSet); $parser->parse($this->getReportMock(0)); } /** * testFactoryConfiguresMultipleInputFilesAndDirectories * * @return void */ public function testFactoryConfiguresMultipleInputFilesAndDirectories() { $factory = new ParserFactory(); $uri1 = $this->createFileUri('ParserFactory/File/Test.php'); $uri2 = $this->createFileUri('ParserFactory/Directory'); $phpmd = $this->getMockFromBuilder($this->getMockBuilder('PHPMD\\PHPMD')->setMethods(array('getInput'))); $phpmd->expects($this->once()) ->method('getInput') ->will($this->returnValue($uri1 . ',' . $uri2)); $ruleSet = $this->getRuleSetMock('PHPMD\\Node\\ClassNode', 2); $parser = $factory->create($phpmd); $parser->addRuleSet($ruleSet); $parser->parse($this->getReportMock(0)); } /** * testFactoryConfiguresIgnorePattern * * @return void */ public function testFactoryConfiguresIgnorePattern() { $factory = new ParserFactory(); $uri = $this->createFileUri('ParserFactory/File/Test.php'); $phpmd = $this->getMockFromBuilder( $this->getMockBuilder('PHPMD\\PHPMD') ->setMethods(array('getIgnorePattern', 'getInput')) ); $phpmd->expects($this->exactly(2)) ->method('getIgnorePattern') ->will($this->returnValue(array('Test'))); $phpmd->expects($this->once()) ->method('getInput') ->will($this->returnValue($uri)); $factory->create($phpmd); } /** * testFactoryConfiguresFileExtensions * * @return void */ public function testFactoryConfiguresFileExtensions() { $factory = new ParserFactory(); $uri = $this->createFileUri('ParserFactory/File/Test.php'); $phpmd = $this->getMockFromBuilder( $this->getMockBuilder('PHPMD\\PHPMD') ->setMethods(array('getFileExtensions', 'getInput')) ); $phpmd->expects($this->exactly(2)) ->method('getFileExtensions') ->will($this->returnValue(array('.php'))); $phpmd->expects($this->once()) ->method('getInput') ->will($this->returnValue($uri)); $factory->create($phpmd); } } phpmd-2.8.1/src/test/php/PHPMD/ParserTest.php000066400000000000000000000174551360164303200206560ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD; use PDepend\Metrics\AnalyzerFactory; use PDepend\Source\Parser\InvalidStateException; use PDepend\Util\Cache\CacheFactory; use PDepend\Util\Configuration; use Symfony\Component\DependencyInjection\Container; /** * Test case for the PHP_Depend backend adapter class. * * @covers \PHPMD\Parser */ class ParserTest extends AbstractTest { /** * Tests that the metrics adapter delegates a node to a registered rule-set. * * @return void */ public function testAdapterDelegatesClassNodeToRuleSet() { $mock = $this->getPHPDependClassMock(); $mock->expects($this->once()) ->method('isUserDefined') ->will($this->returnValue(true)); $adapter = new Parser($this->getPHPDependMock()); $adapter->addRuleSet($this->getRuleSetMock('PHPMD\\Node\\ClassNode')); $adapter->setReport($this->getReportMock(0)); $adapter->visitClass($mock); } /** * Tests that the metrics adapter does not delegate a node without source * code file to a registered rule-set. * * @return void */ public function testAdapterDoesNotDelegateNonSourceClassNodeToRuleSet() { $mock = $this->getPHPDependClassMock(); $mock->expects($this->once()) ->method('isUserDefined') ->will($this->returnValue(false)); $adapter = new Parser($this->getPHPDependMock()); $adapter->addRuleSet($this->getRuleSetMock()); $adapter->setReport($this->getReportMock(0)); $adapter->visitClass($mock); } /** * Tests that the metrics adapter delegates a node to a registered rule-set. * * @return void */ public function testAdapterDelegatesMethodNodeToRuleSet() { $adapter = new Parser($this->getPHPDependMock()); $adapter->addRuleSet($this->getRuleSetMock('PHPMD\\Node\\MethodNode')); $adapter->setReport($this->getReportMock(0)); $adapter->visitMethod($this->getPHPDependMethodMock()); } /** * Tests that the metrics adapter does not delegate a node without source * code file to a registered rule-set. * * @return void */ public function testAdapterDoesNotDelegateNonSourceMethodNodeToRuleSet() { $adapter = new Parser($this->getPHPDependMock()); $adapter->addRuleSet($this->getRuleSetMock()); $adapter->setReport($this->getReportMock(0)); $adapter->visitMethod($this->getPHPDependMethodMock(null)); } /** * Tests that the metrics adapter delegates a node to a registered rule-set. * * @return void */ public function testAdapterDelegatesFunctionNodeToRuleSet() { $adapter = new Parser($this->getPHPDependMock()); $adapter->addRuleSet($this->getRuleSetMock('PHPMD\\Node\\FunctionNode')); $adapter->setReport($this->getReportMock(0)); $adapter->visitFunction($this->getPHPDependFunctionMock()); } /** * Tests that the metrics adapter does not delegate a node without source * code file to a registered rule-set. * * @return void */ public function testAdapterDoesNotDelegateNonSourceFunctionNodeToRuleSet() { $adapter = new Parser($this->getPHPDependMock()); $adapter->addRuleSet($this->getRuleSetMock()); $adapter->setReport($this->getReportMock(0)); $adapter->visitFunction($this->getPHPDependFunctionMock(null)); } /** * testParserStoreParsingExceptionsInReport * * @return void * @since 1.2.1 */ public function testParserStoreParsingExceptionsInReport() { $report = $this->getReportMock(0); $report->expects($this->once()) ->method('addError'); $pdepend = $this->getPHPDependMock(); $pdepend->expects($this->once()) ->method('getExceptions') ->will($this->returnValue(array( new InvalidStateException(42, __FILE__, 'foo') ))); $parser = new Parser($pdepend); $parser->parse($report); } /** * Creates a mocked PDepend instance. * * @return \PDepend\Engine */ private function getPHPDependMock() { $container = new Container(); $config = new Configuration((object) array()); return $this->getMockFromBuilder( $this->getMockBuilder('PDepend\Engine') ->setConstructorArgs(array( $config, new CacheFactory($config), new AnalyzerFactory($container), )) ); } /** * Creates a mocked PDepend class instance. * * @return \PDepend\Source\AST\ASTClass */ protected function getPHPDependClassMock() { $class = $this->getMockFromBuilder( $this->getMockBuilder('PDepend\\Source\\AST\\ASTClass') ->setConstructorArgs(array(null)) ); $class->expects($this->any()) ->method('getCompilationUnit') ->will($this->returnValue($this->getPHPDependFileMock('foo.php'))); $class->expects($this->any()) ->method('getConstants') ->will($this->returnValue(new \ArrayIterator(array()))); $class->expects($this->any()) ->method('getProperties') ->will($this->returnValue(new \ArrayIterator(array()))); $class->expects($this->any()) ->method('getMethods') ->will($this->returnValue(new \ArrayIterator(array()))); return $class; } /** * Creates a mocked PHP_Depend function instance. * * @param string $fileName Optional file name for the source file. * @return PHP_Depend_Code_Function */ protected function getPHPDependFunctionMock($fileName = '/foo/bar.php') { $function = $this->getMockFromBuilder( $this->getMockBuilder('PDepend\Source\AST\ASTFunction') ->setConstructorArgs(array(null)) ); $function->expects($this->atLeastOnce()) ->method('getCompilationUnit') ->will($this->returnValue($this->getPHPDependFileMock($fileName))); return $function; } /** * Creates a mocked PHP_Depend method instance. * * @param string $fileName Optional file name for the source file. * @return PHP_Depend_Code_CodeMethod */ protected function getPHPDependMethodMock($fileName = '/foo/bar.php') { $method = $this->getMockFromBuilder( $this->getMockBuilder('PDepend\Source\AST\ASTMethod') ->setConstructorArgs(array(null)) ); $method->expects($this->atLeastOnce()) ->method('getCompilationUnit') ->will($this->returnValue($this->getPHPDependFileMock($fileName))); return $method; } /** * Creates a mocked PHP_Depend file instance. * * @param string $fileName The temporary file name. * @return PHP_Depend_Code_File */ protected function getPHPDependFileMock($fileName) { $file = $this->getMockFromBuilder( $this->getMockBuilder('PDepend\Source\AST\ASTCompilationUnit') ->setConstructorArgs(array(null)) ); $file->expects($this->any()) ->method('getFileName') ->will($this->returnValue($fileName)); return $file; } } phpmd-2.8.1/src/test/php/PHPMD/ProcessingErrorTest.php000066400000000000000000000042711360164303200225400ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD; /** * Test case for the processing error class. * * @since 1.2.1 * * @covers \PHPMD\ProcessingError */ class ProcessingErrorTest extends AbstractTest { /** * testGetMessageReturnsTheExpectedValue * * @return void */ public function testGetMessageReturnsTheExpectedValue() { $processingError = new ProcessingError('Hello World.'); $this->assertEquals('Hello World.', $processingError->getMessage()); } /** * Tests that the processing error class extracts the source filename from * a given exception message, * * @param string $message The original exception message * @return void * @dataProvider getParserExceptionMessages */ public function testGetFileReturnsExpectedFileName($message) { $processingError = new ProcessingError($message); $this->assertEquals('/tmp/foo.php', $processingError->getFile()); } /** * Data provider that returns common exception messages used by PHP_Depend's * parser. * * @return array */ public function getParserExceptionMessages() { return array( array( 'The parser has reached an invalid state near line "42" in file ' . '"/tmp/foo.php". Please check the following conditions: message' ), array( 'Unexpected token: >, line: 42, col: 23, file: /tmp/foo.php.' ), array( 'Unexpected end of token stream in file: /tmp/foo.php.' ), array( 'Missing default value on line: 42, col: 23, file: /tmp/foo.php.' ) ); } } phpmd-2.8.1/src/test/php/PHPMD/Regression/000077500000000000000000000000001360164303200201555ustar00rootroot00000000000000phpmd-2.8.1/src/test/php/PHPMD/Regression/AbstractTest.php000066400000000000000000000023731360164303200232760ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Regression; /** * Regression test for issue 001. */ abstract class AbstractTest extends \PHPMD\AbstractTest { /** * Creates a full filename for a test content in the _files directory. * * @param string $localPath The local path within the _files dir. * @return string */ protected static function createFileUri($localPath = '') { $trace = debug_backtrace(); $ticket = ''; if (preg_match('(\D(\d+)Test$)', $trace[1]['class'], $match)) { $ticket = $match[1]; } if ($localPath === '') { $localPath = $trace[1]['function'] . '.php'; } return parent::createFileUri('Regression/' . $ticket . '/' . $localPath); } } phpmd-2.8.1/src/test/php/PHPMD/Regression/AcceptsFilesAndDirectoriesAsInputTicket001Test.php000066400000000000000000000033351360164303200316100ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Regression; use PHPMD\PHPMD; use PHPMD\Renderer\XMLRenderer; use PHPMD\RuleSetFactory; use PHPMD\Stubs\WriterStub; /** * Regression test for issue 001. * * @covers \stdClass */ class AcceptsFilesAndDirectoriesAsInputTicket001Test extends AbstractTest { /** * testCliAcceptsDirectoryAsInput * * @return void */ public function testCliAcceptsDirectoryAsInput() { self::changeWorkingDirectory(); $renderer = new XMLRenderer(); $renderer->setWriter(new WriterStub()); $phpmd = new PHPMD(); $phpmd->processFiles( self::createFileUri('source'), 'pmd-refset1', array($renderer), new RuleSetFactory() ); } /** * testCliAcceptsSingleFileAsInput * * @return void */ public function testCliAcceptsSingleFileAsInput() { self::changeWorkingDirectory(); $renderer = new XMLRenderer(); $renderer->setWriter(new WriterStub()); $phpmd = new PHPMD(); $phpmd->processFiles( self::createFileUri('source/FooBar.php'), 'pmd-refset1', array($renderer), new RuleSetFactory() ); } } phpmd-2.8.1/src/test/php/PHPMD/Regression/ExcessivePublicCountRuleNeverExecutedTicket015Test.php000066400000000000000000000023161360164303200325470ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Regression; use PHPMD\Rule\ExcessivePublicCount; use PHPMD\RuleSet; /** * Regression test for issue 015. * * @covers stdClass */ class ExcessivePublicCountRuleNeverExecutedTicket015Test extends AbstractTest { /** * testRuleSetInvokesRuleForClassInstance * * @return void */ public function testRuleSetInvokesRuleForClassInstance() { $rule = new ExcessivePublicCount(); $rule->addProperty('minimum', 3); $class = $this->getClass(); $class->setMetrics(array('cis' => 4)); $ruleSet = new RuleSet(); $ruleSet->addRule($rule); $ruleSet->setReport($this->getReportMock(1)); $ruleSet->apply($class); } } ExcessivePublicCountWorksCorrectlyWithStaticMethodsTest.php000066400000000000000000000103731360164303200340260ustar00rootroot00000000000000phpmd-2.8.1/src/test/php/PHPMD/Regression. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Regression; use PHPMD\PHPMD; use PHPMD\Report; use PHPMD\RuleSetFactory; /** * Regression test for issue 409. * * @link https://github.com/phpmd/phpmd/issues/409 */ class ExcessivePublicCountWorksCorrectlyWithStaticMethodsTest extends AbstractTest { /** * @var string Beginning of the violation message */ const VIOLATION_MESSAGE = 'The class ExcessivePublicCountWorksForPublicStaticMethods has 71 public methods'; /** * @var \PHPUnit_Framework_MockObject_MockObject|\PHPMD\Renderer\TextRenderer */ private $renderer; /** * Sets up the renderer mock */ public function setUp() { $this->renderer = $this->getMockFromBuilder( $this->getMockBuilder('PHPMD\Renderer\TextRenderer') ->disableOriginalConstructor() ->setMethods(array('renderReport', 'start', 'end')) ); } /** * testReportIsGeneratedIWithNoSuppression * * This scenario should trigger at least four violations (in this direction): * - ExcessivePublicCount * - TooManyMethods * - TooManyPublicMethods * - ExcessiveClassComplexity * * @return void */ public function testReportIsGeneratedIWithNoSuppression() { self::changeWorkingDirectory(); $phpmd = new PHPMD(); $self = $this; $this->renderer->expects($this->once()) ->method('renderReport') ->will( $this->returnCallback( function (Report $report) use ($self) { $isViolating = false; foreach ($report->getRuleViolations() as $ruleViolation) { if (strpos($ruleViolation->getDescription(), $self::VIOLATION_MESSAGE) === 0) { $isViolating = true; break; } } $self->assertTrue($isViolating); $self->assertEquals(4, count($report->getRuleViolations())); } ) ); $phpmd->processFiles( __DIR__ . '/Sources/ExcessivePublicCountWorksForPublicStaticMethods.php', 'codesize', array($this->renderer), new RuleSetFactory() ); } /** * testReportIsNotGeneratedIWithSuppression * * This scenario should trigger at least four violations (in this direction): * - TooManyMethods * - TooManyPublicMethods * - ExcessiveClassComplexity * * @return void */ public function testReportIsNotGeneratedIWithSuppression() { self::changeWorkingDirectory(); $phpmd = new PHPMD(); $self = $this; $this->renderer->expects($this->once()) ->method('renderReport') ->will( $this->returnCallback( function (Report $report) use ($self) { $isViolating = false; foreach ($report->getRuleViolations() as $ruleViolation) { if (strpos($ruleViolation->getDescription(), $self::VIOLATION_MESSAGE) === 0) { $isViolating = true; break; } } $self->assertFalse($isViolating); $self->assertEquals(3, count($report->getRuleViolations())); } ) ); $phpmd->processFiles( __DIR__ . '/Sources/ExcessivePublicCountSuppressionWorksForPublicStaticMethods.php', 'codesize', array($this->renderer), new RuleSetFactory() ); } } InvalidUnusedLocalVariableAndFormalParameterTicket007Test.php000066400000000000000000000026351360164303200336700ustar00rootroot00000000000000phpmd-2.8.1/src/test/php/PHPMD/Regression. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Regression; use PHPMD\Rule\UnusedFormalParameter; use PHPMD\Rule\UnusedLocalVariable; /** * Regression test for issue 007. * * @covers stdClass */ class InvalidUnusedLocalVariableAndFormalParameterTicket007Test extends AbstractTest { /** * testLocalVariableUsedInDoubleQuoteStringGetsNotReported * * @return void */ public function testLocalVariableUsedInDoubleQuoteStringGetsNotReported() { $rule = new UnusedLocalVariable(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testFormalParameterUsedInDoubleQuoteStringGetsNotReported * * @return void */ public function testFormalParameterUsedInDoubleQuoteStringGetsNotReported() { $rule = new UnusedFormalParameter(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } } phpmd-2.8.1/src/test/php/PHPMD/Regression/MaximumNestingLevelTicket24975295Test.php000066400000000000000000000027221360164303200275050ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Regression; use PHPMD\PHPMD; use PHPMD\Renderer\TextRenderer; use PHPMD\RuleSetFactory; use PHPMD\Writer\StreamWriter; /** * Regression test for issue 14990109. * * @link https://www.pivotaltracker.com/story/show/24975295 * @since 1.3.1 * * @covers \stdClass */ class MaximumNestingLevelTicket24975295Test extends AbstractTest { /** * testLocalVariableUsedInDoubleQuoteStringGetsNotReported * * @return void * @outputBuffering enabled */ public function testLocalVariableUsedInDoubleQuoteStringGetsNotReported() { $renderer = new TextRenderer(); $renderer->setWriter(new StreamWriter(self::createTempFileUri())); $inputs = self::createCodeResourceUriForTest(); $rules = 'unusedcode'; $renderes = array($renderer); $factory = new RuleSetFactory(); $phpmd = new PHPMD(); $phpmd->processFiles($inputs, $rules, $renderes, $factory); } } phpmd-2.8.1/src/test/php/PHPMD/Regression/Sources/000077500000000000000000000000001360164303200216005ustar00rootroot00000000000000ExcessivePublicCountSuppressionWorksForPublicStaticMethods.php000066400000000000000000000102531360164303200361440ustar00rootroot00000000000000phpmd-2.8.1/src/test/php/PHPMD/Regression/Sources. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Regression\Sources; /** * @SuppressWarnings(PHPMD.ExcessivePublicCount) */ class ExcessivePublicCountSuppressionWorksForPublicStaticMethods { public static function aMethod() { } public static function bMethod() { } public static function cMethod() { } public static function dMethod() { } public static function eMethod() { } public static function fMethod() { } public static function gMethod() { } public static function hMethod() { } public static function iMethod() { } public static function jMethod() { } public static function kMethod() { } public static function lMethod() { } public static function mMethod() { } public static function nMethod() { } public static function oMethod() { } public static function pMethod() { } public static function rMethod() { } public static function sMethod() { } public static function tMethod() { } public static function uMethod() { } public static function wMethod() { } public static function xMethod() { } public static function yMethod() { } public static function zMethod() { } public static function aaMethod() { } public static function abMethod() { } public static function acMethod() { } public static function adMethod() { } public static function aeMethod() { } public static function afMethod() { } public static function agMethod() { } public static function ahMethod() { } public static function ajMethod() { } public static function akMethod() { } public static function alMethod() { } public static function amMethod() { } public static function anMethod() { } public static function aoMethod() { } public static function apMethod() { } public static function arMethod() { } public static function asMethod() { } public static function atMethod() { } public static function auMethod() { } public static function awMethod() { } public static function axMethod() { } public static function ayMethod() { } public static function azMethod() { } public static function baMethod() { } public static function bbMethod() { } public static function bcMethod() { } public static function bdMethod() { } public static function beMethod() { } public static function bfMethod() { } public static function bgMethod() { } public static function bhMethod() { } public static function biMethod() { } public static function bjMethod() { } public static function bkMethod() { } public static function blmethod() { } public static function bmmethod() { } public static function bnMethod() { } public static function boMethod() { } public static function bpMethod() { } public static function brMethod() { } public static function bsMethod() { } public static function btMethod() { } public static function buMethod() { } public static function bwMethod() { } public static function bxMethod() { } public static function byMethod() { } public static function bzMethod() { } } ExcessivePublicCountWorksForPublicStaticMethods.php000066400000000000000000000101471360164303200336730ustar00rootroot00000000000000phpmd-2.8.1/src/test/php/PHPMD/Regression/Sources. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Regression\Sources; class ExcessivePublicCountWorksForPublicStaticMethods { public static function aMethod() { } public static function bMethod() { } public static function cMethod() { } public static function dMethod() { } public static function eMethod() { } public static function fMethod() { } public static function gMethod() { } public static function hMethod() { } public static function iMethod() { } public static function jMethod() { } public static function kMethod() { } public static function lMethod() { } public static function mMethod() { } public static function nMethod() { } public static function oMethod() { } public static function pMethod() { } public static function rMethod() { } public static function sMethod() { } public static function tMethod() { } public static function uMethod() { } public static function wMethod() { } public static function xMethod() { } public static function yMethod() { } public static function zMethod() { } public static function aaMethod() { } public static function abMethod() { } public static function acMethod() { } public static function adMethod() { } public static function aeMethod() { } public static function afMethod() { } public static function agMethod() { } public static function ahMethod() { } public static function ajMethod() { } public static function akMethod() { } public static function alMethod() { } public static function amMethod() { } public static function anMethod() { } public static function aoMethod() { } public static function apMethod() { } public static function arMethod() { } public static function asMethod() { } public static function atMethod() { } public static function auMethod() { } public static function awMethod() { } public static function axMethod() { } public static function ayMethod() { } public static function azMethod() { } public static function baMethod() { } public static function bbMethod() { } public static function bcMethod() { } public static function bdMethod() { } public static function beMethod() { } public static function bfMethod() { } public static function bgMethod() { } public static function bhMethod() { } public static function biMethod() { } public static function bjMethod() { } public static function bkMethod() { } public static function blmethod() { } public static function bmmethod() { } public static function bnMethod() { } public static function boMethod() { } public static function bpMethod() { } public static function brMethod() { } public static function bsMethod() { } public static function btMethod() { } public static function buMethod() { } public static function bwMethod() { } public static function bxMethod() { } public static function byMethod() { } public static function bzMethod() { } } phpmd-2.8.1/src/test/php/PHPMD/Regression/StaticVariablesFlaggedAsUnusedTicket020Test.php000066400000000000000000000020011360164303200311070ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Regression; use PHPMD\Rule\UnusedLocalVariable; /** * Regression test for issue 020. * * @covers \stdClass */ class StaticVariablesFlaggedAsUnusedTicket020Test extends AbstractTest { /** * testRuleDoesNotApplyToAnySuperGlobalVariable * * @return void */ public function testRuleDoesNotApplyToAnyStaticLocalVariable() { $rule = new UnusedLocalVariable(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } } phpmd-2.8.1/src/test/php/PHPMD/Regression/SuperGlobalsFlaggedAsUnusedTicket019Test.php000066400000000000000000000017761360164303200304630ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Regression; use PHPMD\Rule\UnusedLocalVariable; /** * Regression test for issue 019. * * @covers \stdClass */ class SuperGlobalsFlaggedAsUnusedTicket019Test extends AbstractTest { /** * testRuleDoesNotApplyToAnySuperGlobalVariable * * @return void */ public function testRuleDoesNotApplyToAnySuperGlobalVariable() { $rule = new UnusedLocalVariable(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } } phpmd-2.8.1/src/test/php/PHPMD/Regression/SuppressWarningsNotAppliesToUnusedPrivateMethod036Test.php000066400000000000000000000021731360164303200335010ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Regression; use PHPMD\Rule\UnusedPrivateMethod; use PHPMD\RuleSet; /** * Regression test for issue 036. * * @covers stdClass */ class SuppressWarningsNotAppliesToUnusedPrivateMethod036Test extends AbstractTest { /** * testRuleDoesNotApplyToPrivateMethodWithSuppressWarningsAnnotation * * @return void */ public function testRuleDoesNotApplyToPrivateMethodWithSuppressWarningsAnnotation() { $ruleSet = new RuleSet(); $ruleSet->addRule(new UnusedPrivateMethod()); $ruleSet->setReport($this->getReportMock(0)); $ruleSet->apply($this->getClass()); } } phpmd-2.8.1/src/test/php/PHPMD/Regression/UnusedParameterArgvTicket14990109Test.php000066400000000000000000000030401360164303200274540ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Regression; use PHPMD\Rule\UnusedFormalParameter; use PHPMD\RuleSet; /** * Regression test for issue 14990109. * * @link https://www.pivotaltracker.com/story/show/14990109 * @since 1.1.0 * * @covers \stdClass */ class UnusedParameterArgvTicket14990109Test extends AbstractTest { /** * testRuleDoesNotApplyToFunctionParameterNamedArgv * * @return void */ public function testRuleDoesNotApplyToFunctionParameterNamedArgv() { $ruleSet = new RuleSet(); $ruleSet->addRule(new UnusedFormalParameter()); $ruleSet->setReport($this->getReportMock(0)); $ruleSet->apply($this->getFunction()); } /** * testRuleDoesNotApplyToMethodParameterNamedArgv * * @return void */ public function testRuleDoesNotApplyToMethodParameterNamedArgv() { $ruleSet = new RuleSet(); $ruleSet->addRule(new UnusedFormalParameter()); $ruleSet->setReport($this->getReportMock(0)); $ruleSet->apply($this->getMethod()); } } phpmd-2.8.1/src/test/php/PHPMD/Renderer/000077500000000000000000000000001360164303200176035ustar00rootroot00000000000000phpmd-2.8.1/src/test/php/PHPMD/Renderer/AnsiRendererTest.php000066400000000000000000000111171360164303200235360ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Renderer; use PHPMD\AbstractTest; use PHPMD\Stubs\WriterStub; /** * Test case for the ansi renderer implementation. * * @covers \PHPMD\Renderer\AnsiRendererTest */ class AnsiRendererTest extends AbstractTest { /** * testRendererOutputsForReportWithContents * * @return void */ public function testRendererOutputsForReportWithContents() { $writer = new WriterStub(); $violations = array( $this->getRuleViolationMock('/bar.php', 1), $this->getRuleViolationMock('/foo.php', 2), $this->getRuleViolationMock('/foo.php', 3), ); $errors = array( $this->getErrorMock(), ); $report = $this->getReportMock(0); $report->expects($this->atLeastOnce()) ->method('getRuleViolations') ->will($this->returnValue(new \ArrayIterator($violations))); $report->expects($this->atLeastOnce()) ->method('isEmpty') ->will($this->returnValue(false)); $report->expects($this->atLeastOnce()) ->method('hasErrors') ->will($this->returnValue(true)); $report->expects($this->atLeastOnce()) ->method('getErrors') ->will($this->returnValue(new \ArrayIterator($errors))); $report->expects($this->once()) ->method('getElapsedTimeInMillis') ->will($this->returnValue(200)); $renderer = new AnsiRenderer(); $renderer->setWriter($writer); $renderer->start(); $renderer->renderReport($report); $renderer->end(); $expectedChunks = array( PHP_EOL . "FILE: /bar.php" . PHP_EOL . "--------------" . PHP_EOL, " 1 | \e[31mVIOLATION\e[0m | Test description" . PHP_EOL, PHP_EOL . "FILE: /foo.php" . PHP_EOL . "--------------" . PHP_EOL, " 2 | \e[31mVIOLATION\e[0m | Test description" . PHP_EOL, " 3 | \e[31mVIOLATION\e[0m | Test description" . PHP_EOL, PHP_EOL . "\e[33mERROR\e[0m while parsing /foo/baz.php" . PHP_EOL . "--------------------------------" . (version_compare(PHP_VERSION, '5.4.0-dev', '<') ? '--' : '') . PHP_EOL, "Error in file \"/foo/baz.php\"" . PHP_EOL, PHP_EOL . "Found 3 violations and 1 error in 200ms" . PHP_EOL, ); foreach($writer->getChunks() as $i => $chunk) { $this->assertEquals( $expectedChunks[$i], $chunk, sprintf('Chunk %s did not match expected string', $i) ); } } /** * testRendererOutputsForReportWithoutContents * * @return void */ public function testRendererOutputsForReportWithoutContents() { $writer = new WriterStub(); $report = $this->getReportMock(0); $report->expects($this->atLeastOnce()) ->method('getRuleViolations') ->will($this->returnValue(new \ArrayIterator(array()))); $report->expects($this->atLeastOnce()) ->method('isEmpty') ->will($this->returnValue(true)); $report->expects($this->atLeastOnce()) ->method('hasErrors') ->will($this->returnValue(false)); $report->expects($this->atLeastOnce()) ->method('getErrors') ->will($this->returnValue(new \ArrayIterator(array()))); $report->expects($this->once()) ->method('getElapsedTimeInMillis') ->will($this->returnValue(200)); $renderer = new AnsiRenderer(); $renderer->setWriter($writer); $renderer->start(); $renderer->renderReport($report); $renderer->end(); $expectedChunks = array( PHP_EOL . "Found 0 violations and 0 errors in 200ms" . PHP_EOL, PHP_EOL . "\e[32mNo mess detected\e[0m" . PHP_EOL, ); foreach($writer->getChunks() as $i => $chunk) { $this->assertEquals( $expectedChunks[$i], $chunk, sprintf('Chunk %s did not match expected string', $i) ); } } } phpmd-2.8.1/src/test/php/PHPMD/Renderer/HTMLRendererTest.php000066400000000000000000000064241360164303200234150ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Renderer; use PHPMD\AbstractTest; use PHPMD\ProcessingError; use PHPMD\Stubs\WriterStub; /** * Test case for the html renderer implementation. * * @covers \PHPMD\Renderer\HTMLRenderer */ class HTMLRendererTest extends AbstractTest { /** * testRendererCreatesExpectedNumberOfTextEntries * * @return void */ public function testRendererCreatesExpectedHtmlTableRow() { // Create a writer instance. $writer = new WriterStub(); $violations = array( $this->getRuleViolationMock('/bar.php', 1), $this->getRuleViolationMock('/foo.php', 2), $this->getRuleViolationMock('/foo.php', 3), ); $report = $this->getReportMock(0); $report->expects($this->once()) ->method('getRuleViolations') ->will($this->returnValue(new \ArrayIterator($violations))); $report->expects($this->once()) ->method('getErrors') ->will($this->returnValue(new \ArrayIterator(array()))); $renderer = new HTMLRenderer(); $renderer->setWriter($writer); $renderer->start(); $renderer->renderReport($report); $renderer->end(); $this->assertContains( '' . PHP_EOL . '2' . PHP_EOL . '/foo.php' . PHP_EOL . '2' . PHP_EOL . 'Test description' . PHP_EOL . '', $writer->getData() ); } /** * testRendererAddsProcessingErrorsToHtmlReport * * @return void */ public function testRendererAddsProcessingErrorsToHtmlReport() { // Create a writer instance. $writer = new WriterStub(); $errors = array( new ProcessingError('Failed for file "/tmp/foo.php".'), new ProcessingError('Failed for file "/tmp/bar.php".'), new ProcessingError('Failed for file "/tmp/baz.php".'), ); $report = $this->getReportMock(0); $report->expects($this->once()) ->method('getRuleViolations') ->will($this->returnValue(new \ArrayIterator(array()))); $report->expects($this->once()) ->method('getErrors') ->will($this->returnValue(new \ArrayIterator($errors))); $renderer = new HTMLRenderer(); $renderer->setWriter($writer); $renderer->start(); $renderer->renderReport($report); $renderer->end(); $this->assertContains( '' . '/tmp/bar.php' . 'Failed for file "/tmp/bar.php".' . '', $writer->getData() ); } } phpmd-2.8.1/src/test/php/PHPMD/Renderer/JSONRendererTest.php000066400000000000000000000060261360164303200234200ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Renderer; use PHPMD\AbstractTest; use PHPMD\ProcessingError; use PHPMD\Stubs\WriterStub; /** * Test case for the JSON renderer implementation. * * @covers \PHPMD\Renderer\JSONRenderer */ class JSONRendererTest extends AbstractTest { /** * testRendererCreatesExpectedNumberOfJsonElements * * @return void */ public function testRendererCreatesExpectedNumberOfJsonElements() { $writer = new WriterStub(); $violations = array( $this->getRuleViolationMock('/bar.php'), $this->getRuleViolationMock('/foo.php'), $this->getRuleViolationMock('/bar.php'), // TODO Set with description "foo getReportMock(0); $report->expects($this->once()) ->method('getRuleViolations') ->will($this->returnValue(new \ArrayIterator($violations))); $report->expects($this->once()) ->method('getErrors') ->will($this->returnValue(new \ArrayIterator(array()))); $renderer = new JSONRenderer(); $renderer->setWriter($writer); $renderer->start(); $renderer->renderReport($report); $renderer->end(); $this->assertJsonEquals( $writer->getData(), 'renderer/json_renderer_expected.json' ); } /** * testRendererAddsProcessingErrorsToJsonReport * * @return void */ public function testRendererAddsProcessingErrorsToJsonReport() { $writer = new WriterStub(); $processingErrors = array( new ProcessingError('Failed for file "/tmp/foo.php".'), new ProcessingError('Failed for file "/tmp/bar.php".'), new ProcessingError('Failed for file "/tmp/baz.php".'), new ProcessingError('Cannot read file "/tmp/foo.php". Permission denied.'), ); $report = $this->getReportMock(0); $report->expects($this->once()) ->method('getRuleViolations') ->will($this->returnValue(new \ArrayIterator(array()))); $report->expects($this->once()) ->method('getErrors') ->will($this->returnValue(new \ArrayIterator($processingErrors))); $renderer = new JSONRenderer(); $renderer->setWriter($writer); $renderer->start(); $renderer->renderReport($report); $renderer->end(); $this->assertJsonEquals( $writer->getData(), 'renderer/json_renderer_processing_errors.json' ); } } phpmd-2.8.1/src/test/php/PHPMD/Renderer/TextRendererTest.php000066400000000000000000000063261360164303200235760ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Renderer; use PHPMD\AbstractTest; use PHPMD\ProcessingError; use PHPMD\Stubs\WriterStub; /** * Test case for the text renderer implementation. * * @covers \PHPMD\Renderer\TextRenderer */ class TextRendererTest extends AbstractTest { /** * testRendererCreatesExpectedNumberOfTextEntries * * @return void */ public function testRendererCreatesExpectedNumberOfTextEntries() { // Create a writer instance. $writer = new WriterStub(); $violations = array( $this->getRuleViolationMock('/bar.php', 1), $this->getRuleViolationMock('/foo.php', 2), $this->getRuleViolationMock('/foo.php', 3), ); $report = $this->getReportMock(0); $report->expects($this->once()) ->method('getRuleViolations') ->will($this->returnValue(new \ArrayIterator($violations))); $report->expects($this->once()) ->method('getErrors') ->will($this->returnValue(new \ArrayIterator(array()))); $renderer = new TextRenderer(); $renderer->setWriter($writer); $renderer->start(); $renderer->renderReport($report); $renderer->end(); $this->assertEquals( "/bar.php:1\tTest description" . PHP_EOL . "/foo.php:2\tTest description" . PHP_EOL . "/foo.php:3\tTest description" . PHP_EOL, $writer->getData() ); } /** * testRendererAddsProcessingErrorsToTextReport * * @return void */ public function testRendererAddsProcessingErrorsToTextReport() { // Create a writer instance. $writer = new WriterStub(); $errors = array( new ProcessingError('Failed for file "/tmp/foo.php".'), new ProcessingError('Failed for file "/tmp/bar.php".'), new ProcessingError('Failed for file "/tmp/baz.php".'), ); $report = $this->getReportMock(0); $report->expects($this->once()) ->method('getRuleViolations') ->will($this->returnValue(new \ArrayIterator(array()))); $report->expects($this->once()) ->method('getErrors') ->will($this->returnValue(new \ArrayIterator($errors))); $renderer = new TextRenderer(); $renderer->setWriter($writer); $renderer->start(); $renderer->renderReport($report); $renderer->end(); $this->assertEquals( "/tmp/foo.php\t-\tFailed for file \"/tmp/foo.php\"." . PHP_EOL . "/tmp/bar.php\t-\tFailed for file \"/tmp/bar.php\"." . PHP_EOL . "/tmp/baz.php\t-\tFailed for file \"/tmp/baz.php\"." . PHP_EOL, $writer->getData() ); } } phpmd-2.8.1/src/test/php/PHPMD/Renderer/XMLRendererTest.php000066400000000000000000000057671360164303200233220ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Renderer; use PHPMD\AbstractTest; use PHPMD\ProcessingError; use PHPMD\Stubs\WriterStub; /** * Test case for the xml renderer implementation. * * @covers \PHPMD\Renderer\XMLRenderer */ class XMLRendererTest extends AbstractTest { /** * testRendererCreatesExpectedNumberOfXmlElements * * @return void */ public function testRendererCreatesExpectedNumberOfXmlElements() { // Create a writer instance. $writer = new WriterStub(); $violations = array( $this->getRuleViolationMock('/bar.php'), $this->getRuleViolationMock('/foo.php'), $this->getRuleViolationMock('/foo.php', 23, 42, null, 'foo getReportMock(0); $report->expects($this->once()) ->method('getRuleViolations') ->will($this->returnValue(new \ArrayIterator($violations))); $report->expects($this->once()) ->method('getErrors') ->will($this->returnValue(new \ArrayIterator(array()))); $renderer = new XMLRenderer(); $renderer->setWriter($writer); $renderer->start(); $renderer->renderReport($report); $renderer->end(); $this->assertXmlEquals( $writer->getData(), 'renderer/xml_renderer_expected1.xml' ); } /** * testRendererAddsProcessingErrorsToXmlReport * * @return void * @since 1.2.1 */ public function testRendererAddsProcessingErrorsToXmlReport() { // Create a writer instance. $writer = new WriterStub(); $processingErrors = array( new ProcessingError('Failed for file "/tmp/foo.php".'), new ProcessingError('Failed for file "/tmp/bar.php".'), new ProcessingError('Failed for file "/tmp/baz.php".'), ); $report = $this->getReportMock(0); $report->expects($this->once()) ->method('getRuleViolations') ->will($this->returnValue(new \ArrayIterator(array()))); $report->expects($this->once()) ->method('getErrors') ->will($this->returnValue(new \ArrayIterator($processingErrors))); $renderer = new XMLRenderer(); $renderer->setWriter($writer); $renderer->start(); $renderer->renderReport($report); $renderer->end(); $this->assertXmlEquals( $writer->getData(), 'renderer/xml_renderer_processing_errors.xml' ); } } phpmd-2.8.1/src/test/php/PHPMD/ReportTest.php000066400000000000000000000124541360164303200206670ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD; /** * Test case for the report class. * * @covers \PHPMD\Report */ class ReportTest extends AbstractTest { /** * Tests that the report returns a linear/sorted list of all rule violation * files. * * @return void */ public function testReportReturnsAListWithAllRuleViolations() { $report = new Report(); $report->addRuleViolation($this->getRuleViolationMock('foo.txt')); $report->addRuleViolation($this->getRuleViolationMock('bar.txt')); $report->addRuleViolation($this->getRuleViolationMock('foo.txt')); $report->addRuleViolation($this->getRuleViolationMock('foo.txt')); $report->addRuleViolation($this->getRuleViolationMock('bar.txt')); $actual = array(); foreach ($report->getRuleViolations() as $violation) { $actual[] = $violation->getFileName(); } $expected = array('bar.txt', 'bar.txt', 'foo.txt', 'foo.txt', 'foo.txt'); $this->assertSame($expected, $actual); } /** * Tests that the report returns the result by the violation line number. * * @return void */ public function testReportSortsResultByLineNumber() { $report = new Report(); $report->addRuleViolation($this->getRuleViolationMock('foo.txt', 4, 5)); $report->addRuleViolation($this->getRuleViolationMock('foo.txt', 1, 2)); $report->addRuleViolation($this->getRuleViolationMock('foo.txt', 3, 6)); $report->addRuleViolation($this->getRuleViolationMock('foo.txt', 2, 3)); $report->addRuleViolation($this->getRuleViolationMock('bar.txt', 2, 3)); $report->addRuleViolation($this->getRuleViolationMock('bar.txt', 1, 2)); $actual = array(); foreach ($report->getRuleViolations() as $violation) { $actual[] = array($violation->getFileName(), $violation->getBeginLine(), $violation->getEndLine()); } $expected = array( array('bar.txt', 1, 2), array('bar.txt', 2, 3), array('foo.txt', 1, 2), array('foo.txt', 2, 3), array('foo.txt', 3, 6), array('foo.txt', 4, 5), ); $this->assertSame($expected, $actual); } /** * Tests that the timer method returns the expected result. * * @return void */ public function testReportTimerReturnsMilliSeconds() { $start = microtime(true); $report = new Report(); $report->start(); usleep(50000); // 50 Milli Seconds $report->end(); $time = ceil((microtime(true) - $start) * 1000.0); // Windows does not compute the time correctly, simply skipping if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { $this->assertGreaterThanOrEqual(50, $report->getElapsedTimeInMillis()); } $this->assertLessThanOrEqual($time, $report->getElapsedTimeInMillis()); } /** * testIsEmptyReturnsTrueByDefault * * @return void */ public function testIsEmptyReturnsTrueByDefault() { $report = new Report(); $this->assertTrue($report->isEmpty()); } /** * testIsEmptyReturnsFalseWhenAtLeastOneViolationExists * * @return void */ public function testIsEmptyReturnsFalseWhenAtLeastOneViolationExists() { $report = new Report(); $report->addRuleViolation($this->getRuleViolationMock('foo.txt', 4, 5)); $this->assertFalse($report->isEmpty()); } /** * testHasErrorsReturnsFalseByDefault * * @return void * @since 1.2.1 */ public function testHasErrorsReturnsFalseByDefault() { $report = new Report(); $this->assertFalse($report->hasErrors()); } /** * testHasErrorsReturnsTrueWhenReportContainsAtLeastOneError * * @return void * @since 1.2.1 */ public function testHasErrorsReturnsTrueWhenReportContainsAtLeastOneError() { $report = new Report(); $report->addError(new ProcessingError('Failing file "/foo.php".')); $this->assertTrue($report->hasErrors()); } /** * testGetErrorsReturnsEmptyIteratorByDefault * * @return void * @since 1.2.1 */ public function testGetErrorsReturnsEmptyIteratorByDefault() { $report = new Report(); $this->assertSame(0, iterator_count($report->getErrors())); } /** * testGetErrorsReturnsPreviousAddedProcessingError * * @return void * @since 1.2.1 */ public function testGetErrorsReturnsPreviousAddedProcessingError() { $report = new Report(); $report->addError(new ProcessingError('Failing file "/foo.php".')); $this->assertSame(1, iterator_count($report->getErrors())); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/000077500000000000000000000000001360164303200167445ustar00rootroot00000000000000phpmd-2.8.1/src/test/php/PHPMD/Rule/CleanCode/000077500000000000000000000000001360164303200205615ustar00rootroot00000000000000phpmd-2.8.1/src/test/php/PHPMD/Rule/CleanCode/DuplicatedArrayKeyTest.php000066400000000000000000000153021360164303200256610ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\CleanCode; use PHPMD\AbstractTest; /** * Duplicated Array Key Test. * * @author Rafał Wrzeszcz * @author Kamil Szymanaski */ class DuplicatedArrayKeyTest extends AbstractTest { /** * testRuleNotAppliesToMethodWithoutArrayDefinition * * @return void */ public function testRuleNotAppliesToMethodWithoutArrayDefinition() { $rule = new DuplicatedArrayKey(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleNotAppliesToMethodWithNonAssotiativeArrayDefinition * * @return void */ public function testRuleNotAppliesToMethodWithNonAssotiativeArrayDefinition() { $rule = new DuplicatedArrayKey(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleNotAppliesToMethodWithAssotiativeArrayDefinitionWithoutDuplicatedKeys * * @return void */ public function testRuleNotAppliesToMethodWithAssotiativeArrayDefinitionWithoutDuplicatedKeys() { $rule = new DuplicatedArrayKey(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleAppliesToMethodWithAssotiativeArrayDefinitionWithDuplicatedKeys * * @return void */ public function testRuleAppliesToMethodWithAssotiativeArrayDefinitionWithDuplicatedKeys() { $rule = new DuplicatedArrayKey(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getMethod()); } /** * testRuleAppliesToMethodWithAssotiativeArrayDefinitionWithDuplicatedMixedTypeKeys * * @return void */ public function testRuleAppliesToMethodWithAssotiativeArrayDefinitionWithDuplicatedMixedTypeKeys() { $rule = new DuplicatedArrayKey(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getMethod()); } /** * testRuleAppliesToMethodWithAssotiativeArrayDefinitionWithDuplicatedMixedQuotedKeys * * @return void */ public function testRuleAppliesToMethodWithAssotiativeArrayDefinitionWithDuplicatedMixedQuotedKeys() { $rule = new DuplicatedArrayKey(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getMethod()); } /** * testRuleAppliesMultipleTimesToMethodWithAssotiativeArrayDefinitionWithDuplicatedKeys * * @return void */ public function testRuleAppliesMultipleTimesToMethodWithAssotiativeArrayDefinitionWithDuplicatedKeys() { $rule = new DuplicatedArrayKey(); $rule->setReport($this->getReportMock(3)); $rule->apply($this->getMethod()); } /** * testRuleNotAppliesToFunctionWithoutArrayDefinition * * @return void */ public function testRuleNotAppliesToFunctionWithoutArrayDefinition() { $rule = new DuplicatedArrayKey(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getFunction()); } /** * testRuleNotAppliesToFunctionWithNonAssotiativeArrayDefinition * * @return void */ public function testRuleNotAppliesToFunctionWithNonAssotiativeArrayDefinition() { $rule = new DuplicatedArrayKey(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getFunction()); } /** * testRuleNotAppliesToFunctionWithAssotiativeArrayDefinitionWithoutDuplicatedKeys * * @return void */ public function testRuleNotAppliesToFunctionWithAssotiativeArrayDefinitionWithoutDuplicatedKeys() { $rule = new DuplicatedArrayKey(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getFunction()); } /** * testRuleAppliesToFunctionWithAssotiativeArrayDefinitionWithDuplicatedKeys * * @return void */ public function testRuleAppliesToFunctionWithAssotiativeArrayDefinitionWithDuplicatedKeys() { $rule = new DuplicatedArrayKey(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getFunction()); } /** * testRuleAppliesToFunctionWithAssotiativeArrayDefinitionWithDuplicatedMixedTypeKeys * * @return void */ public function testRuleAppliesToFunctionWithAssotiativeArrayDefinitionWithDuplicatedMixedTypeKeys() { $rule = new DuplicatedArrayKey(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getFunction()); } /** * testRuleAppliesToFunctionWithAssotiativeArrayDefinitionWithDuplicatedMixedQuotedKeys * * @return void */ public function testRuleAppliesToFunctionWithAssotiativeArrayDefinitionWithDuplicatedMixedQuotedKeys() { $rule = new DuplicatedArrayKey(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getFunction()); } /** * testRuleAppliesMultipleTimesToFunctionWithAssotiativeArrayDefinitionWithDuplicatedKeys * * @return void */ public function testRuleAppliesMultipleTimesToFunctionWithAssotiativeArrayDefinitionWithDuplicatedKeys() { $rule = new DuplicatedArrayKey(); $rule->setReport($this->getReportMock(3)); $rule->apply($this->getFunction()); } /** * testRuleAppliesWhenKeyIsDeclaredInNonStandardWay * * @return void */ public function testRuleAppliesWhenKeyIsDeclaredInNonStandardWay() { $rule = new DuplicatedArrayKey(); $rule->setReport($this->getReportMock(4)); $rule->apply($this->getMethod()); } /** * testRuleAppliesCorrectlyWithNestedArrays * * @return void */ public function testRuleAppliesCorrectlyWithNestedArrays() { $rule = new DuplicatedArrayKey(); $rule->setReport($this->getReportMock(4)); $rule->apply($this->getFunction()); } /** * testRuleAppliesCorrectlyToMultipleArrays * * @return void */ public function testRuleAppliesCorrectlyToMultipleArrays() { $rule = new DuplicatedArrayKey(); $rule->setReport($this->getReportMock(4)); $rule->apply($this->getFunction()); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/CleanCode/ElseExpressionTest.php000066400000000000000000000023631360164303200251060ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\CleanCode; use PHPMD\AbstractTest; class ElseExpressionTest extends AbstractTest { public function testRuleNotAppliesToMethodWithoutElseExpression() { $rule = new ElseExpression(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } public function testRuleAppliesToMethodWithElseExpression() { $rule = new ElseExpression(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getMethod()); } public function testRuleAppliesMultipleTimesToMethodWithMultipleElseExpressions() { $rule = new ElseExpression(); $rule->setReport($this->getReportMock(3)); $rule->apply($this->getMethod()); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/CleanCode/IfStatementAssignmentTest.php000066400000000000000000000052761360164303200264200ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\CleanCode; use PHPMD\AbstractTest; class IfStatementAssignmentTest extends AbstractTest { public function testRuleNotAppliesInsideClosure() { $rule = new IfStatementAssignment(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } public function testRuleNotAppliesInsideClosureCallbacks() { $rule = new IfStatementAssignment(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } public function testRuleNotAppliesToIfsWithoutAssignment() { $rule = new IfStatementAssignment(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } public function testRuleNotAppliesToIfsWithConditionsOnly() { $rule = new IfStatementAssignment(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } public function testRuleNotAppliesToLogicalOperators() { $rule = new IfStatementAssignment(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } public function testRuleWorksCorrectlyWhenExpressionContainsMath() { $rule = new IfStatementAssignment(); $rule->setReport($this->getReportMock(3)); $rule->apply($this->getMethod()); } public function testRuleAppliesToFunctions() { $rule = new IfStatementAssignment(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getFunction()); } public function testRuleAppliesMultipleIfConditions() { $rule = new IfStatementAssignment(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getFunction()); } public function testRuleAppliesToMultilevelIfConditions() { $rule = new IfStatementAssignment(); $rule->setReport($this->getReportMock(6)); $rule->apply($this->getFunction()); } public function testRuleAppliesMultipleTimesInOneIfCondition() { $rule = new IfStatementAssignment(); $rule->setReport($this->getReportMock(3)); $rule->apply($this->getFunction()); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/CleanCode/MissingImportTest.php000066400000000000000000000065041360164303200247430ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\CleanCode; use PHPMD\AbstractTest; /** * MissingImport Tests * * @coversDefaultClass \PHPMD\Rule\CleanCode\MissingImport */ class MissingImportTest extends AbstractTest { /** * Tests that it does not apply to a class without any class dependencies * * @return void * @covers ::apply */ public function testRuleNotAppliesToClassWithoutAnyDependencies() { $rule = new MissingImport(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * Tests that it does not apply to a class with only imported classes * * @return void * @covers ::apply * @covers ::isSelfReference */ public function testRuleNotAppliesToClassWithOnlyImportedDependencies() { $rule = new MissingImport(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * Tests that it applies to a class that has fully qualified class names * * @return void * @covers ::apply * @covers ::isSelfReference */ public function testRuleAppliesToClassWithNotImportedDependencies() { $rule = new MissingImport(); $rule->setReport($this->getReportMock(2)); $rule->apply($this->getMethod()); } /** * Tests that it does not apply to a class that uses self references * * @return void * @covers ::apply * @covers ::isSelfReference */ public function testRuleNotAppliesToClassWithSelfAndStaticCalls() { $rule = new MissingImport(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * Tests that it does not apply to a function without any class dependencies * * @return void * @covers ::apply */ public function testRuleNotAppliesToFunctionWithoutAnyDependencies() { $rule = new MissingImport(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getFunction()); } /** * Tests that it does not apply to a function with only imported classes * * @return void * @covers ::apply * @covers ::isSelfReference */ public function testRuleNotAppliesToFunctionWithOnlyImportedDependencies() { $rule = new MissingImport(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getFunction()); } /** * Tests that it applies to a function that has fully qualified class names * * @return void * @covers ::apply * @covers ::isSelfReference */ public function testRuleAppliesToFunctionWithNotImportedDependencies() { $rule = new MissingImport(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getFunction()); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/CleanCode/StaticAccessTest.php000066400000000000000000000041661360164303200245120ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\CleanCode; use PHPMD\AbstractTest; class StaticAccessTest extends AbstractTest { public function testRuleNotAppliesToParentStaticCall() { $rule = new StaticAccess(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } public function testRuleNotAppliesToSelfStaticCall() { $rule = new StaticAccess(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } public function testRuleNotAppliesToDynamicMethodCall() { $rule = new StaticAccess(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } public function testRuleNotAppliesToStaticMethodAccessWhenExcluded() { $rule = new StaticAccess(); $rule->setReport($this->getReportMock(0)); $rule->addProperty('exceptions', 'Excluded1,Excluded2'); $rule->apply($this->getMethod()); } public function testRuleAppliesToStaticMethodAccess() { $rule = new StaticAccess(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getMethod()); } public function testRuleAppliesToStaticMethodAccessWhenNotAllExcluded() { $rule = new StaticAccess(); $rule->setReport($this->getReportMock(1)); $rule->addProperty('exceptions', 'Excluded'); $rule->apply($this->getMethod()); } public function testRuleNotAppliesToConstantAccess() { $rule = new StaticAccess(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/CleanCode/UndefinedValiableTest.php000066400000000000000000000050561360164303200255010ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\CleanCode; use PHPMD\AbstractTest; /** * Test case for the undefined variable rule. * * @covers \PHPMD\Rule\CleanCode\UndefinedVariable * @covers \PHPMD\Rule\AbstractLocalVariable */ class UndefinedVariableTest extends AbstractTest { /** * testRuleAppliesToUndefinedVariable * * @return void */ public function testRuleAppliesToUndefinedVariable() { $rule = new UndefinedVariable(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getMethod()); } /** * testRuleAppliesToUndefinedVariableWithDefinedVariable * * @return void */ public function testRuleAppliesToUndefinedVariableWithDefinedVariable() { $rule = new UndefinedVariable(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getMethod()); } /** * testRuleAppliesToUndefinedVariableOnArray * * @return void */ public function testRuleAppliesToUndefinedVariableOnArray() { $rule = new UndefinedVariable(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getMethod()); } /** * testRuleAppliesToUndefinedVariableOnArrayWithKeys * * @return void */ public function testRuleAppliesToUndefinedVariableOnArrayWithKeys() { $rule = new UndefinedVariable(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getMethod()); } /** * testRuleAppliesToUndefinedVariableOnArrayWithKeys * * @return void */ public function testRuleDoesNotApplyToSuperGlobals() { $rule = new UndefinedVariable(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToUsedProperties * * @return void */ public function testRuleDoesNotApplyToUsedProperties() { $rule = new UndefinedVariable(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/Controversial/000077500000000000000000000000001360164303200215765ustar00rootroot00000000000000phpmd-2.8.1/src/test/php/PHPMD/Rule/Controversial/CamelCaseMethodNameTest.php000066400000000000000000000137341360164303200267360ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Controversial; use PHPMD\AbstractTest; /** * Test case for the camel case method name rule. * * @covers \PHPMD\Rule\Controversial\CamelCaseMethodName */ class CamelCaseMethodNameTest extends AbstractTest { /** * Tests that the rule does not apply for a valid method name. * * @return void */ public function testRuleDoesNotApplyForValidMethodName() { //$method = $this->getMethod(); $report = $this->getReportMock(0); $rule = new CamelCaseMethodName(); $rule->setReport($report); $rule->addProperty('allow-underscore', 'false'); $rule->addProperty('allow-underscore-test', 'false'); $rule->apply($this->getMethod()); } /** * Tests that the rule does apply for an method name * starting with a capital. * * @return void */ public function testRuleDoesApplyForMethodNameWithCapital() { // Test method name with capital at the beginning $method = $this->getMethod(); $report = $this->getReportMock(1); $rule = new CamelCaseMethodName(); $rule->setReport($report); $rule->addProperty('allow-underscore', 'false'); $rule->addProperty('allow-underscore-test', 'false'); $rule->apply($method); } /** * Tests that the rule does apply for a method name * with underscores. * * @return void */ public function testRuleDoesApplyForMethodNameWithUnderscores() { // Test method name with underscores $method = $this->getMethod(); $report = $this->getReportMock(1); $rule = new CamelCaseMethodName(); $rule->setReport($report); $rule->addProperty('allow-underscore', 'false'); $rule->addProperty('allow-underscore-test', 'false'); $rule->apply($method); } /** * Tests that the rule does apply for a valid method name * with an underscore at the beginning when it is allowed. * * @return void */ public function testRuleDoesApplyForValidMethodNameWithUnderscoreWhenNotAllowed() { $method = $this->getMethod(); $report = $this->getReportMock(1); $rule = new CamelCaseMethodName(); $rule->setReport($report); $rule->addProperty('allow-underscore', 'false'); $rule->addProperty('allow-underscore-test', 'false'); $rule->apply($method); } /** * Tests that the rule does not apply for a valid method name * with an underscore at the beginning when it is not allowed. * * @return void */ public function testRuleDoesNotApplyForValidMethodNameWithUnderscoreWhenAllowed() { $method = $this->getMethod(); $report = $this->getReportMock(0); $rule = new CamelCaseMethodName(); $rule->setReport($report); $rule->addProperty('allow-underscore', 'true'); $rule->addProperty('allow-underscore-test', 'false'); $rule->apply($method); } /** * Tests that the rule does apply for a valid test method name * with an underscore. * * @return void */ public function testRuleDoesApplyForTestMethodWithUnderscoreWhenNotAllowed() { $method = $this->getMethod(); $report = $this->getReportMock(1); $rule = new CamelCaseMethodName(); $rule->setReport($report); $rule->addProperty('allow-underscore', 'false'); $rule->addProperty('allow-underscore-test', 'false'); $rule->apply($method); } /** * Tests that the rule does not apply for a valid test method name * with an underscore when an single underscore is allowed. * * @return void */ public function testRuleDoesNotApplyForTestMethodWithUnderscoreWhenAllowed() { $method = $this->getMethod(); $report = $this->getReportMock(0); $rule = new CamelCaseMethodName(); $rule->setReport($report); $rule->addProperty('allow-underscore', 'false'); $rule->addProperty('allow-underscore-test', 'true'); $rule->apply($method); } /** * Tests that the rule does apply for a test method name * with multiple underscores even when one is allowed. * * @return void */ public function testRuleAppliesToTestMethodWithTwoUnderscoresEvenWhenOneIsAllowed() { $method = $this->getMethod(); $report = $this->getReportMock(1); $rule = new CamelCaseMethodName(); $rule->setReport($report); $rule->addProperty('allow-underscore', 'false'); $rule->addProperty('allow-underscore-test', 'true'); $rule->apply($method); } /** * Tests that the rule does apply to for test method names that * have a capital after their single allowed underscore. * * @return void */ public function testRuleAppliesToTestMethodWithUnderscoreFollowedByCapital() { $method = $this->getMethod(); $report = $this->getReportMock(1); $rule = new CamelCaseMethodName(); $rule->setReport($report); $rule->addProperty('allow-underscore', 'false'); $rule->addProperty('allow-underscore-test', 'true'); $rule->apply($method); } /** * Returns the first method found in a source file related to the calling * test method. * * @return \PHPMD\Node\MethodNode */ protected function getMethod() { $methods = $this->getClass()->getMethods(); return reset($methods); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/Controversial/CamelCasePropertyNameTest.php000066400000000000000000000070511360164303200273350ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Controversial; use PHPMD\AbstractTest; /** * Test case for the camel case property name rule. * * @covers \PHPMD\Rule\Controversial\CamelCasePropertyName */ class CamelCasePropertyNameTest extends AbstractTest { /** * Tests that the rule does not apply for a valid property name. * * @return void */ public function testRuleDoesNotApplyForValidPropertyName() { $report = $this->getReportMock(0); $rule = new CamelCasePropertyName(); $rule->setReport($report); $rule->addProperty('allow-underscore', 'false'); $rule->apply($this->getClass()); } /** * Tests that the rule does NOT apply for an property name * starting with a capital. * * @return void */ public function testRuleDoesNotApplyForPropertyNameWithCapital() { // Test property name with capital at the beginning $report = $this->getReportMock(0); $rule = new CamelCasePropertyName(); $rule->setReport($report); $rule->addProperty('allow-underscore', 'false'); $rule->apply($this->getClass()); } /** * Tests that the rule does apply for a property name * with underscores. * * @return void */ public function testRuleDoesApplyForPropertyNameWithUnderscores() { // Test property name with underscores $report = $this->getReportMock(1); $rule = new CamelCasePropertyName(); $rule->setReport($report); $rule->addProperty('allow-underscore', 'false'); $rule->apply($this->getClass()); } /** * Tests that the rule does apply for a valid property name * with an underscore at the beginning when it is allowed. * * @return void */ public function testRuleDoesApplyForValidPropertyNameWithUnderscoreWhenNotAllowed() { $report = $this->getReportMock(1); $rule = new CamelCasePropertyName(); $rule->setReport($report); $rule->addProperty('allow-underscore', 'false'); $rule->apply($this->getClass()); } /** * Tests that the rule does not apply for a valid property name * with no underscore at the beginning when it is allowed. * * @return void */ public function testRuleDoesNotApplyForValidPropertyNameWithNoUnderscoreWhenAllowed() { $report = $this->getReportMock(0); $rule = new CamelCasePropertyName(); $rule->setReport($report); $rule->addProperty('allow-underscore', 'true'); $rule->apply($this->getClass()); } /** * Tests that the rule does not apply for a valid property name * with an underscore at the beginning when it is allowed. * * @return void */ public function testRuleDoesNotApplyForValidPropertyNameWithUnderscoreWhenAllowed() { $report = $this->getReportMock(0); $rule = new CamelCasePropertyName(); $rule->setReport($report); $rule->addProperty('allow-underscore', 'true'); $rule->apply($this->getClass()); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/Controversial/CamelCaseVariableNameTest.php000066400000000000000000000042321360164303200272340ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Controversial; use PHPMD\AbstractTest; /** * Test case for the camel case variable name rule. * * @covers \PHPMD\Rule\Controversial\CamelCaseVariableName */ class CamelCaseVariableNameTest extends AbstractTest { /** * Tests that the rule does apply for an invalid variable name * @return void */ public function testRuleDoesApplyForInvariableNameWithUnderscore() { $report = $this->getReportMock(1); $rule = new CamelCaseVariableName(); $rule->setReport($report); $rule->apply($this->getClass()); } /** * Tests that the rule does apply for an invalid variable name * starting with a capital. * * @return void */ public function testRuleDoesApplyForVariableNameWithCapital() { $report = $this->getReportMock(1); $rule = new CamelCaseVariableName(); $rule->setReport($report); $rule->apply($this->getClass()); } /** * Tests that the rule does NOT apply for a valid variable name * * @return void */ public function testRuleDoesNotApplyForValidVariableName() { $report = $this->getReportMock(0); $rule = new CamelCaseVariableName(); $rule->setReport($report); $rule->apply($this->getClass()); } /** * Tests that the rule does NOT apply for a statically accessed variable * * @return void */ public function testRuleDoesNotApplyForStaticVariableAccess() { $report = $this->getReportMock(0); $rule = new CamelCaseVariableName(); $rule->setReport($report); $rule->apply($this->getClass()); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/CyclomaticComplexityTest.php000066400000000000000000000041501360164303200244620ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule; use PHPMD\AbstractTest; /** * Test case for the cyclomatic complexity violation rule. * * @covers \PHPMD\Rule\CyclomaticComplexity */ class CyclomaticComplexityTest extends AbstractTest { /** * Tests that the rule applies for a value greater than the configured * threshold. * * @return void */ public function testRuleAppliesForValueGreaterThanThreshold() { $method = $this->getMethodMock('ccn2', 42); $report = $this->getReportMock(1); $rule = new CyclomaticComplexity(); $rule->setReport($report); $rule->addProperty('reportLevel', '10'); $rule->apply($method); } /** * Test that the rule applies for a value that is equal with the configured * threshold. * * @return void */ public function testRuleAppliesForValueEqualToThreshold() { $method = $this->getMethodMock('ccn2', 42); $report = $this->getReportMock(1); $rule = new CyclomaticComplexity(); $rule->setReport($report); $rule->addProperty('reportLevel', '42'); $rule->apply($method); } /** * Tests that the rule does not apply when the value is at least one lower * than the threshold. * * @return void */ public function testRuleDoesNotApplyForValueLowerThanThreshold() { $method = $this->getMethodMock('ccn2', 22); $report = $this->getReportMock(0); $rule = new CyclomaticComplexity(); $rule->setReport($report); $rule->addProperty('reportLevel', '23'); $rule->apply($method); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/Design/000077500000000000000000000000001360164303200201555ustar00rootroot00000000000000phpmd-2.8.1/src/test/php/PHPMD/Rule/Design/CountInLoopExpressionTest.php000066400000000000000000000041261360164303200260220ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PHPMD\AbstractTest; /** * Count In Loop Expression Test * * @author Kamil Szymanski */ class CountInLoopExpressionTest extends AbstractTest { /** * testRuleAppliesToAllTypesOfLoops * * @return void */ public function testRuleAppliesToAllTypesOfLoops() { $rule = new CountInLoopExpression(); $rule->setReport($this->getReportMock(3)); $rule->apply($this->getMethod()); } /** * testRuleNotApplyToExpressionElsewhere * * @return void */ public function testRuleNotApplyToExpressionElsewhere() { $rule = new CountInLoopExpression(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleApplyToNestedLoops * * @return void */ public function testRuleApplyToNestedLoops() { $rule = new CountInLoopExpression(); $rule->setReport($this->getReportMock(8)); $rule->apply($this->getFunction()); } /** * testMutedRuleAtClassLevel * * @return void */ public function testMutedRuleAtClassLevel() { $rule = new CountInLoopExpression(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } /** * testMutedRuleAtMethodLevel * * @return void */ public function testMutedRuleAtMethodLevel() { $rule = new CountInLoopExpression(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/Design/CouplingBetweenObjectsTest.php000066400000000000000000000036451360164303200261420ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PHPMD\AbstractTest; /** * Test case for the {@link \PHPMD\Rule\Design\CouplingBetweenObjects} class. * * @link https://www.pivotaltracker.com/story/show/10474987 * @covers \PHPMD\Rule\Design\CouplingBetweenObjects */ class CouplingBetweenObjectsTest extends AbstractTest { /** * testRuleNotAppliesToClassWithCboLessThanThreshold * * @return void */ public function testRuleNotAppliesToClassWithCboLessThanThreshold() { $rule = new CouplingBetweenObjects(); $rule->setReport($this->getReportMock(0)); $rule->addProperty('maximum', '42'); $rule->apply($this->getClassMock('cbo', 41)); } /** * testRuleAppliesToClassWithCboEqualToThreshold * * @return void */ public function testRuleAppliesToClassWithCboEqualToThreshold() { $rule = new CouplingBetweenObjects(); $rule->setReport($this->getReportMock(1)); $rule->addProperty('maximum', '42'); $rule->apply($this->getClassMock('cbo', 42)); } /** * testRuleAppliesToClassWithCboGreaterThanThreshold * * @return void */ public function testRuleAppliesToClassWithCboGreaterThanThreshold() { $rule = new CouplingBetweenObjects(); $rule->setReport($this->getReportMock(1)); $rule->addProperty('maximum', '41'); $rule->apply($this->getClassMock('cbo', 42)); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/Design/DepthOfInheritanceTest.php000066400000000000000000000036331360164303200252360ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PHPMD\AbstractTest; /** * Test case for the {@link \PHPMD\Rule\Design\DepthOfInheritance} class. * * @covers \PHPMD\Rule\Design\DepthOfInheritance */ class DepthOfInheritanceTest extends AbstractTest { /** * testRuleNotAppliesToClassWithNumberOfParentLessThanThreshold * * @return void */ public function testRuleNotAppliesToClassWithNumberOfParentLessThanThreshold() { $rule = new DepthOfInheritance(); $rule->setReport($this->getReportMock(0)); $rule->addProperty('minimum', '42'); $rule->apply($this->getClassMock('dit', 41)); } /** * testRuleAppliesToClassWithNumberOfParentIdenticalToThreshold * * @return void */ public function testRuleAppliesToClassWithNumberOfParentIdenticalToThreshold() { $rule = new DepthOfInheritance(); $rule->setReport($this->getReportMock(1)); $rule->addProperty('minimum', '42'); $rule->apply($this->getClassMock('dit', 42)); } /** * testRuleAppliesToClassWithNumberOfParentGreaterThanThreshold * * @return void */ public function testRuleAppliesToClassWithNumberOfParentGreaterThanThreshold() { $rule = new DepthOfInheritance(); $rule->setReport($this->getReportMock(1)); $rule->addProperty('minimum', '42'); $rule->apply($this->getClassMock('dit', 43)); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/Design/DevelopmentCodeFragmentTest.php000066400000000000000000000073131360164303200262730ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PHPMD\AbstractTest; /** * Test case for the {@link \PHPMD\Rule\Design\DevelopmentCodeFragment} class. * * @link https://github.com/phpmd/phpmd/issues/265 * @since 2.3.0 * * @covers \PHPMD\Rule\Design\DevelopmentCodeFragment */ class DevelopmentCodeFragmentTest extends AbstractTest { /** * testRuleNotAppliesToMethodWithoutSuspectFunctionCall * * @return void */ public function testRuleNotAppliesToMethodWithoutSuspectFunctionCall() { $rule = $this->getRule(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleAppliesToMethodWithSuspectFunctionCall * * @return void */ public function testRuleAppliesToMethodWithSuspectFunctionCall() { $rule = $this->getRule(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getMethod()); } /** * testRuleAppliesToMethodWithMultipleSuspectFunctionCall * * @return void */ public function testRuleAppliesToMethodWithMultipleSuspectFunctionCall() { $rule = $this->getRule(); $rule->setReport($this->getReportMock(3)); $rule->apply($this->getMethod()); } /** * testRuleNotAppliesToFunctionWithoutSuspectFunctionCall * * @return void */ public function testRuleNotAppliesToFunctionWithoutSuspectFunctionCall() { $rule = $this->getRule(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getFunction()); } /** * testRuleAppliesToFunctionWithSuspectFunctionCall * * @return void */ public function testRuleAppliesToFunctionWithSuspectFunctionCall() { $rule = $this->getRule(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getFunction()); } /** * testRuleAppliesToFunctionWithMultipleSuspectFunctionCall * * @return void */ public function testRuleAppliesToFunctionWithMultipleSuspectFunctionCall() { $rule = $this->getRule(); $rule->setReport($this->getReportMock(3)); $rule->apply($this->getFunction()); } /** * testRuleAppliesToMethodWithinNamespace * * @return void */ public function testRuleAppliesToMethodWithinNamespace() { $rule = $this->getRule(); $rule->addProperty('ignore-namespaces', 'true'); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getClass()); } /** * testRuleNotAppliesToMethodWithinNamespaceByDefault * * @return void */ public function testRuleNotAppliesToMethodWithinNamespaceByDefault() { $rule = $this->getRule(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } /** * Get a configured DevelopmentCodeFragment rule * @return DevelopmentCodeFragment */ private function getRule() { $rule = new DevelopmentCodeFragment(); $rule->addProperty('unwanted-functions', 'var_dump,print_r,debug_zval_dump,debug_print_backtrace'); $rule->addProperty('ignore-namespaces', 'false'); return $rule; } } phpmd-2.8.1/src/test/php/PHPMD/Rule/Design/EmptyCatchBlockTest.php000066400000000000000000000044451360164303200245510ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PHPMD\AbstractTest; /** * Empty Catch Block Test * * @author Grégoire Paris * @author Kamil Szymanski */ class EmptyCatchBlockTest extends AbstractTest { /** * testRuleNotAppliesToMethodWithoutTryCatchBlock * * @return void */ public function testRuleNotAppliesToMethodWithoutTryCatchBlock() { $rule = new EmptyCatchBlock(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleAppliesToFunctionWithEmptyCatchBlock * * @return void */ public function testRuleAppliesToFunctionWithEmptyCatchBlock() { $rule = new EmptyCatchBlock(); $rule->setReport($this->getReportMock(3)); $rule->apply($this->getFunction()); } /** * testRuleNotAppliesToFunctionWithNonEmptyCatchBlock * * @return void */ public function testRuleNotAppliesToFunctionWithNonEmptyCatchBlock() { $rule = new EmptyCatchBlock(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getFunction()); } /** * testRuleNotAppliesToCatchBlockWithComments * * @return void */ public function testRuleNotAppliesToCatchBlockWithComments() { $rule = new EmptyCatchBlock(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getFunction()); } /** * testRuleWorksWithNestedTryCatchBlocksAndNonSPLExceptions * * @return void */ public function testRuleWorksWithNestedTryCatchBlocksAndNonSPLExceptions() { $rule = new EmptyCatchBlock(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getFunction()); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/Design/EvalExpressionTest.php000066400000000000000000000051101360164303200244720ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PHPMD\AbstractTest; /** * Test case for the {@link \PHPMD\Rule\Design\EvalExpression} class. * * @covers \PHPMD\Rule\Design\EvalExpression */ class EvalExpressionTest extends AbstractTest { /** * testRuleNotAppliesToMethodWithoutEvalExpression * * @return void */ public function testRuleNotAppliesToMethodWithoutEvalExpression() { $rule = new EvalExpression(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleAppliesToMethodWithEvalExpression * * @return void */ public function testRuleAppliesToMethodWithEvalExpression() { $rule = new EvalExpression(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getMethod()); } /** * testRuleAppliesMultipleTimesToMethodWithEvalExpression * * @return void */ public function testRuleAppliesMultipleTimesToMethodWithEvalExpression() { $rule = new EvalExpression(); $rule->setReport($this->getReportMock(3)); $rule->apply($this->getMethod()); } /** * testRuleNotAppliesToFunctionWithoutEvalExpression * * @return void */ public function testRuleNotAppliesToFunctionWithoutEvalExpression() { $rule = new EvalExpression(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getFunction()); } /** * testRuleAppliesToFunctionWithEvalExpression * * @return void */ public function testRuleAppliesToFunctionWithEvalExpression() { $rule = new EvalExpression(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getFunction()); } /** * testRuleAppliesMultipleTimesToFunctionWithEvalExpression * * @return void */ public function testRuleAppliesMultipleTimesToFunctionWithEvalExpression() { $rule = new EvalExpression(); $rule->setReport($this->getReportMock(3)); $rule->apply($this->getFunction()); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/Design/ExitExpressionTest.php000066400000000000000000000051101360164303200245140ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PHPMD\AbstractTest; /** * Test case for the {@link \PHPMD\Rule\Design\ExitExpression} class. * * @covers \PHPMD\Rule\Design\ExitExpression */ class ExitExpressionTest extends AbstractTest { /** * testRuleNotAppliesToMethodWithoutExitExpression * * @return void */ public function testRuleNotAppliesToMethodWithoutExitExpression() { $rule = new ExitExpression(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleAppliesToMethodWithExitExpression * * @return void */ public function testRuleAppliesToMethodWithExitExpression() { $rule = new ExitExpression(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getMethod()); } /** * testRuleAppliesMultipleTimesToMethodWithExitExpression * * @return void */ public function testRuleAppliesMultipleTimesToMethodWithExitExpression() { $rule = new ExitExpression(); $rule->setReport($this->getReportMock(3)); $rule->apply($this->getMethod()); } /** * testRuleNotAppliesToFunctionWithoutExitExpression * * @return void */ public function testRuleNotAppliesToFunctionWithoutExitExpression() { $rule = new ExitExpression(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getFunction()); } /** * testRuleAppliesToFunctionWithExitExpression * * @return void */ public function testRuleAppliesToFunctionWithExitExpression() { $rule = new ExitExpression(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getFunction()); } /** * testRuleAppliesMultipleTimesToFunctionWithExitExpression * * @return void */ public function testRuleAppliesMultipleTimesToFunctionWithExitExpression() { $rule = new ExitExpression(); $rule->setReport($this->getReportMock(3)); $rule->apply($this->getFunction()); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/Design/GotoStatementTest.php000066400000000000000000000037541360164303200243340ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PHPMD\AbstractTest; /** * Test case for the {@link \PHPMD\Rule\Design\GotoStatement} class. * * @link https://www.pivotaltracker.com/story/show/10474873 * * @covers \PHPMD\Rule\Design\GotoStatement */ class GotoStatementTest extends AbstractTest { /** * testRuleNotAppliesToMethodWithoutGotoStatement * * @return void */ public function testRuleNotAppliesToMethodWithoutGotoStatement() { $rule = new GotoStatement(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleAppliesToMethodWithGotoStatement * * @return void */ public function testRuleAppliesToMethodWithGotoStatement() { $rule = new GotoStatement(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getMethod()); } /** * testRuleNotAppliesToFunctionWithoutGotoStatement * * @return void */ public function testRuleNotAppliesToFunctionWithoutGotoStatement() { $rule = new GotoStatement(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getFunction()); } /** * testRuleAppliesToFunctionWithGotoStatement * * @return void */ public function testRuleAppliesToFunctionWithGotoStatement() { $rule = new GotoStatement(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getFunction()); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/Design/LongClassTest.php000066400000000000000000000052451360164303200234210ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PHPMD\AbstractTest; /** * Test case for the excessive long class rule. * * @covers \PHPMD\Rule\Design\LongClass */ class LongClassTest extends AbstractTest { /** * Tests that the rule applies for a value greater than the configured * threshold. * * @return void */ public function testRuleAppliesForValueGreaterThanThreshold() { $class = $this->getClassMock('loc', 42); $report = $this->getReportMock(1); $rule = new LongClass(); $rule->setReport($report); $rule->addProperty('minimum', '41'); $rule->addProperty('ignore-whitespace', false); $rule->apply($class); } /** * Test that the rule applies for a value that is equal with the configured * threshold. * * @return void */ public function testRuleAppliesForValueEqualToThreshold() { $class = $this->getClassMock('loc', 42); $report = $this->getReportMock(1); $rule = new LongClass(); $rule->setReport($report); $rule->addProperty('minimum', '42'); $rule->addProperty('ignore-whitespace', false); $rule->apply($class); } /** * Tests that the rule does not apply when the value is at least one lower * than the threshold. * * @return void */ public function testRuleDoesNotApplyForValueLowerThanThreshold() { $class = $this->getClassMock('loc', 22); $report = $this->getReportMock(0); $rule = new LongClass(); $rule->setReport($report); $rule->addProperty('minimum', '23'); $rule->addProperty('ignore-whitespace', false); $rule->apply($class); } /** * Tests that the rule uses eloc when ignore whitespace is set * * @return void */ public function testRuleUsesElocWhenIgnoreWhitespaceSet() { $class = $this->getClassMock('eloc', 22); $report = $this->getReportMock(0); $rule = new LongClass(); $rule->setReport($report); $rule->addProperty('minimum', '23'); $rule->addProperty('ignore-whitespace', true); $rule->apply($class); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/Design/LongMethodTest.php000066400000000000000000000052621360164303200235730ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PHPMD\AbstractTest; /** * Test case for the excessive long method rule. * * @covers \PHPMD\Rule\Design\LongMethod */ class LongMethodTest extends AbstractTest { /** * Tests that the rule applies for a value greater than the configured * threshold. * * @return void */ public function testRuleAppliesForValueGreaterThanThreshold() { $method = $this->getMethodMock('loc', 42); $report = $this->getReportMock(1); $rule = new LongMethod(); $rule->setReport($report); $rule->addProperty('minimum', '41'); $rule->addProperty('ignore-whitespace', false); $rule->apply($method); } /** * Test that the rule applies for a value that is equal with the configured * threshold. * * @return void */ public function testRuleAppliesForValueEqualToThreshold() { $method = $this->getMethodMock('loc', 42); $report = $this->getReportMock(1); $rule = new LongMethod(); $rule->setReport($report); $rule->addProperty('minimum', '42'); $rule->addProperty('ignore-whitespace', false); $rule->apply($method); } /** * Tests that the rule does not apply when the value is at least one lower * than the threshold. * * @return void */ public function testRuleDoesNotApplyForValueLowerThanThreshold() { $method = $this->getMethodMock('loc', 22); $report = $this->getReportMock(0); $rule = new LongMethod(); $rule->setReport($report); $rule->addProperty('minimum', '23'); $rule->addProperty('ignore-whitespace', false); $rule->apply($method); } /** * Tests that the rule uses eloc when ignore whitespace is set * * @return void */ public function testRuleUsesElocWhenIgnoreWhitespaceSet() { $class = $this->getClassMock('eloc', 22); $report = $this->getReportMock(0); $rule = new LongMethod(); $rule->setReport($report); $rule->addProperty('minimum', '23'); $rule->addProperty('ignore-whitespace', true); $rule->apply($class); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/Design/LongParameterListTest.php000066400000000000000000000100711360164303200251210ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PHPMD\AbstractTest; /** * Test case for the excessive long parameter list rule. * * @covers \PHPMD\Rule\Design\LongParameterList */ class LongParameterListTest extends AbstractTest { /** * testApplyIgnoresMethodsWithLessParametersThanMinimum * * @return void */ public function testApplyIgnoresMethodsWithLessParametersThanMinimum() { $rule = new LongParameterList(); $rule->setReport($this->getReportMock(0)); $rule->addProperty('minimum', '4'); $rule->apply($this->createMethod(3)); } /** * testApplyReportsMethodsWithIdenticalParametersAndMinimum * * @return void */ public function testApplyReportsMethodsWithIdenticalParametersAndMinimum() { $rule = new LongParameterList(); $rule->setReport($this->getReportMock(1)); $rule->addProperty('minimum', '3'); $rule->apply($this->createMethod(3)); } /** * testApplyReportsMethodsWithMoreParametersThanMinimum * * @return void */ public function testApplyReportsMethodsWithMoreParametersThanMinimum() { $rule = new LongParameterList(); $rule->setReport($this->getReportMock(1)); $rule->addProperty('minimum', '3'); $rule->apply($this->createMethod(42)); } /** * testApplyIgnoresFunctionsWithLessParametersThanMinimum * * @return void */ public function testApplyIgnoresFunctionsWithLessParametersThanMinimum() { $rule = new LongParameterList(); $rule->setReport($this->getReportMock(0)); $rule->addProperty('minimum', '4'); $rule->apply($this->createFunction(3)); } /** * testApplyReportsFunctionsWithIdenticalParametersAndMinimum * * @return void */ public function testApplyReportsFunctionsWithIdenticalParametersAndMinimum() { $rule = new LongParameterList(); $rule->setReport($this->getReportMock(1)); $rule->addProperty('minimum', '3'); $rule->apply($this->createFunction(3)); } /** * testApplyReportsFunctionsWithMoreParametersThanMinimum * * @return void */ public function testApplyReportsFunctionsWithMoreParametersThanMinimum() { $rule = new LongParameterList(); $rule->setReport($this->getReportMock(1)); $rule->addProperty('minimum', '3'); $rule->apply($this->createFunction(42)); } /** * Returns a mocked method instance. * * @param integer $parameterCount * @return \PHPMD\Node\MethodNode */ private function createMethod($parameterCount) { return $this->initFunctionOrMethodMock($this->getMethodMock(), $parameterCount); } /** * Creates a mocked function node instance. * * @param integer $parameterCount Number of function parameters. * * @return \PHPMD\Node\FunctionNode */ private function createFunction($parameterCount) { return $this->initFunctionOrMethodMock($this->createFunctionMock(), $parameterCount); } /** * Initializes the getParameterCount() method of the given callable. * * @param \PHPMD\Node\FunctionNode|\PHPMD\Node\MethodNode $mock * @param integer $parameterCount * @return \PHPMD\Node\FunctionNode|\PHPMD\Node\MethodNode */ private function initFunctionOrMethodMock($mock, $parameterCount) { $mock->expects($this->once()) ->method('getParameterCount') ->will($this->returnValue($parameterCount)); return $mock; } } phpmd-2.8.1/src/test/php/PHPMD/Rule/Design/NpathComplexityTest.php000066400000000000000000000041171360164303200246610ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PHPMD\AbstractTest; /** * This is a test case for the NPath complexity rule. * * @covers \PHPMD\Rule\Design\NpathComplexity */ class NpathComplexityTest extends AbstractTest { /** * Tests that the rule applies for a value greater than the configured * threshold. * * @return void */ public function testRuleAppliesForValueGreaterThanThreshold() { $method = $this->getMethodMock('npath', 42); $report = $this->getReportMock(1); $rule = new NpathComplexity(); $rule->setReport($report); $rule->addProperty('minimum', '41'); $rule->apply($method); } /** * Test that the rule applies for a value that is equal with the configured * threshold. * * @return void */ public function testRuleAppliesForValueEqualToThreshold() { $method = $this->getMethodMock('npath', 42); $report = $this->getReportMock(1); $rule = new NpathComplexity(); $rule->setReport($report); $rule->addProperty('minimum', '42'); $rule->apply($method); } /** * Tests that the rule does not apply when the value is at least one lower * than the threshold. * * @return void */ public function testRuleDoesNotApplyForValueLowerThanThreshold() { $method = $this->getMethodMock('npath', 22); $report = $this->getReportMock(0); $rule = new NpathComplexity(); $rule->setReport($report); $rule->addProperty('minimum', '23'); $rule->apply($method); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/Design/NumberOfChildrenTest.php000066400000000000000000000035561360164303200247250ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PHPMD\AbstractTest; /** * Test case for the {@link \PHPMD\Rule\Design\NumberOfChildren} class. * * @covers \PHPMD\Rule\Design\NumberOfChildren */ class NumberOfChildrenTest extends AbstractTest { /** * testRuleNotAppliesToClassWithChildrenLessThanThreshold * * @return void */ public function testRuleNotAppliesToClassWithChildrenLessThanThreshold() { $rule = new NumberOfChildren(); $rule->setReport($this->getReportMock(0)); $rule->addProperty('minimum', '42'); $rule->apply($this->getClassMock('nocc', 41)); } /** * testRuleAppliesToClassWithChildrenIdenticalToThreshold * * @return void */ public function testRuleAppliesToClassWithChildrenIdenticalToThreshold() { $rule = new NumberOfChildren(); $rule->setReport($this->getReportMock(1)); $rule->addProperty('minimum', '42'); $rule->apply($this->getClassMock('nocc', 42)); } /** * testRuleAppliesToClassWithChildrenGreaterThanThreshold * * @return void */ public function testRuleAppliesToClassWithChildrenGreaterThanThreshold() { $rule = new NumberOfChildren(); $rule->setReport($this->getReportMock(1)); $rule->addProperty('minimum', '42'); $rule->apply($this->getClassMock('nocc', 43)); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/Design/TooManyFieldsTest.php000066400000000000000000000035271360164303200242520ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PHPMD\AbstractTest; /** * Test case for the too many methods rule. * * @covers \PHPMD\Rule\Design\TooManyFields */ class TooManyFieldsTest extends AbstractTest { /** * testRuleDoesNotApplyToClassesWithLessFieldsThanThreshold * * @return void */ public function testRuleDoesNotApplyToClassesWithLessFieldsThanThreshold() { $rule = new TooManyFields(); $rule->setReport($this->getReportMock(0)); $rule->addProperty('maxfields', '42'); $rule->apply($this->getClassMock('vars', 23)); } /** * testRuleDoesNotApplyToClassesWithSameNumberOfFieldsAsThreshold * * @return void */ public function testRuleDoesNotApplyToClassesWithSameNumberOfFieldsAsThreshold() { $rule = new TooManyFields(); $rule->setReport($this->getReportMock(0)); $rule->addProperty('maxfields', '42'); $rule->apply($this->getClassMock('vars', 42)); } /** * testRuleAppliesToClassesWithMoreFieldsThanThreshold * * @return void */ public function testRuleAppliesToClassesWithMoreFieldsThanThreshold() { $rule = new TooManyFields(); $rule->setReport($this->getReportMock(1)); $rule->addProperty('maxfields', '23'); $rule->apply($this->getClassMock('vars', 42)); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/Design/TooManyMethodsTest.php000066400000000000000000000127761360164303200244550ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PHPMD\AbstractTest; /** * Test case for the too many methods rule. * * @covers \PHPMD\Rule\Design\TooManyMethods */ class TooManyMethodsTest extends AbstractTest { /** * testRuleDoesNotApplyToClassesWithLessMethodsThanThreshold * * @return void */ public function testRuleDoesNotApplyToClassesWithLessMethodsThanThreshold() { $rule = new TooManyMethods(); $rule->setReport($this->getReportMock(0)); $rule->addProperty('maxmethods', '42'); $rule->addProperty('ignorepattern', '(^(set|get|inject))i'); $rule->apply($this->createClassMock(23)); } /** * testRuleDoesNotApplyToClassesWithSameNumberOfMethodsAsThreshold * * @return void */ public function testRuleDoesNotApplyToClassesWithSameNumberOfMethodsAsThreshold() { $rule = new TooManyMethods(); $rule->setReport($this->getReportMock(0)); $rule->addProperty('maxmethods', '42'); $rule->addProperty('ignorepattern', '(^(set|get|inject))i'); $rule->apply($this->createClassMock(42)); } /** * testRuleAppliesToClassesWithMoreMethodsThanThreshold * * @return void */ public function testRuleAppliesToClassesWithMoreMethodsThanThreshold() { $rule = new TooManyMethods(); $rule->setReport($this->getReportMock(1)); $rule->addProperty('maxmethods', '23'); $rule->addProperty('ignorepattern', '(^(set|get|inject))i'); $rule->apply($this->createClassMock(42, array_fill(0, 42, __FUNCTION__))); } /** * testRuleIgnoresGetterMethodsInTest * * @return void */ public function testRuleIgnoresGetterMethodsInTest() { $rule = new TooManyMethods(); $rule->setReport($this->getReportMock(0)); $rule->addProperty('maxmethods', '1'); $rule->addProperty('ignorepattern', '(^(set|get|inject))i'); $rule->apply($this->createClassMock(2, array('invoke', 'getClass'))); } /** * testRuleIgnoresSetterMethodsInTest * * @return void */ public function testRuleIgnoresSetterMethodsInTest() { $rule = new TooManyMethods(); $rule->setReport($this->getReportMock(0)); $rule->addProperty('maxmethods', '1'); $rule->addProperty('ignorepattern', '(^(set|get|inject))i'); $rule->apply($this->createClassMock(2, array('invoke', 'setClass'))); } /** * testRuleIgnoresCustomMethodsWhenRegexPropertyIsGiven * * @return void */ public function testRuleIgnoresCustomMethodsWhenRegexPropertyIsGiven() { $rule = new TooManyMethods(); $rule->setReport($this->getReportMock(0)); $rule->addProperty('maxmethods', '1'); $rule->addProperty('ignorepattern', '(^(set|get|inject))i'); $rule->apply($this->createClassMock(2, array('invoke', 'injectClass'))); } /** * testRuleIgnoresGetterAndSetterMethodsInTest * * @return void */ public function testRuleIgnoresGetterAndSetterMethodsInTest() { $rule = new TooManyMethods(); $rule->setReport($this->getReportMock(0)); $rule->addProperty('maxmethods', '2'); $rule->addProperty('ignorepattern', '(^(set|get|inject))i'); $rule->apply($this->createClassMock(3, array('invoke', 'getClass', 'setClass'))); } /** * @return void */ public function testRuleIgnoresHassers() { $rule = new TooManyMethods(); $rule->setReport($this->getReportMock(0)); $rule->addProperty('maxmethods', '1'); $rule->addProperty('ignorepattern', '(^(set|get|is|has|with))i'); $rule->apply($this->createClassMock(2, array('invoke', 'hasClass'))); } /** * @return void */ public function testRuleIgnoresIssers() { $rule = new TooManyMethods(); $rule->setReport($this->getReportMock(0)); $rule->addProperty('maxmethods', '1'); $rule->addProperty('ignorepattern', '(^(set|get|is|has|with))i'); $rule->apply($this->createClassMock(2, array('invoke', 'isClass'))); } /** * @return void */ public function testRuleIgnoresWithers() { $rule = new TooManyMethods(); $rule->setReport($this->getReportMock(0)); $rule->addProperty('maxmethods', '1'); $rule->addProperty('ignorepattern', '(^(set|get|is|has|with))i'); $rule->apply($this->createClassMock(2, array('invoke', 'withClass'))); } /** * Creates a prepared class node mock * * @param integer $numberOfMethods * @param array$methodNames * @return \PHPMD\Node\ClassNode */ private function createClassMock($numberOfMethods, array $methodNames = null) { $class = $this->getClassMock('nom', $numberOfMethods); if (is_array($methodNames)) { $class->expects($this->once()) ->method('getMethodNames') ->will($this->returnValue($methodNames)); } return $class; } } phpmd-2.8.1/src/test/php/PHPMD/Rule/Design/TooManyPublicMethodsTest.php000066400000000000000000000142711360164303200256040ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PDepend\Source\AST\ASTMethod; use PDepend\Source\AST\State; use PHPMD\AbstractTest; use PHPMD\Node\MethodNode; /** * Test case for the too many public methods rule. * * @covers \PHPMD\Rule\Design\TooManyPublicMethods */ class TooManyPublicMethodsTest extends AbstractTest { /** * @return void */ public function testRuleDoesNotApplyToClassesWithLessMethodsThanThreshold() { $rule = new TooManyPublicMethods(); $rule->setReport($this->getReportMock(0)); $rule->addProperty('maxmethods', '42'); $rule->addProperty('ignorepattern', '(^(set|get|inject))i'); $rule->apply($this->createClassMock(23)); } /** * @return void */ public function testRuleDoesNotApplyToClassesWithSameNumberOfMethodsAsThreshold() { $rule = new TooManyPublicMethods(); $rule->setReport($this->getReportMock(0)); $rule->addProperty('maxmethods', '42'); $rule->addProperty('ignorepattern', '(^(set|get|inject))i'); $rule->apply($this->createClassMock(42)); } /** * @return void */ public function testRuleAppliesToClassesWithMoreMethodsThanThreshold() { $rule = new TooManyPublicMethods(); $rule->setReport($this->getReportMock(1)); $rule->addProperty('maxmethods', '23'); $rule->addProperty('ignorepattern', '(^(set|get|inject))i'); $rule->apply($this->createClassMock(42, array_fill(0, 42, __FUNCTION__))); } /** * @return void */ public function testRuleIgnoresGetterMethodsInTest() { $rule = new TooManyPublicMethods(); $rule->setReport($this->getReportMock(0)); $rule->addProperty('maxmethods', '1'); $rule->addProperty('ignorepattern', '(^(set|get|inject))i'); $rule->apply($this->createClassMock(2, array('invoke', 'getClass'))); } /** * @return void */ public function testRuleIgnoresSetterMethodsInTest() { $rule = new TooManyPublicMethods(); $rule->setReport($this->getReportMock(0)); $rule->addProperty('maxmethods', '1'); $rule->addProperty('ignorepattern', '(^(set|get|inject))i'); $rule->apply($this->createClassMock(2, array('invoke', 'setClass'))); } /** * @return void */ public function testRuleIgnoresCustomMethodsWhenRegexPropertyIsGiven() { $rule = new TooManyPublicMethods(); $rule->setReport($this->getReportMock(0)); $rule->addProperty('maxmethods', '1'); $rule->addProperty('ignorepattern', '(^(set|get|inject))i'); $rule->apply($this->createClassMock(2, array('invoke', 'injectClass'))); } /** * @return void */ public function testRuleIgnoresGetterAndSetterMethodsInTest() { $rule = new TooManyPublicMethods(); $rule->setReport($this->getReportMock(0)); $rule->addProperty('maxmethods', '2'); $rule->addProperty('ignorepattern', '(^(set|get|inject))i'); $rule->apply($this->createClassMock(3, array('foo', 'bar'), array('baz', 'bah'))); } /** * @return void */ public function testRuleIgnoresPrivateMethods() { $rule = new TooManyPublicMethods(); $rule->setReport($this->getReportMock(0)); $rule->addProperty('maxmethods', '2'); $rule->addProperty('ignorepattern', '(^(set|get|inject))i'); $rule->apply($this->createClassMock(2, array('invoke', 'getClass', 'setClass'))); } /** * @return void */ public function testRuleIgnoresHassers() { $rule = new TooManyPublicMethods(); $rule->setReport($this->getReportMock(0)); $rule->addProperty('maxmethods', '1'); $rule->addProperty('ignorepattern', '(^(set|get|is|has|with))i'); $rule->apply($this->createClassMock(2, array('invoke', 'hasClass'))); } /** * @return void */ public function testRuleIgnoresIssers() { $rule = new TooManyPublicMethods(); $rule->setReport($this->getReportMock(0)); $rule->addProperty('maxmethods', '1'); $rule->addProperty('ignorepattern', '(^(set|get|is|has|with))i'); $rule->apply($this->createClassMock(2, array('invoke', 'isClass'))); } /** * @return void */ public function testRuleIgnoresWithers() { $rule = new TooManyPublicMethods(); $rule->setReport($this->getReportMock(0)); $rule->addProperty('maxmethods', '1'); $rule->addProperty('ignorepattern', '(^(set|get|is|has|with))i'); $rule->apply($this->createClassMock(2, array('invoke', 'withClass'))); } /** * Creates a prepared class node mock * * @param integer $numberOfMethods * @param array|null $publicMethods * @param array|null $privateMethods * @return \PHPMD\Node\ClassNode */ private function createClassMock($numberOfMethods, array $publicMethods = array(), array $privateMethods = array()) { $class = $this->getClassMock('npm', $numberOfMethods); $class->expects($this->any()) ->method('getMethods') ->will($this->returnValue(array_merge( array_map(array($this, 'createPublicMethod'), $publicMethods), array_map(array($this, 'createPrivateMethod'), $privateMethods) ))); return $class; } private function createPublicMethod($methodName) { $astMethod = new ASTMethod($methodName); $astMethod->setModifiers(State::IS_PUBLIC); return new MethodNode($astMethod); } private function createPrivateMethod($methodName) { $astMethod = new ASTMethod($methodName); return new MethodNode($astMethod); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/Design/WeightedMethodCountTest.php000066400000000000000000000037251360164303200254470ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Design; use PHPMD\AbstractTest; /** * Test case for the weighted method count rule. * * @since 0.2.5 * * @covers \PHPMD\Rule\Design\WeightedMethodCount */ class WeightedMethodCountTest extends AbstractTest { /** * testRuleAppliesForValueGreaterThanThreshold * * @return void */ public function testRuleAppliesForValueGreaterThanThreshold() { $class = $this->getClassMock('wmc', 42); $report = $this->getReportMock(1); $rule = new WeightedMethodCount(); $rule->setReport($report); $rule->addProperty('maximum', '10'); $rule->apply($class); } /** * testRuleAppliesForValueEqualToThreshold * * @return void */ public function testRuleAppliesForValueEqualToThreshold() { $class = $this->getClassMock('wmc', 42); $report = $this->getReportMock(1); $rule = new WeightedMethodCount(); $rule->setReport($report); $rule->addProperty('maximum', '42'); $rule->apply($class); } /** * testRuleNotAppliesForValueLowerThanThreshold * * @return void */ public function testRuleNotAppliesForValueLowerThanThreshold() { $class = $this->getClassMock('wmc', 42); $report = $this->getReportMock(0); $rule = new WeightedMethodCount(); $rule->setReport($report); $rule->addProperty('maximum', '43'); $rule->apply($class); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/ExcessivePublicCountTest.php000066400000000000000000000036221360164303200244260ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule; use PHPMD\AbstractTest; /** * Test case for the excessive use of public members rule. * * @covers \PHPMD\Rule\ExcessivePublicCount */ class ExcessivePublicCountTest extends AbstractTest { /** * testRuleDoesNotApplyToClassesWithLessPublicMembersThanThreshold * * @return void */ public function testRuleDoesNotApplyToClassesWithLessPublicMembersThanThreshold() { $rule = new ExcessivePublicCount(); $rule->setReport($this->getReportMock(0)); $rule->addProperty('minimum', '42'); $rule->apply($this->getClassMock('cis', 23)); } /** * testRuleAppliesToClassesWithSameNumberOfPublicMembersAsThreshold * * @return void */ public function testRuleAppliesToClassesWithSameNumberOfPublicMembersAsThreshold() { $rule = new ExcessivePublicCount(); $rule->setReport($this->getReportMock(1)); $rule->addProperty('minimum', '42'); $rule->apply($this->getClassMock('cis', 42)); } /** * testRuleAppliesToClassesWithMorePublicMembersThanThreshold * * @return void */ public function testRuleAppliesToClassesWithMorePublicMembersThanThreshold() { $rule = new ExcessivePublicCount(); $rule->setReport($this->getReportMock(1)); $rule->addProperty('minimum', '23'); $rule->apply($this->getClassMock('cis', 42)); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/Naming/000077500000000000000000000000001360164303200201555ustar00rootroot00000000000000phpmd-2.8.1/src/test/php/PHPMD/Rule/Naming/BooleanGetMethodNameTest.php000066400000000000000000000101421360164303200255050ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Naming; use PHPMD\AbstractTest; /** * Test case for the {@link \PHPMD\Rule\Naming\BooleanGetMethodName} rule class. * * @covers PHPMD\Rule\Naming\BooleanGetMethodName */ class BooleanGetMethodNameTest extends AbstractTest { /** * testRuleAppliesToMethodStartingWithGetAndReturningBoolean * * @return void */ public function testRuleAppliesToMethodStartingWithGetAndReturningBoolean() { $rule = new BooleanGetMethodName(); $rule->addProperty('checkParameterizedMethods', 'false'); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getMethod()); } /** * testRuleAppliesToMethodStartingWithGetAndReturningBool * * @return void */ public function testRuleAppliesToMethodStartingWithGetAndReturningBool() { $rule = new BooleanGetMethodName(); $rule->addProperty('checkParameterizedMethods', 'false'); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getMethod()); } /** * testRuleAppliesToPearPrivateMethodStartingWithGetAndReturningBoolean * * @return void */ public function testRuleAppliesToPearPrivateMethodStartingWithGetAndReturningBoolean() { $rule = new BooleanGetMethodName(); $rule->addProperty('checkParameterizedMethods', 'false'); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getMethod()); } /** * testRuleIgnoresParametersWhenNotExplicitConfigured * * @return void */ public function testRuleIgnoresParametersWhenNotExplicitConfigured() { $rule = new BooleanGetMethodName(); $rule->addProperty('checkParameterizedMethods', 'false'); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getMethod()); } /** * testRuleNotAppliesWhenParametersAreExplicitEnabled * * @return void */ public function testRuleNotAppliesWhenParametersAreExplicitEnabled() { $rule = new BooleanGetMethodName(); $rule->addProperty('checkParameterizedMethods', 'true'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleNotAppliesToMethodStartingWithIs * * @return void */ public function testRuleNotAppliesToMethodStartingWithIs() { $rule = new BooleanGetMethodName(); $rule->addProperty('checkParameterizedMethods', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleNotAppliesToMethodStartingWithHas * * @return void */ public function testRuleNotAppliesToMethodStartingWithHas() { $rule = new BooleanGetMethodName(); $rule->addProperty('checkParameterizedMethods', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleNotAppliesToMethodWithReturnTypeNotBoolean * * @return void */ public function testRuleNotAppliesToMethodWithReturnTypeNotBoolean() { $rule = new BooleanGetMethodName(); $rule->addProperty('checkParameterizedMethods', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * Returns the first method found in a source file related to the calling * test method. * * @return \PHPMD\Node\MethodNode */ protected function getMethod() { $methods = $this->getClass()->getMethods(); return reset($methods); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/Naming/ConstantNamingConventionsTest.php000066400000000000000000000040711360164303200267010ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Naming; use PHPMD\AbstractTest; /** * Test case for the constructor name rule. * * @covers PHPMD\Rule\Naming\ConstantNamingConventions */ class ConstantNamingConventionsTest extends AbstractTest { /** * testRuleAppliesToClassConstantWithLowerCaseCharacters * * @return void */ public function testRuleAppliesToClassConstantWithLowerCaseCharacters() { $rule = new ConstantNamingConventions(); $rule->setReport($this->getReportMock(2)); $rule->apply($this->getClass()); } /** * testRuleAppliesToInterfaceConstantWithLowerCaseCharacters * * @return void */ public function testRuleAppliesToInterfaceConstantWithLowerCaseCharacters() { $rule = new ConstantNamingConventions(); $rule->setReport($this->getReportMock(3)); $rule->apply($this->getInterface()); } /** * testRuleNotAppliesToClassConstantWithUpperCaseCharacters * * @return void */ public function testRuleNotAppliesToClassConstantWithUpperCaseCharacters() { $rule = new ConstantNamingConventions(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } /** * testRuleNotAppliesToInterfaceConstantWithUpperCaseCharacters * * @return void */ public function testRuleNotAppliesToInterfaceConstantWithUpperCaseCharacters() { $rule = new ConstantNamingConventions(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getInterface()); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/Naming/ConstructorWithNameAsEnclosingClassTest.php000066400000000000000000000043651360164303200306340ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Naming; use PHPMD\AbstractTest; /** * Test case for the constructor name rule. * * @covers PHPMD\Rule\Naming\ConstructorWithNameAsEnclosingClass */ class ConstructorWithNameAsEnclosingClassTest extends AbstractTest { /** * testRuleAppliesToConstructorMethodNamedAsEnclosingClass * * @return void */ public function testRuleAppliesToConstructorMethodNamedAsEnclosingClass() { $rule = new ConstructorWithNameAsEnclosingClass(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getMethod()); } /** * testRuleAppliesToConstructorMethodNamedAsEnclosingClassCaseInsensitive * * @return void */ public function testRuleAppliesToConstructorMethodNamedAsEnclosingClassCaseInsensitive() { $rule = new ConstructorWithNameAsEnclosingClass(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getMethod()); } /** * testRuleNotAppliesToMethodNamedSimilarToEnclosingClass * * @return void */ public function testRuleNotAppliesToMethodNamedSimilarToEnclosingClass() { $rule = new ConstructorWithNameAsEnclosingClass(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } public function testRuleNotAppliesToMethodNamedAsEnclosingInterface() { $rule = new ConstructorWithNameAsEnclosingClass(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } public function testRuleNotAppliesToMethodInNamespaces() { $rule = new ConstructorWithNameAsEnclosingClass(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/Naming/LongVariableTest.php000066400000000000000000000203131360164303200240720ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Naming; use PHPMD\AbstractTest; /** * Test case for the really long variable, parameter and property name rule. * * @covers PHPMD\Rule\Naming\LongVariable */ class LongVariableTest extends AbstractTest { /** * testRuleAppliesToLocalVariableInFunctionWithNameLongerThanThreshold * * @return void */ public function testRuleAppliesToLocalVariableInFunctionWithNameLongerThanThreshold() { $rule = new LongVariable(); $rule->addProperty('maximum', 17); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getFunction()); } /** * testRuleNotAppliesToLocalVariableInFunctionWithNameSmallerThanThreshold * * @return void */ public function testRuleNotAppliesToLocalVariableInFunctionWithNameSmallerThanThreshold() { $rule = new LongVariable(); $rule->addProperty('maximum', 17); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getFunction()); } /** * testRuleNotAppliesToLocalVariableInFunctionWithNameEqualToThreshold * * @return void */ public function testRuleNotAppliesToLocalVariableInFunctionWithNameEqualToThreshold() { $rule = new LongVariable(); $rule->addProperty('maximum', 6); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getFunction()); } /** * testRuleAppliesToFunctionParameterWithNameLongerThanThreshold * * @return void */ public function testRuleAppliesToFunctionParameterWithNameLongerThanThreshold() { $rule = new LongVariable(); $rule->addProperty('maximum', 17); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getFunction()); } /** * testRuleNotAppliesToFunctionParameterWithNameSmallerThanThreshold * * @return void */ public function testRuleNotAppliesToFunctionParameterWithNameSmallerThanThreshold() { $rule = new LongVariable(); $rule->addProperty('maximum', 17); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getFunction()); } /** * testRuleAppliesToLocalVariableInMethodWithNameLongerThanThreshold * * @return void */ public function testRuleAppliesToLocalVariableInMethodWithNameLongerThanThreshold() { $rule = new LongVariable(); $rule->addProperty('maximum', 17); $rule->setReport($this->getReportMock(1)); $class = $this->getClass(); $rule->apply($class); foreach ($class->getMethods() as $method) { $rule->apply($method); } } /** * testRuleNotAppliesToLocalVariableInMethodWithNameEqualToThreshold * * @return void */ public function testRuleNotAppliesToLocalVariableInMethodWithNameEqualToThreshold() { $rule = new LongVariable(); $rule->addProperty('maximum', 6); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } /** * testRuleNotAppliesToLocalVariableInMethodWithNameShorterThanThreshold * * @return void */ public function testRuleNotAppliesToLocalVariableInMethodWithNameShorterThanThreshold() { $rule = new LongVariable(); $rule->addProperty('maximum', 17); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } /** * testRuleAppliesToMethodParameterWithNameLongerThanThreshold * * @return void */ public function testRuleAppliesToMethodParameterWithNameLongerThanThreshold() { $rule = new LongVariable(); $rule->addProperty('maximum', 3); $rule->setReport($this->getReportMock(1)); $class = $this->getClass(); $rule->apply($class); foreach ($class->getMethods() as $method) { $rule->apply($method); } } /** * testRuleNotAppliesToMethodParameterWithNameShorterThanThreshold * * @return void */ public function testRuleNotAppliesToMethodParameterWithNameShorterThanThreshold() { $rule = new LongVariable(); $rule->addProperty('maximum', 17); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } /** * testRuleAppliesToFieldWithNameLongerThanThreshold * * @return void */ public function testRuleAppliesToFieldWithNameLongerThanThreshold() { $rule = new LongVariable(); $rule->addProperty('maximum', 17); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getClass()); } /** * testRuleNotAppliesToFieldWithNameEqualToThreshold * * @return void */ public function testRuleNotAppliesToFieldWithNameEqualToThreshold() { $rule = new LongVariable(); $rule->addProperty('maximum', 6); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } /** * testRuleNotAppliesToFieldWithNameShorterThanThreshold * * @return void */ public function testRuleNotAppliesToFieldWithNameShorterThanThreshold() { $rule = new LongVariable(); $rule->addProperty('maximum', 8); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } /** * testRuleAppliesToFieldAndParameterWithNameLongerThanThreshold * * @return void */ public function testRuleAppliesToFieldAndParameterWithNameLongerThanThreshold() { $rule = new LongVariable(); $rule->addProperty('maximum', 3); $rule->setReport($this->getReportMock(2)); $class = $this->getClass(); $rule->apply($class); foreach ($class->getMethods() as $method) { $rule->apply($method); } } /** * testRuleNotAppliesToStaticMembersAccessedInMethod * * @return void */ public function testRuleNotAppliesToStaticMembersAccessedInMethod() { $rule = new LongVariable(); $rule->addProperty('maximum', 3); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleAppliesToIdenticalVariableOnlyOneTime * * @return void */ public function testRuleAppliesToIdenticalVariableOnlyOneTime() { $rule = new LongVariable(); $rule->addProperty('maximum', 17); $rule->setReport($this->getReportMock(2)); $rule->apply($this->getMethod()); } /** * testRuleAppliesToIdenticalVariablesInDifferentContextsSeveralTimes * * @return void */ public function testRuleAppliesToIdenticalVariablesInDifferentContextsSeveralTimes() { $rule = new LongVariable(); $rule->addProperty('maximum', 17); $rule->setReport($this->getReportMock(2)); $class = $this->getClass(); $rule->apply($class); foreach ($class->getMethods() as $method) { $rule->apply($method); } } /** * testRuleAppliesForLongPrivateProperty * * @return void * @since 1.1.0 */ public function testRuleAppliesForLongPrivateProperty() { $rule = new LongVariable(); $rule->addProperty('maximum', 17); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getClass()); } /** * testRuleAppliesForLongPrivateStaticProperty * * @return void * @since 1.1.0 */ public function testRuleAppliesForLongPrivateStaticProperty() { $rule = new LongVariable(); $rule->addProperty('maximum', 17); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getClass()); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/Naming/ShortMethodNameTest.php000066400000000000000000000101231360164303200245640ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Naming; use PHPMD\AbstractTest; /** * Test case for the very short method and function name rule. * * @covers PHPMD\Rule\Naming\ShortMethodName */ class ShortMethodNameTest extends AbstractTest { /** * testRuleAppliesToFunctionWithNameShorterThanThreshold * * @return void */ public function testRuleAppliesToFunctionWithNameShorterThanThreshold() { $rule = new ShortMethodName(); $rule->addProperty('minimum', 54); $rule->addProperty('exceptions', ''); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getFunction()); } /** * testRuleNotAppliesToFunctionWithNameEqualToThreshold * * @return void */ public function testRuleNotAppliesToFunctionWithNameEqualToThreshold() { $rule = new ShortMethodName(); $rule->addProperty('minimum', 52); $rule->addProperty('exceptions', ''); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getFunction()); } /** * testRuleNotAppliesToFunctionWithNameLongerThanThreshold * * @return void */ public function testRuleNotAppliesToFunctionWithNameLongerThanThreshold() { $rule = new ShortMethodName(); $rule->addProperty('minimum', 54); $rule->addProperty('exceptions', ''); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getFunction()); } /** * testRuleAppliesToFunctionWithNameShorterThanThreshold * * @return void */ public function testRuleAppliesToMethodWithNameShorterThanThreshold() { $rule = new ShortMethodName(); $rule->addProperty('minimum', 52); $rule->addProperty('exceptions', ''); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getMethod()); } /** * testRuleNotAppliesToMethodWithNameEqualToThreshold * * @return void */ public function testRuleNotAppliesToMethodWithNameEqualToThreshold() { $rule = new ShortMethodName(); $rule->addProperty('minimum', 50); $rule->addProperty('exceptions', ''); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleNotAppliesToMethodWithNameLongerThanThreshold * * @return void */ public function testRuleNotAppliesToMethodWithNameLongerThanThreshold() { $rule = new ShortMethodName(); $rule->addProperty('minimum', 52); $rule->addProperty('exceptions', ''); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleNotAppliesToMethodWithNameLongerThanThreshold * * @return void */ public function testRuleNotAppliesToMethodWithShortNameWhenException() { $rule = new ShortMethodName(); $rule->addProperty('minimum', 100); $rule->addProperty('exceptions', 'testRuleNotAppliesToMethodWithShortNameWhenException,another'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleAlsoWorksWithoutExceptionListConfigured * * @return void * @since 2.2.2 * @link https://github.com/phpmd/phpmd/issues/80 * @link https://github.com/phpmd/phpmd/issues/270 */ public function testRuleAlsoWorksWithoutExceptionListConfigured() { $rule = new ShortMethodName(); $rule->addProperty('minimum', 100); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethodMock()); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/Naming/ShortVariableTest.php000066400000000000000000000236051360164303200243010ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule\Naming; use PHPMD\AbstractTest; /** * Test case for the really short variable, parameter and property name rule. * * @covers PHPMD\Rule\Naming\ShortVariable */ class ShortVariableTest extends AbstractTest { /** * testRuleAppliesToLocalVariableInFunctionWithNameShorterThanThreshold * * @return void */ public function testRuleAppliesToLocalVariableInFunctionWithNameShorterThanThreshold() { $rule = new ShortVariable(); $rule->addProperty('minimum', 3); $rule->addProperty('exceptions', ''); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getFunction()); } /** * testRuleNotAppliesToLocalVariableInFunctionWithNameLongerThanThreshold * * @return void */ public function testRuleNotAppliesToLocalVariableInFunctionWithNameLongerThanThreshold() { $rule = new ShortVariable(); $rule->addProperty('minimum', 2); $rule->addProperty('exceptions', ''); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getFunction()); } /** * testRuleNotAppliesToLocalVariableInFunctionWithNameEqualToThreshold * * @return void */ public function testRuleNotAppliesToLocalVariableInFunctionWithNameEqualToThreshold() { $rule = new ShortVariable(); $rule->addProperty('minimum', 3); $rule->addProperty('exceptions', ''); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getFunction()); } /** * testRuleAppliesToFunctionParameterWithNameShorterThanThreshold * * @return void */ public function testRuleAppliesToFunctionParameterWithNameShorterThanThreshold() { $rule = new ShortVariable(); $rule->addProperty('minimum', 3); $rule->addProperty('exceptions', ''); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getFunction()); } /** * testRuleNotAppliesToFunctionParameterWithNameLongerThanThreshold * * @return void */ public function testRuleNotAppliesToFunctionParameterWithNameLongerThanThreshold() { $rule = new ShortVariable(); $rule->addProperty('minimum', 3); $rule->addProperty('exceptions', ''); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getFunction()); } /** * testRuleAppliesToLocalVariableInMethodWithNameShorterThanThreshold * * @return void */ public function testRuleAppliesToLocalVariableInMethodWithNameShorterThanThreshold() { $rule = new ShortVariable(); $rule->addProperty('minimum', 3); $rule->addProperty('exceptions', ''); $rule->setReport($this->getReportMock(1)); $class = $this->getClass(); $rule->apply($class); foreach ($class->getMethods() as $method) { $rule->apply($method); } } /** * testRuleNotAppliesToLocalVariableInMethodWithNameEqualToThreshold * * @return void */ public function testRuleNotAppliesToLocalVariableInMethodWithNameEqualToThreshold() { $rule = new ShortVariable(); $rule->addProperty('minimum', 3); $rule->addProperty('exceptions', ''); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } /** * testRuleNotAppliesToLocalVariableInMethodWithNameLongerThanThreshold * * @return void */ public function testRuleNotAppliesToLocalVariableInMethodWithNameLongerThanThreshold() { $rule = new ShortVariable(); $rule->addProperty('minimum', 2); $rule->addProperty('exceptions', ''); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } /** * testRuleAppliesToMethodParameterWithNameShorterThanThreshold * * @return void */ public function testRuleAppliesToMethodParameterWithNameShorterThanThreshold() { $rule = new ShortVariable(); $rule->addProperty('minimum', 3); $rule->addProperty('exceptions', ''); $rule->setReport($this->getReportMock(1)); $class = $this->getClass(); $rule->apply($class); foreach ($class->getMethods() as $method) { $rule->apply($method); } } /** * testRuleNotAppliesToMethodParameterWithNameLongerThanThreshold * * @return void */ public function testRuleNotAppliesToMethodParameterWithNameLongerThanThreshold() { $rule = new ShortVariable(); $rule->addProperty('minimum', 2); $rule->addProperty('exceptions', ''); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } /** * testRuleAppliesToFieldWithNameShorterThanThreshold * * @return void */ public function testRuleAppliesToFieldWithNameShorterThanThreshold() { $rule = new ShortVariable(); $rule->addProperty('minimum', 3); $rule->addProperty('exceptions', ''); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getClass()); } /** * testRuleNotAppliesToFieldWithNameEqualToThreshold * * @return void */ public function testRuleNotAppliesToFieldWithNameEqualToThreshold() { $rule = new ShortVariable(); $rule->addProperty('minimum', 3); $rule->addProperty('exceptions', ''); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } /** * testRuleNotAppliesToFieldWithNameGreaterThanThreshold * * @return void */ public function testRuleNotAppliesToFieldWithNameGreaterThanThreshold() { $rule = new ShortVariable(); $rule->addProperty('minimum', 2); $rule->addProperty('exceptions', ''); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } /** * testRuleAppliesToFieldAndParameterWithNameShorterThanThreshold * * @return void */ public function testRuleAppliesToFieldAndParameterWithNameShorterThanThreshold() { $rule = new ShortVariable(); $rule->addProperty('minimum', 3); $rule->addProperty('exceptions', ''); $rule->setReport($this->getReportMock(2)); $class = $this->getClass(); $rule->apply($class); foreach ($class->getMethods() as $method) { $rule->apply($method); } } /** * testRuleNotAppliesToShortVariableNameAsForLoopIndex * * @return void */ public function testRuleNotAppliesToShortVariableNameAsForLoopIndex() { $rule = new ShortVariable(); $rule->addProperty('minimum', 3); $rule->addProperty('exceptions', ''); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getFunction()); } /** * testRuleNotAppliesToShortVariableNameAsForeachLoopIndex * * @return void */ public function testRuleNotAppliesToShortVariableNameAsForeachLoopIndex() { $rule = new ShortVariable(); $rule->addProperty('minimum', 3); $rule->addProperty('exceptions', ''); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getFunction()); } /** * testRuleNotAppliesToShortVariableNameInCatchStatement * * @return void */ public function testRuleNotAppliesToShortVariableNameInCatchStatement() { $rule = new ShortVariable(); $rule->addProperty('minimum', 3); $rule->addProperty('exceptions', ''); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getFunction()); } /** * testRuleNotAppliesToStaticMembersAccessedInMethod * * @return void */ public function testRuleNotAppliesToStaticMembersAccessedInMethod() { $rule = new ShortVariable(); $rule->addProperty('minimum', 3); $rule->addProperty('exceptions', ''); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleAppliesToIdenticalVariableOnlyOneTime * * @return void */ public function testRuleAppliesToIdenticalVariableOnlyOneTime() { $rule = new ShortVariable(); $rule->addProperty('minimum', 3); $rule->addProperty('exceptions', ''); $rule->setReport($this->getReportMock(2)); $rule->apply($this->getMethod()); } /** * testRuleAppliesToIdenticalVariablesInDifferentContextsSeveralTimes * * @return void */ public function testRuleAppliesToIdenticalVariablesInDifferentContextsSeveralTimes() { $rule = new ShortVariable(); $rule->addProperty('minimum', 3); $rule->addProperty('exceptions', ''); $rule->setReport($this->getReportMock(2)); $class = $this->getClass(); $rule->apply($class); foreach ($class->getMethods() as $method) { $rule->apply($method); } } /** * testRuleNotAppliesToVariablesFromExceptionsList * * @return void */ public function testRuleNotAppliesToVariablesFromExceptionsList() { $rule = new ShortVariable(); $rule->addProperty('minimum', 3); $rule->addProperty('exceptions', 'id'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/UnusedFormalParameterTest.php000066400000000000000000000305611360164303200245670ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule; use PHPMD\AbstractTest; /** * Test case for the unused formal parameter rule. * * @covers \PHPMD\Rule\UnusedFormalParameter * @covers \PHPMD\Rule\AbstractLocalVariable */ class UnusedFormalParameterTest extends AbstractTest { /** * testRuleAppliesToFunctionUnusedFormalParameter * * @return void */ public function testRuleAppliesToFunctionUnusedFormalParameter() { $rule = new UnusedFormalParameter(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getFunction()); } /** * testRuleAppliesToMultipleFunctionUnusedFormalParameter * * @return void */ public function testRuleAppliesToMultipleFunctionUnusedFormalParameter() { $rule = new UnusedFormalParameter(); $rule->setReport($this->getReportMock(3)); $rule->apply($this->getFunction()); } /** * testRuleAppliesToMethodUnusedFormalParameter * * @return void */ public function testRuleAppliesToMethodUnusedFormalParameter() { $rule = new UnusedFormalParameter(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getMethod()); } /** * testRuleAppliesToMultipleMethodUnusedFormalParameter * * @return void */ public function testRuleAppliesToMultipleMethodUnusedFormalParameter() { $rule = new UnusedFormalParameter(); $rule->setReport($this->getReportMock(2)); $rule->apply($this->getMethod()); } /** * testRuleAppliesToFormalParameterWhenSimilarStaticMemberIsAccessed * * * class Foo { * public static $bar = null; * public function baz($bar) { * self::$bar = 'fooBar'; * } * } * * * @return void */ public function testRuleAppliesToFormalParameterWhenSimilarStaticMemberIsAccessed() { $rule = new UnusedFormalParameter(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getMethod()); } /** * testRuleNotAppliesToFormalParameterUsedInPropertyCompoundVariable * * * class Foo { * public function baz($bar) { * self::${$bar} = 'fooBar'; * } * } * * * @return void */ public function testRuleNotAppliesToFormalParameterUsedInPropertyCompoundVariable() { $rule = new UnusedFormalParameter(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleNotAppliesToFormalParameterUsedInMethodCompoundVariable * * * class Foo { * public function baz($bar) { * self::${$bar}(); * } * } * * * @return void */ public function testRuleNotAppliesToFormalParameterUsedInMethodCompoundVariable() { $rule = new UnusedFormalParameter(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToAbstractMethodFormalParameter * * @return void */ public function testRuleDoesNotApplyToAbstractMethodFormalParameter() { $rule = new UnusedFormalParameter(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToInterfaceMethodFormalParameter * * @return void */ public function testRuleDoesNotApplyToInterfaceMethodFormalParameter() { $rule = new UnusedFormalParameter(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToInnerFunctionDeclaration * * @return void */ public function testRuleDoesNotApplyToInnerFunctionDeclaration() { $rule = new UnusedFormalParameter(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getFunction()); } /** * testRuleDoesNotApplyToFormalParameterUsedInCompoundExpression * * * class Foo { * public static $bar; * public function baz($bar) { * self::${$bar} = 42; * } * } * * * @return void */ public function testRuleDoesNotApplyToFormalParameterUsedInCompoundExpression() { $rule = new UnusedFormalParameter(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToMethodArgument * * * class Foo { * function bar($baz) { * $this->foo($baz); * } * } * * * @return void */ public function testRuleDoesNotApplyToMethodArgument() { $rule = new UnusedFormalParameter(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToMethodArgumentUsedAsArrayIndex * * @return void */ public function testRuleDoesNotApplyToMethodArgumentUsedAsArrayIndex() { $rule = new UnusedFormalParameter(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToParameterUsedAsArrayIndex * * * class Foo { * function bar($baz) { * self::$values[$baz]; * } * } * * * @return void */ public function testRuleDoesNotApplyToParameterUsedAsArrayIndex() { $rule = new UnusedFormalParameter(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToParameterUsedAsStringIndex * * * class Foo { * function bar($baz) { * self::$string{$baz}; * } * } * * * @return void */ public function testRuleDoesNotApplyToParameterUsedAsStringIndex() { $rule = new UnusedFormalParameter(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToMethodWithFuncGetArgs * * If func_get_args() is called then all parameters are * automatically referenced without needing them to be referenced * explicitly * * * class Foo { * function bar($baz) { * print_r(func_get_args()); * } * } * * * @return void */ public function testRuleDoesNotApplyToMethodWithFuncGetArgs() { $rule = new UnusedFormalParameter(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * @test * @return void * @since 2.0.0 */ public function testFuncGetArgsRuleWorksCaseInsensitive() { $rule = new UnusedFormalParameter(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToInheritMethod * * @return void * @since 1.2.1 */ public function testRuleDoesNotApplyToInheritMethod() { $rule = new UnusedFormalParameter(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToImplementedAbstractMethod * * @return void * @since 1.2.1 */ public function testRuleDoesNotApplyToImplementedAbstractMethod() { $rule = new UnusedFormalParameter(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToImplementedInterfaceMethod * * @return void * @since 1.2.1 */ public function testRuleDoesNotApplyToImplementedInterfaceMethod() { $rule = new UnusedFormalParameter(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToMagicMethod * * @return void */ public function testRuleDoesNotApplyToMagicMethod() { $methods = array_filter($this->getClass()->getMethods(), function ($method) { return $method->getName() == '__call'; }); $rule = new UnusedFormalParameter(); $rule->setReport($this->getReportMock(0)); $rule->apply(reset($methods)); } /** * testRuleDoesNotApplyToMethodWithInheritdocAnnotation */ public function testRuleDoesNotApplyToMethodWithInheritdocAnnotation() { $rule = new UnusedFormalParameter(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToMethodWithInheritdocAnnotationCamelCase */ public function testRuleDoesNotApplyToMethodWithInheritdocAnnotationCamelCase() { $rule = new UnusedFormalParameter(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * @test * @return void * @since 2.0.0 */ public function testCompactFunctionRuleDoesNotApply() { $rule = new UnusedFormalParameter(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * @test * @return void * @since 2.0.0 */ public function testCompactFunctionRuleOnlyAppliesToUsedParameters() { $rule = new UnusedFormalParameter(); $rule->setReport($this->getReportMock(2)); $rule->apply($this->getMethod()); } /** * @test * @return void * @since 2.0.0 */ public function testCompactFunctionRuleWorksCaseInsensitive() { $rule = new UnusedFormalParameter(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * @test * @return void * @since 2.0.1 */ public function testNamespacedCompactFunctionRuleDoesNotApply() { $rule = new UnusedFormalParameter(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * @test * @return void * @since 2.0.1 */ public function testNamespacedCompactFunctionRuleOnlyAppliesToUsedParameters() { $rule = new UnusedFormalParameter(); $rule->setReport($this->getReportMock(2)); $rule->apply($this->getMethod()); } /** * @test * @return void * @since 2.0.1 */ public function testNamespacedCompactFunctionRuleWorksCaseInsensitive() { $rule = new UnusedFormalParameter(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToFormalParameterUsedInStringCompoundVariable * * * class Foo { * public function foo($bar) { * return "me_${bar}"; * } * } * * * @return void */ public function testRuleDoesNotApplyToFormalParameterUsedInStringCompoundVariable() { $rule = new UnusedFormalParameter(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToFormalParameterUsedAsParameterInStringCompoundVariable * * * class Foo { * public function foo($bar) { * return $this->baz("${bar}"); * } * * private function baz($bar) { * return "who ${bar}?"; * } * } * * * @return void */ public function testRuleDoesNotApplyToFormalParameterUsedAsParameterInStringCompoundVariable() { $rule = new UnusedFormalParameter(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/UnusedLocalVariableTest.php000066400000000000000000000447021360164303200242100ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule; use PHPMD\AbstractTest; /** * Test case for the unused local variable rule. * * @covers \PHPMD\Rule\UnusedLocalVariable * @covers \PHPMD\Rule\AbstractLocalVariable */ class UnusedLocalVariableTest extends AbstractTest { /** * testRuleAppliesToUnusedLocalVariable * * @return void */ public function testRuleAppliesToUnusedLocalVariable() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getMethod()); } /** * testInnerFunctionParametersDoNotHideUnusedVariables * * @return void */ public function testInnerFunctionParametersDoNotHideUnusedVariables() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getFunction()); } /** * testRuleAppliesToLocalVariableWithSameNameAsStaticProperty * * * class Foo * protected $baz = 42; * function bar() { * $baz = 23; * return self::$baz; * } * } * * * @return void */ public function testRuleAppliesToLocalVariableWithSameNameAsStaticProperty() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getMethod()); } /** * testRuleAppliesToLocalVariableWithSameNameAsStaticArrayProperty * * * class Foo * protected $baz = array(array(1=>42)); * function bar() { * $baz = 23; * return self::$baz[0][1]; * } * } * * * @return void */ public function testRuleAppliesToLocalVariableWithSameNameAsStaticArrayProperty() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getMethod()); } /** * testRuleDoesApplyToCompoundVariableInString * * * class Foo * function bar() { * $baz = 23; * return "${baz}_wibble"; * } * } * * * @return void */ public function testRuleDoesApplyToCompoundVariableInString() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToLocalVariableUsedInCompoundVariable * * * class Foo { * protected static $bar = 42; * public function baz() * { * $name = 'bar'; * return self::${$name}; * } * } * * * @return void */ public function testRuleDoesNotApplyToLocalVariableUsedInCompoundVariable() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToThisVariable * * @return void */ public function testRuleDoesNotApplyToThisVariable() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToStaticProperty * * @return void */ public function testRuleDoesNotApplyToStaticProperty() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToStaticArrayProperty * * @return void */ public function testRuleDoesNotApplyToStaticArrayProperty() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToMethodArgument * * * class Foo { * function bar() { * $baz = 42; * $this->foo($baz); * } * } * * * @return void */ public function testRuleDoesNotApplyToMethodArgument() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToStaticObjectProperty * * @return void */ public function testRuleDoesNotApplyToStaticObjectProperty() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToDynamicProperty * * @return void */ public function testRuleDoesNotApplyToDynamicProperty() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToUnusedParameters * * @return void */ public function testRuleDoesNotApplyToUnusedParameters() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToArgcSuperGlobal * * @return void */ public function testRuleDoesNotApplyToArgcSuperGlobal() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToArgvSuperGlobal * * @return void */ public function testRuleDoesNotApplyToArgvSuperGlobal() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToGlobalsSuperGlobal * * @return void */ public function testRuleDoesNotApplyToGlobalsSuperGlobal() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToCookieSuperGlobal * * @return void */ public function testRuleDoesNotApplyToCookieSuperGlobal() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToEnvSuperGlobal * * @return void */ public function testRuleDoesNotApplyToEnvSuperGlobal() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToFilesSuperGlobal * * @return void */ public function testRuleDoesNotApplyToFilesSuperGlobal() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToGetSuperGlobal * * @return void */ public function testRuleDoesNotApplyToGetSuperGlobal() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToPostSuperGlobal * * @return void */ public function testRuleDoesNotApplyToPostSuperGlobal() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToRequestSuperGlobal * * @return void */ public function testRuleDoesNotApplyToRequestSuperGlobal() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToSessionSuperGlobal * * @return void */ public function testRuleDoesNotApplyToSessionSuperGlobal() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToServerSuperGlobal * * @return void */ public function testRuleDoesNotApplyToServerSuperGlobal() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToHttpRawPostDataSuperGlobal * * @return void */ public function testRuleDoesNotApplyToHttpRawPostDataSuperGlobal() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToUnusedLocalVariableInFunction * * @return void */ public function testRuleDoesNotApplyToUnusedLocalVariableInFunction() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getFunction()); } /** * testRuleDoesNotApplyToUnusedLocalVariableInMethod * * @return void */ public function testRuleDoesNotApplyToUnusedLocalVariableInMethod() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToLocalVariableUsedAsArrayIndex * * * class Foo { * public function bar() { * foreach ($baz as $key) { * self::$values[$key] = 42; * } * } * } * * * @return void */ public function testRuleDoesNotApplyToLocalVariableUsedAsArrayIndex() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleAppliesToUnusedForeachKeyWhenNotIgnored * * @return void */ public function testRuleAppliesToUnusedForeachKeyWhenNotIgnored() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getMethod()); } /** * testRuleAppliesToUnusedForeachValueWhenNotIgnored * * @return void */ public function testRuleAppliesToUnusedForeachValueWhenNotIgnored() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToUnusedForeachKeyWhenIgnored * * @return void */ public function testRuleDoesNotApplyToUnusedForeachKeyWhenIgnored() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'true'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToUnusedForeachKeyWhenWhitelisted * * @return void */ public function testRuleDoesNotApplyToUnusedForeachKeyWhenWhitelisted() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->addProperty('exceptions', '_'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotAppliesToWhitelistedUnusedLocaleVariable * * @return void */ public function testRuleDoesNotAppliesToWhitelistedUnusedLocaleVariable() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->addProperty('exceptions', '_'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleStillAppliesWhenSomeUnusedLocaleAreWhitelisted * * @return void */ public function testRuleStillAppliesWhenSomeUnusedLocaleAreWhitelisted() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->addProperty('exceptions', '_'); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToUnusedForeachValueWhenIgnored * * @return void */ public function testRuleDoesNotApplyToUnusedForeachValueWhenIgnored() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'true'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToLocalVariableUsedAsStringIndex * * * class Foo { * public function bar() { * foreach ($baz as $key) { * self::$string{$key} = 'a'; * } * } * } * * * @return void */ public function testRuleDoesNotApplyToLocalVariableUsedAsStringIndex() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToCatchStatement * * * class Foo { * public function bar() { * try { * } catch (Exception $e) { * } * } * } * * * @return void */ public function testRuleDoesNotApplyToCatchStatement() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToCompactFunction * * * class Foo { * public function bar() { * $key = 'ok'; * return compact('key'); * } * } * * * @return void */ public function testRuleDoesNotApplyToCompactFunction() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * @test * @return void * @since 2.0.0 */ public function testCompactFunctionRuleWorksCaseInsensitive() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleDoesNotApplyToNamespacedCompactFunction * * * namespace Baz; * * class Foo { * public function bar() { * $key = 'ok'; * return compact('key'); * } * } * * * @return void */ public function testRuleDoesNotApplyToNamespacedCompactFunction() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * @test * @return void * @since 2.0.1 */ public function testNamespacedCompactFunctionRuleWorksCaseInsensitive() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getMethod()); } /** * testRuleNotAppliesToPredefinedVariables.php * * @return void */ public function testRuleNotAppliesToPredefinedVariables() { $rule = new UnusedLocalVariable(); $rule->addProperty('allow-unused-foreach-variables', 'false'); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getMethod()); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/UnusedPrivateFieldTest.php000066400000000000000000000157651360164303200240750ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule; use PHPMD\AbstractTest; /** * Test case for the unused private field rule. * * @covers \PHPMD\Rule\UnusedPrivateField */ class UnusedPrivateFieldTest extends AbstractTest { /** * testRuleAppliesToUnusedPrivateField * * @return void */ public function testRuleAppliesToUnusedPrivateField() { $rule = new UnusedPrivateField(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getClass()); } /** * testRuleAppliesToUnusedPrivateStaticField * * @return void */ public function testRuleAppliesWhenFieldWithSameNameIsAccessedOnDifferentObject() { $rule = new UnusedPrivateField(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getClass()); } /** * testRuleAppliesToUnusedPrivateStaticField * * @return void */ public function testRuleAppliesToUnusedPrivateStaticField() { $rule = new UnusedPrivateField(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getClass()); } /** * testRuleAppliesWhenStaticFieldWithSameNameIsAccessedOnDifferentClass * * @return void */ public function testRuleAppliesWhenStaticFieldWithSameNameIsAccessedOnDifferentClass() { $rule = new UnusedPrivateField(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getClass()); } /** * testRuleAppliesWhenStaticFieldWithSameNameIsAccessedOnParent * * @return void */ public function testRuleAppliesWhenStaticFieldWithSameNameIsAccessedOnParent() { $rule = new UnusedPrivateField(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getClass()); } /** * testRuleAppliesWhenLocalVariableIsUsedInStaticMemberPrefix * * * class Foo { * private static $_bar = null; * * public function baz() { * self::${$_bar = '_bar'} = 42; * } * } * * * @return void */ public function testRuleAppliesWhenLocalVariableIsUsedInStaticMemberPrefix() { $rule = new UnusedPrivateField(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getClass()); } /** * testRuleAppliesWhenLocalVariableIsUsedInStaticMemberPrefix * * * class Foo { * private static $_bar = null; * * public function baz() { * self::${'_bar'} = 42; * } * } * * * @return void */ public function testRuleDoesNotResultInFatalErrorByCallingNonObject() { $rule = new UnusedPrivateField(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getClass()); } /** * testRuleDoesNotApplyToUnusedPublicField * * @return void */ public function testRuleDoesNotApplyToUnusedPublicField() { $rule = new UnusedPrivateField(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } /** * testRuleDoesNotApplyToUnusedProtectedField * * @return void */ public function testRuleDoesNotApplyToUnusedProtectedField() { $rule = new UnusedPrivateField(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } /** * testRuleDoesNotApplyToThisAccessedPrivateField * * @return void */ public function testRuleDoesNotApplyToThisAccessedPrivateField() { $rule = new UnusedPrivateField(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } /** * testRuleDoesNotApplyToSelfAccessedPrivateField * * @return void */ public function testRuleDoesNotApplyToSelfAccessedPrivateField() { $rule = new UnusedPrivateField(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } /** * testRuleDoesNotApplyToStaticAccessedPrivateField * * @return void */ public function testRuleDoesNotApplyToStaticAccessedPrivateField() { $rule = new UnusedPrivateField(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } /** * testRuleDoesNotApplyToClassNameAccessedPrivateField * * @return void */ public function testRuleDoesNotApplyToClassNameAccessedPrivateField() { $rule = new UnusedPrivateField(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } /** * testRuleDoesNotApplyToPrivateFieldInChainedMethodCall * * * class Foo { * private $bar = null; * // ... * public function baz() { * $this->bar->foobar(); * } * } * * * @return void */ public function testRuleDoesNotApplyToPrivateFieldInChainedMethodCall() { $rule = new UnusedPrivateField(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } /** * testRuleDoesNotApplyToPrivateArrayFieldAccess * * * class Foo { * private $bar = array(); * // ... * public function baz() { * return $this->bar[42]; * } * } * * * @return void */ public function testRuleDoesNotApplyToPrivateArrayFieldAccess() { $rule = new UnusedPrivateField(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } /** * testRuleDoesNotApplyToPrivateStringIndexFieldAccess * * * class Foo { * private $bar = "Manuel"; * // ... * public function baz() { * return $this->bar{3}; * } * } * * * @return void */ public function testRuleDoesNotApplyToPrivateStringIndexFieldAccess() { $rule = new UnusedPrivateField(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } /** * testRuleDoesNotApplyToFieldWithMethodsThatReturnArray * * @return void */ public function testRuleDoesNotApplyToFieldWithMethodsThatReturnArray() { $rule = new UnusedPrivateField(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } } phpmd-2.8.1/src/test/php/PHPMD/Rule/UnusedPrivateMethodTest.php000066400000000000000000000142231360164303200242560ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Rule; use PHPMD\AbstractTest; /** * Test case for the unused private method rule. * * @covers \PHPMD\Rule\UnusedPrivateMethod */ class UnusedPrivateMethodTest extends AbstractTest { /** * testRuleAppliesToUnusedPrivateMethod * * @return void */ public function testRuleAppliesToUnusedPrivateMethod() { $rule = new UnusedPrivateMethod(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getClass()); } /** * testRuleAppliesToUnusedStaticPrivateMethod * * @return void */ public function testRuleAppliesToUnusedStaticPrivateMethod() { $rule = new UnusedPrivateMethod(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getClass()); } /** * testRuleAppliesToParentReferencedUnusedPrivateMethod * * @return void */ public function testRuleAppliesToParentReferencedUnusedPrivateMethod() { $rule = new UnusedPrivateMethod(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getClass()); } /** * testRuleAppliesWhenMethodIsReferencedOnDifferentObject * * @return void */ public function testRuleAppliesWhenMethodIsReferencedOnDifferentObject() { $rule = new UnusedPrivateMethod(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getClass()); } /** * testRuleAppliesWhenMethodIsReferencedOnDifferentClass * * @return void */ public function testRuleAppliesWhenMethodIsReferencedOnDifferentClass() { $rule = new UnusedPrivateMethod(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getClass()); } /** * testRuleAppliesWhenPropertyWithSimilarNameIsReferenced * * @return void */ public function testRuleAppliesWhenPropertyWithSimilarNameIsReferenced() { $rule = new UnusedPrivateMethod(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getClass()); } /** * testRuleAppliesWhenMethodWithSimilarNameIsInInvocationChain * * * class Foo { * protected $bar; * private function baz(); * public function doIt() { * $this->bar->baz(); * } * } * * * @return void */ public function testRuleAppliesWhenMethodWithSimilarNameIsInInvocationChain() { $rule = new UnusedPrivateMethod(); $rule->setReport($this->getReportMock(1)); $rule->apply($this->getClass()); } /** * testRuleDoesNotApplyToPrivateConstructor * * @return void */ public function testRuleDoesNotApplyToPrivateConstructor() { $rule = new UnusedPrivateMethod(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } /** * testRuleDoesNotApplyToPrivatePhp4Constructor * * @return void */ public function testRuleDoesNotApplyToPrivatePhp4Constructor() { $rule = new UnusedPrivateMethod(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } /** * testRuleDoesNotApplyToPrivateCloneMethod * * @return void */ public function testRuleDoesNotApplyToPrivateCloneMethod() { $rule = new UnusedPrivateMethod(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } /** * testRuleDoesNotApplyToThisReferencedMethod * * @return void */ public function testRuleDoesNotApplyToThisReferencedMethod() { $rule = new UnusedPrivateMethod(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } /** * testRuleDoesNotApplyToSelfReferencedMethod * * @return void */ public function testRuleDoesNotApplyToSelfReferencedMethod() { $rule = new UnusedPrivateMethod(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } /** * testRuleDoesNotApplyToStaticReferencedMethod * * @return void */ public function testRuleDoesNotApplyToStaticReferencedMethod() { $rule = new UnusedPrivateMethod(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } /** * testRuleDoesNotApplyToClassNameReferencedMethod * * @return void */ public function testRuleDoesNotApplyToClassNameReferencedMethod() { $rule = new UnusedPrivateMethod(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } /** * testRuleDoesNotApplyToPrivateMethodInChainedMethodCall * * * class Foo { * private function bar() { * return new \SplObjectStorage(); * } * public function add($object) { * $this->bar()->attach($object); * } * } * * * @return void */ public function testRuleDoesNotApplyToPrivateMethodInChainedMethodCall() { $rule = new UnusedPrivateMethod(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } /** * testRuleDoesNotApplyToPrivateMethodInChainedMethodCallInNumberBiggerThanTwo * * @return void */ public function testRuleDoesNotApplyToPrivateMethodInChainedMethodCallInNumberBiggerThanTwo() { $rule = new UnusedPrivateMethod(); $rule->setReport($this->getReportMock(0)); $rule->apply($this->getClass()); } } phpmd-2.8.1/src/test/php/PHPMD/RuleSetFactoryTest.php000066400000000000000000000563571360164303200223410ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD; use org\bovigo\vfs\vfsStream; /** * Test case for the rule set factory class. * * @covers \PHPMD\RuleSetFactory */ class RuleSetFactoryTest extends AbstractTest { /** * Used to test files/directories access for ignore code rule * * @var string */ const DIR_UNDER_TESTS = 'designăôü0汉字'; /** * testCreateRuleSetFileNameFindsXmlFileInBundledRuleSets * * @return void */ public function testCreateRuleSetFileNameFindsXmlFileInBundledRuleSets() { $factory = new RuleSetFactory(); $ruleSet = $factory->createSingleRuleSet('codesize'); $this->assertContains('The Code Size Ruleset', $ruleSet->getDescription()); } /** * testCreateRuleSetFileNameFindsXmlFileInCurrentWorkingDirectory * * @return void */ public function testCreateRuleSetFileNameFindsXmlFileInCurrentWorkingDirectory() { self::changeWorkingDirectory('rulesets'); $factory = new RuleSetFactory(); $ruleSet = $factory->createSingleRuleSet('set1.xml'); $this->assertEquals('First description...', $ruleSet->getDescription()); } /** * testCreateRuleSetsReturnsArray * * @return void */ public function testCreateRuleSetsReturnsArray() { $ruleSets = $this->createRuleSetsFromAbsoluteFiles('rulesets/set1.xml'); $this->assertInternalType('array', $ruleSets); } /** * testCreateRuleSetsForSingleFileReturnsArrayWithOneElement * * @return void */ public function testCreateRuleSetsForSingleFileReturnsArrayWithOneElement() { $ruleSets = $this->createRuleSetsFromAbsoluteFiles('rulesets/set1.xml'); $this->assertEquals(1, count($ruleSets)); } /** * testCreateRuleSetsForSingleFileReturnsOneRuleSetInstance * * @return void */ public function testCreateRuleSetsForSingleFileReturnsOneRuleSetInstance() { $ruleSets = $this->createRuleSetsFromAbsoluteFiles('rulesets/set1.xml'); $this->assertInstanceOf('PHPMD\\RuleSet', $ruleSets[0]); } /** * testCreateRuleSetsConfiguresExpectedRuleSetName * * @return void */ public function testCreateRuleSetsConfiguresExpectedRuleSetName() { $ruleSets = $this->createRuleSetsFromAbsoluteFiles('rulesets/set1.xml'); $this->assertEquals('First Test RuleSet', $ruleSets[0]->getName()); } /** * testCreateRuleSetsConfiguresExpectedRuleSetName * * @return void */ public function testCreateRuleSetsConfiguresExpectedRuleSetDescription() { $ruleSets = $this->createRuleSetsFromAbsoluteFiles('rulesets/set1.xml'); $this->assertEquals('First description...', $ruleSets[0]->getDescription()); } /** * testCreateRuleSetsForTwoFilesReturnsArrayWithTwoElements * * @return void */ public function testCreateRuleSetsForTwoFilesReturnsArrayWithTwoElements() { $ruleSets = $this->createRuleSetsFromAbsoluteFiles( 'rulesets/set1.xml', 'rulesets/set2.xml' ); $this->assertEquals(2, count($ruleSets)); } /** * testCreateRuleSetsForTwoFilesReturnsExpectedRuleSetInstances * * @return void */ public function testCreateRuleSetsForTwoFilesReturnsExpectedRuleSetInstances() { $ruleSets = $this->createRuleSetsFromAbsoluteFiles( 'rulesets/set1.xml', 'rulesets/set2.xml' ); $this->assertInstanceOf('PHPMD\\RuleSet', $ruleSets[0]); $this->assertInstanceOf('PHPMD\\RuleSet', $ruleSets[1]); } /** * testCreateRuleSetsForTwoConfiguresExpectedRuleSetNames * * @return void */ public function testCreateRuleSetsForTwoConfiguresExpectedRuleSetNames() { $ruleSets = $this->createRuleSetsFromAbsoluteFiles( 'rulesets/set1.xml', 'rulesets/set2.xml' ); $this->assertEquals('First Test RuleSet', $ruleSets[0]->getName()); $this->assertEquals('Second Test RuleSet', $ruleSets[1]->getName()); } /** * testCreateRuleSetsForTwoConfiguresExpectedRuleSetDescriptions * * @return void */ public function testCreateRuleSetsForTwoConfiguresExpectedRuleSetDescriptions() { $ruleSets = $this->createRuleSetsFromAbsoluteFiles( 'rulesets/set1.xml', 'rulesets/set2.xml' ); $this->assertSame('First description...', $ruleSets[0]->getDescription()); $this->assertSame('Second description...', $ruleSets[1]->getDescription()); } /** * testCreateRuleSetsForSingleLocalFileNameReturnsArray * * @return void */ public function testCreateRuleSetsForLocalFileNameReturnsArray() { self::changeWorkingDirectory(); $ruleSets = $this->createRuleSetsFromFiles('rulesets/set1.xml'); $this->assertInternalType('array', $ruleSets); } /** * testCreateRuleSetsForSingleLocalFileNameReturnsArrayWithOneElement * * @return void */ public function testCreateRuleSetsForLocalFileNameReturnsArrayWithOneElement() { self::changeWorkingDirectory(); $ruleSets = $this->createRuleSetsFromFiles('rulesets/set1.xml'); $this->assertEquals(1, count($ruleSets)); } /** * testCreateRuleSetsForSingleLocalFileNameConfiguresExpectedRuleSetName * * @return void */ public function testCreateRuleSetsForLocalFileNameConfiguresExpectedRuleSetName() { self::changeWorkingDirectory(); $ruleSets = $this->createRuleSetsFromFiles('rulesets/set1.xml'); $this->assertEquals('First Test RuleSet', $ruleSets[0]->getName()); } /** * testCreateRuleSetsWithReferenceContainsExpectedRuleSet * * @return void */ public function testCreateRuleSetsWithReferenceContainsExpectedRuleSet() { self::changeWorkingDirectory(); $ruleSets = $this->createRuleSetsFromAbsoluteFiles('rulesets/refset1.xml'); $this->assertEquals('First Test RuleSet', $ruleSets[0]->getName()); } /** * testCreateRuleSetsWithReferenceContainsExpectedNumberOfRules * * @return void */ public function testCreateRuleSetsWithReferenceContainsExpectedNumberOfRules() { self::changeWorkingDirectory(); $ruleSets = $this->createRuleSetsFromAbsoluteFiles('rulesets/refset1.xml'); $this->assertEquals(4, iterator_count($ruleSets[0])); } /** * testCreateRuleSetsForLocalFileWithRuleSetReferenceNodes * * @return void */ public function testCreateRuleSetsWithReferenceContainsRuleInstances() { self::changeWorkingDirectory(); $ruleSets = $this->createRuleSetsFromAbsoluteFiles('rulesets/refset1.xml'); $this->assertInstanceOf('PHPMD\\AbstractRule', $ruleSets[0]->getRules()->current()); } /** * testCreateRuleSetsWithReferenceContainsExpectedRules * * @return void */ public function testCreateRuleSetsWithReferenceContainsExpectedRules() { self::changeWorkingDirectory(); $ruleSets = $this->createRuleSetsFromAbsoluteFiles('rulesets/refset2.xml'); $actual = array(); $expected = array('RuleTwoInFirstRuleSet', 'RuleOneInSecondRuleSet'); foreach ($ruleSets[0]->getRules() as $rule) { $actual[] = $rule->getName(); } $this->assertEquals($expected, $actual); } /** * testCreateSingleRuleSetReturnsRuleSetInstance * * @return void */ public function testCreateSingleRuleSetReturnsRuleSetInstance() { self::changeWorkingDirectory(); $factory = new RuleSetFactory(); $ruleSet = $factory->createSingleRuleSet('set1'); $this->assertInstanceOf('PHPMD\\RuleSet', $ruleSet); } /** * Tests that the rule-set factory applies a set minimum priority filter correct. * * @return void */ public function testCreateRuleSetWithSpecifiedMinimumPriorityOnlyContainsMatchingRules() { self::changeWorkingDirectory(); $factory = new RuleSetFactory(); $factory->setMinimumPriority(2); $ruleSet = $factory->createSingleRuleSet('set1'); $this->assertSame(1, iterator_count($ruleSet->getRules())); } /** * Tests that the rule-set factory applies a set maximum priority filter correct. * * @return void */ public function testCreateRuleSetWithSpecifiedMaximumPriorityOnlyContainsMatchingRules() { self::changeWorkingDirectory(); $factory = new RuleSetFactory(); $factory->setMaximumPriority(2); $ruleSet = $factory->createSingleRuleSet('set1'); $this->assertSame(1, iterator_count($ruleSet->getRules())); } /** * Tests that the rule-set factory applies a set maximum priority filter correct. * * @return void */ public function testCreateRuleSetWithSpecifiedPrioritiesOnlyContainsMatchingRules() { self::changeWorkingDirectory(); $factory = new RuleSetFactory(); $factory->setMinimumPriority(2); $factory->setMaximumPriority(2); $ruleSet = $factory->createSingleRuleSet('set1'); $this->assertCount(0, $ruleSet->getRules()); } /** * testCreateRuleWithExcludePattern * * @return void */ public function testCreateRuleWithExcludePattern() { self::changeWorkingDirectory(); $factory = new RuleSetFactory(); $excludes = $factory->getIgnorePattern('exclude-pattern'); $expected = array( 'some/excluded/files' ); $this->assertEquals($expected, $excludes); } /** * testCreateRuleSetsWithRuleReferenceThatOverwritesPrioritySetting * * @return void */ public function testCreateRuleSetsWithRuleReferenceThatOverwritesPrioritySetting() { self::changeWorkingDirectory(); $factory = new RuleSetFactory(); $ruleSets = $factory->createRuleSets('refset3'); $rule = $ruleSets[0]->getRules()->current(); $this->assertSame(4, $rule->getPriority()); } /** * testCreateRuleWithExpectedExample * * @return void */ public function testCreateRuleWithExpectedExample() { self::changeWorkingDirectory(); $factory = new RuleSetFactory(); $ruleSets = $factory->createRuleSets('set1'); $rule = $ruleSets[0]->getRules()->current(); $this->assertEquals(array(__FUNCTION__), $rule->getExamples()); } /** * testCreateRuleWithExpectedMultipleExamples * * @return void */ public function testCreateRuleWithExpectedMultipleExamples() { self::changeWorkingDirectory(); $factory = new RuleSetFactory(); $ruleSets = $factory->createRuleSets('set2'); $rule = $ruleSets[0]->getRules()->current(); $this->assertEquals(array(__FUNCTION__ . 'One', __FUNCTION__ . 'Two'), $rule->getExamples()); } /** * testCreateRuleSetsWithRuleReferenceThatOverwritesDescriptionSetting * * @return void */ public function testCreateRuleSetsWithRuleReferenceThatOverwritesDescriptionSetting() { self::changeWorkingDirectory(); $factory = new RuleSetFactory(); $ruleSets = $factory->createRuleSets('refset3'); $rule = $ruleSets[0]->getRules()->current(); $this->assertSame('description 42', $rule->getDescription()); } /** * testCreateRuleSetsWithRuleReferenceThatOverwritesPropertySetting * * @return void */ public function testCreateRuleSetsWithRuleReferenceThatOverwritesPropertySetting() { self::changeWorkingDirectory(); $factory = new RuleSetFactory(); $ruleSets = $factory->createRuleSets('refset3'); $rule = $ruleSets[0]->getRules()->current(); $this->assertSame(42, $rule->getIntProperty('foo')); } /** * testFactorySupportsAlternativeSyntaxForPropertyValue * * @return void */ public function testFactorySupportsAlternativeSyntaxForPropertyValue() { self::changeWorkingDirectory(); $factory = new RuleSetFactory(); $ruleSets = $factory->createRuleSets('alternative-property-value-syntax'); $rule = $ruleSets[0]->getRules()->current(); $this->assertSame(42, $rule->getIntProperty('foo')); } /** * testCreateRuleSetsWithRuleReferenceThatOverwritesExamplesSetting * * @return void */ public function testCreateRuleSetsWithRuleReferenceThatOverwritesExamplesSetting() { self::changeWorkingDirectory(); $factory = new RuleSetFactory(); $ruleSets = $factory->createRuleSets('refset3'); $rule = $ruleSets[0]->getRules()->current(); $examples = $rule->getExamples(); $this->assertEquals('foreach ($foo as $bar) { echo $bar; }', $examples[0]); } /** * testCreateRuleSetsWithRuleReferenceThatOverwritesExamplesSetting * * @return void */ public function testCreateRuleSetsWithRuleReferenceThatOverwritesNameSetting() { self::changeWorkingDirectory(); $factory = new RuleSetFactory(); $ruleSets = $factory->createRuleSets('refset4'); $rule = $ruleSets[0]->getRules()->current(); $this->assertEquals('Name overwritten', $rule->getName()); } /** * testCreateRuleSetsWithRuleReferenceThatOverwritesMessageSetting * * @return void */ public function testCreateRuleSetsWithRuleReferenceThatOverwritesMessageSetting() { self::changeWorkingDirectory(); $factory = new RuleSetFactory(); $ruleSets = $factory->createRuleSets('refset4'); $rule = $ruleSets[0]->getRules()->current(); $this->assertEquals('Message overwritten', $rule->getMessage()); } /** * testCreateRuleSetsWithRuleReferenceThatOverwritesExtInfoUrlSetting * * @return void */ public function testCreateRuleSetsWithRuleReferenceThatOverwritesExtInfoUrlSetting() { self::changeWorkingDirectory(); $factory = new RuleSetFactory(); $ruleSets = $factory->createRuleSets('refset4'); $rule = $ruleSets[0]->getRules()->current(); $this->assertEquals('http://example.com/overwritten', $rule->getExternalInfoUrl()); } /** * testCreateRuleSetsWithRuleReferenceNotContainsExcludedRule * * @return void */ public function testCreateRuleSetsWithRuleReferenceNotContainsExcludedRule() { self::changeWorkingDirectory(); $factory = new RuleSetFactory(); $ruleSets = $factory->createRuleSets('refset-exclude-one'); $rules = $ruleSets[0]->getRules(); $this->assertEquals(1, iterator_count($rules)); } /** * testCreateRuleSetsWithRuleReferenceNotContainsExcludedRules * * @return void */ public function testCreateRuleSetsWithRuleReferenceNotContainsExcludedRules() { self::changeWorkingDirectory(); $factory = new RuleSetFactory(); $ruleSets = $factory->createRuleSets('refset-exclude-all'); $rules = $ruleSets[0]->getRules(); $this->assertEquals(0, iterator_count($rules)); } /** * Tests that the factory throws the expected exception for an invalid ruleset * identifier. * * @return void * @covers \PHPMD\RuleSetNotFoundException */ public function testCreateRuleSetsThrowsExceptionForInvalidIdentifier() { $factory = new RuleSetFactory(); $this->setExpectedException( 'PHPMD\\RuleSetNotFoundException', 'Cannot find specified rule-set "foo-bar-ruleset-23".' ); $factory->createRuleSets('foo-bar-ruleset-23'); } /** * Tests that the factory throws an exception when the source code filename * for the configured rule does not exist. * * @return void * @covers \PHPMD\RuleClassFileNotFoundException */ public function testCreateRuleSetsThrowsExceptionWhenClassFileNotInIncludePath() { $fileName = self::createFileUri('rulesets/set-class-file-not-found.xml'); $factory = new RuleSetFactory(); $this->setExpectedException( 'PHPMD\\RuleClassFileNotFoundException', 'Cannot load source file for class: PHPMD\\Stubs\\ClassFileNotFoundRule' ); $factory->createRuleSets($fileName); } /** * Tests that the factory throws the expected exception when a rule class * cannot be found. * * @return void * @covers \PHPMD\RuleClassNotFoundException */ public function testCreateRuleSetThrowsExceptionWhenFileNotContainsClass() { $fileName = self::createFileUri('rulesets/set-class-not-found.xml'); $factory = new RuleSetFactory(); $this->setExpectedException( 'PHPMD\\RuleClassNotFoundException', 'Cannot find rule class: PHPMD\\Stubs\\ClassNotFoundRule' ); $factory->createRuleSets($fileName); } /** * Tests that the factory throws the expected exception when a rule class * cannot be found. * * @return void * @covers \PHPMD\RuleClassNotFoundException * @expectedException \RuntimeException */ public function testCreateRuleSetsThrowsExpectedExceptionForInvalidXmlFile() { $fileName = self::createFileUri('rulesets/set-invalid-xml.xml'); $factory = new RuleSetFactory(); $factory->createRuleSets($fileName); } /** * testCreateRuleSetsActivatesStrictModeOnRuleSet * * @return void */ public function testCreateRuleSetsActivatesStrictModeOnRuleSet() { $fileName = self::createFileUri('rulesets/set1.xml'); $factory = new RuleSetFactory(); $factory->setStrict(); $ruleSets = $factory->createRuleSets($fileName); $this->assertAttributeEquals(true, 'strict', $ruleSets[0]); } /** * Tests that adding an include-path via ruleset works. * Also implicitly tests (by parsing the ruleset) that * reference-by-includepath and explicit-classfile-declaration works. * * @return void * @throws \Exception */ public function testAddPHPIncludePath() { $includePathBefore = get_include_path(); $rulesetFilepath = 'rulesets/ruleset-refs.xml'; $fileName = self::createFileUri($rulesetFilepath); try { $factory = new RuleSetFactory(); $factory->createRuleSets($fileName); $expectedIncludePath = "/foo/bar/baz"; $actualIncludePaths = explode(PATH_SEPARATOR, get_include_path()); $isIncludePathPresent = in_array($expectedIncludePath, $actualIncludePaths); } catch (\Exception $exception) { set_include_path($includePathBefore); throw $exception; } set_include_path($includePathBefore); $this->assertTrue( $isIncludePathPresent, "The include-path from '{$rulesetFilepath}' was not set!" ); } /** * Checks if PHPMD doesn't treat directories named as code rule as files * * @return void * @link https://github.com/phpmd/phpmd/issues/47 */ public function testIfGettingRuleFilePathExcludeUnreadablePaths() { self::changeWorkingDirectory(__DIR__); $factory = new RuleSetFactory(); $runtimeExceptionCount = 0; $ruleSetNotFoundExceptionCount = 0; foreach ($this->getPathsForFileAccessTest() as $path) { try { $this->assertEquals( array('some/excluded/files'), $factory->getIgnorePattern($path . self::DIR_UNDER_TESTS) ); } catch (RuleSetNotFoundException $e) { $ruleSetNotFoundExceptionCount++; } catch (\RuntimeException $e) { $runtimeExceptionCount++; } } $this->assertEquals(0, $runtimeExceptionCount); $this->assertEquals(5, $ruleSetNotFoundExceptionCount); } /** * Invokes the createRuleSets() of the {@link RuleSetFactory} * class. * * @param string $file At least one rule configuration file name. You can * also pass multiple parameters with ruleset configuration files. * @return \PHPMD\RuleSet[] */ private function createRuleSetsFromAbsoluteFiles($file) { $files = (1 === func_num_args() ? array($file) : func_get_args()); $files = array_map(array(__CLASS__, 'createFileUri'), $files); return call_user_func_array(array($this, 'createRuleSetsFromFiles'), $files); } /** * Invokes the createRuleSets() of the {@link RuleSetFactory} * class. * * @param string $file At least one rule configuration file name. You can * also pass multiple parameters with ruleset configuration files. * @return \PHPMD\RuleSet[] */ private function createRuleSetsFromFiles($file) { $args = func_get_args(); $factory = new RuleSetFactory(); return $factory->createRuleSets(join(',', $args)); } /** * Sets up files and directories for XML rule file access test * * @return array Paths to test against */ public function getPathsForFileAccessTest() { $fileContent = file_get_contents(__DIR__ . '/../../resources/files/rulesets/exclude-pattern.xml'); $structure = array( 'dir1' => array( self::DIR_UNDER_TESTS => array(), // directory - skipped 'foo' => array(), // directory, criteria do not apply ), 'dir2' => array( self::DIR_UNDER_TESTS => array(), // directory, wrong permissions ), 'dir3' => array( self::DIR_UNDER_TESTS => array(), // directory, wrong owner and group ), 'dirÅ' => array( // check UTF-8 characters handling 'foo' => array( self::DIR_UNDER_TESTS => $fileContent, // wrong permissions ), 'bar' => array( self::DIR_UNDER_TESTS => $fileContent, // OK ), ), ); $root = vfsStream::setup('root', null, $structure); $root->getChild('dir2/' . self::DIR_UNDER_TESTS)->chmod(000); $root->getChild('dir3/' . self::DIR_UNDER_TESTS)->chown(vfsStream::OWNER_ROOT)->chgrp(vfsStream::GROUP_ROOT); $root->getChild('dirÅ/foo/' . self::DIR_UNDER_TESTS)->chmod(000); return array( $root->url(), $root->url() . '/dir1/', $root->url() . '/dir2/', $root->url() . '/dir3/', $root->url() . '/dirÅ/foo/', $root->url() . '/dirÅ/bar/', ); } } phpmd-2.8.1/src/test/php/PHPMD/RuleSetTest.php000066400000000000000000000051471360164303200210000ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD; use PHPMD\Stubs\RuleStub; /** * Test case for the {@link \PHPMD\RuleSet} class. * * @covers \PHPMD\RuleSet */ class RuleSetTest extends AbstractTest { /** * testGetRuleByNameReturnsNullWhenNoMatchingRuleExists * * @return void */ public function testGetRuleByNameReturnsNullWhenNoMatchingRuleExists() { $ruleSet = $this->createRuleSetFixture(); $this->assertNull($ruleSet->getRuleByName(__FUNCTION__)); } /** * testGetRuleByNameReturnsMatchingRuleInstance * * @return void */ public function testGetRuleByNameReturnsMatchingRuleInstance() { $ruleSet = $this->createRuleSetFixture(__FUNCTION__, __CLASS__, __METHOD__); $rule = $ruleSet->getRuleByName(__CLASS__); $this->assertEquals(__CLASS__, $rule->getName()); } /** * testApplyNotInvokesRuleWhenSuppressAnnotationExists * * @return void */ public function testApplyNotInvokesRuleWhenSuppressAnnotationExists() { $ruleSet = $this->createRuleSetFixture(__FUNCTION__); $ruleSet->setReport($this->getReportMock(0)); $ruleSet->apply($this->getClass()); $this->assertNull($ruleSet->getRuleByName(__FUNCTION__)->node); } /** * testApplyInvokesRuleWhenStrictModeIsSet * * @return void */ public function testApplyInvokesRuleWhenStrictModeIsSet() { $ruleSet = $this->createRuleSetFixture(__FUNCTION__); $ruleSet->setReport($this->getReportMock(0)); $ruleSet->setStrict(); $class = $this->getClass(); $ruleSet->apply($class); $this->assertSame($class, $ruleSet->getRuleByName(__FUNCTION__)->node); } /** * Creates a rule set instance with a variable amount of appended rule * objects. * * @return \PHPMD\AbstractRule */ private function createRuleSetFixture() { $ruleSet = new RuleSet(); for ($i = 0; $i < func_num_args(); ++$i) { $rule = new RuleStub(func_get_arg($i)); $ruleSet->addRule($rule); } return $ruleSet; } } phpmd-2.8.1/src/test/php/PHPMD/RuleTest.php000066400000000000000000000077061360164303200203270ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD; /** * Test case for the {@link \PHPMD\AbstractRule} class. * * @covers \PHPMD\AbstractRule */ class RuleTest extends AbstractTest { /** * testGetIntPropertyReturnsValueOfTypeInteger * * @return void */ public function testGetIntPropertyReturnsValueOfTypeInteger() { $rule = $this->getMockForAbstractClass('PHPMD\\AbstractRule'); $rule->addProperty(__FUNCTION__, '42.3'); $this->assertSame(42, $rule->getIntProperty(__FUNCTION__)); } /** * testGetBooleanPropertyReturnsTrueForStringValue1 * * @return void */ public function testGetBooleanPropertyReturnsTrueForStringValue1() { $rule = $this->getMockForAbstractClass('PHPMD\\AbstractRule'); $rule->addProperty(__FUNCTION__, '1'); $this->assertTrue($rule->getBooleanProperty(__FUNCTION__)); } /** * testGetBooleanPropertyReturnsTrueForStringValueOn * * @return void */ public function testGetBooleanPropertyReturnsTrueForStringValueOn() { $rule = $this->getMockForAbstractClass('PHPMD\\AbstractRule'); $rule->addProperty(__FUNCTION__, 'on'); $this->assertTrue($rule->getBooleanProperty(__FUNCTION__)); } /** * testGetBooleanPropertyReturnsTrueForStringValueTrue * * @return void */ public function testGetBooleanPropertyReturnsTrueForStringValueTrue() { $rule = $this->getMockForAbstractClass('PHPMD\\AbstractRule'); $rule->addProperty(__FUNCTION__, 'true'); $this->assertTrue($rule->getBooleanProperty(__FUNCTION__)); } /** * testGetBooleanPropertyReturnsTrueForDifferentStringValue * * @return void */ public function testGetBooleanPropertyReturnsTrueForDifferentStringValue() { $rule = $this->getMockForAbstractClass('PHPMD\\AbstractRule'); $rule->addProperty(__FUNCTION__, 'True'); $this->assertFalse($rule->getBooleanProperty(__FUNCTION__)); } /** * testGetIntPropertyThrowsExceptionWhenNoPropertyForNameExists * * @return void * @expectedException \OutOfBoundsException */ public function testGetIntPropertyThrowsExceptionWhenNoPropertyForNameExists() { $rule = $this->getMockForAbstractClass('PHPMD\\AbstractRule'); $rule->getIntProperty(__FUNCTION__); } /** * testGetBooleanPropertyThrowsExceptionWhenNoPropertyForNameExists * * @return void * @expectedException \OutOfBoundsException */ public function testGetBooleanPropertyThrowsExceptionWhenNoPropertyForNameExists() { $rule = $this->getMockForAbstractClass('PHPMD\\AbstractRule'); $rule->getBooleanProperty(__FUNCTION__); } /** * testStringPropertyThrowsExceptionWhenNoPropertyForNameExists * * @return void * @expectedException \OutOfBoundsException */ public function testGetStringPropertyThrowsExceptionWhenNoPropertyForNameExists() { $rule = $this->getMockForAbstractClass('PHPMD\\AbstractRule'); $rule->getStringProperty(__FUNCTION__); } /** * testGetStringPropertyReturnsStringValue * * @return void */ public function testGetStringPropertyReturnsString() { $rule = $this->getMockForAbstractClass('PHPMD\\AbstractRule'); $rule->addProperty(__FUNCTION__, 'Fourty Two'); $this->assertSame('Fourty Two', $rule->getStringProperty(__FUNCTION__)); } } phpmd-2.8.1/src/test/php/PHPMD/RuleViolationTest.php000066400000000000000000000034601360164303200222050ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD; /** * Test case for the {@link \PHPMD\RuleViolation} class. * * @since 0.2.5 * * @covers \PHPMD\RuleViolation */ class RuleViolationTest extends AbstractTest { /** * testConstructorExtractsClassNameFromGivenType * * @return void */ public function testConstructorExtractsClassNameFromGivenType() { $rule = $this->getRuleMock(); $node = $this->getClassMock(); $node->expects($this->once()) ->method('getName'); new RuleViolation($rule, $node, 'foo'); } /** * testConstructorExtractsClassNameFromGivenMethod * * @return void */ public function testConstructorExtractsClassNameFromGivenMethod() { $rule = $this->getRuleMock(); $node = $this->getMethodMock(); $node->expects($this->once()) ->method('getParentName'); new RuleViolation($rule, $node, 'foo'); } /** * testConstructorExtractsMethodNameFromGivenMethod * * @return void */ public function testConstructorExtractsMethodNameFromGivenMethod() { $rule = $this->getRuleMock(); $node = $this->getMethodMock(); $node->expects($this->once()) ->method('getName'); new RuleViolation($rule, $node, 'foo'); } } phpmd-2.8.1/src/test/php/PHPMD/Stubs/000077500000000000000000000000001360164303200171355ustar00rootroot00000000000000phpmd-2.8.1/src/test/php/PHPMD/Stubs/ClassNotFoundRule.php000066400000000000000000000010251360164303200232160ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ // Nothing, no class :-) phpmd-2.8.1/src/test/php/PHPMD/Stubs/RuleStub.php000066400000000000000000000030471360164303200214170ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Stubs; use PHPMD\AbstractNode; use PHPMD\AbstractRule; use PHPMD\Rule\ClassAware; /** * Simple rule stub implementation */ class RuleStub extends AbstractRule implements ClassAware { public $node = null; /** * Constructs a new rule stub instance. * * @param string $ruleName The rule name. * @param string $ruleSetName The rule-set name. */ public function __construct($ruleName = 'RuleStub', $ruleSetName = 'TestRuleSet') { $this->setName($ruleName); $this->setExternalInfoUrl('https://phpmd.org/rules/index.html'); $this->setRuleSetName($ruleSetName); $this->setSince('42.23'); $this->setDescription('Simple rule stub'); } /** * This method should implement the violation analysis algorithm of concrete * rule implementations. All extending classes must implement this method. * * @param \PHPMD\AbstractNode $node * @return void */ public function apply(AbstractNode $node) { $this->node = $node; } } phpmd-2.8.1/src/test/php/PHPMD/Stubs/WriterStub.php000066400000000000000000000024621360164303200217640ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Stubs; use PHPMD\AbstractWriter; /** * Simple test implementation of PHPMD's writer. */ class WriterStub extends AbstractWriter { /** * The written data chunks. * * @var array */ public $chunks = array(); /** * Writes a data string to the concrete output. * * @param string $data The data to write. * * @return void */ public function write($data) { $this->chunks[] = $data; } /** * Returns a concated string of all data chunks. * * @return string */ public function getData() { return join('', $this->chunks); } /** * Returns the written data chunks. * * @return array */ public function getChunks() { return $this->chunks; } } phpmd-2.8.1/src/test/php/PHPMD/TextUI/000077500000000000000000000000001360164303200172175ustar00rootroot00000000000000phpmd-2.8.1/src/test/php/PHPMD/TextUI/CommandLineOptionsTest.php000066400000000000000000000320031360164303200243300ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\TextUI; use PHPMD\AbstractTest; use PHPMD\Rule; /** * Test case for the {@link \PHPMD\TextUI\CommandLineOptions} class. * * @covers \PHPMD\TextUI\CommandLineOptions */ class CommandLineOptionsTest extends AbstractTest { /** * @var resource */ private $stderrStreamFilter; /** * @return void */ protected function tearDown() { if (is_resource($this->stderrStreamFilter)) { stream_filter_remove($this->stderrStreamFilter); } $this->stderrStreamFilter = null; parent::tearDown(); } /** * testAssignsInputArgumentToInputProperty * * @return void * @since 1.1.0 */ public function testAssignsInputArgumentToInputProperty() { $args = array('foo.php', __FILE__, 'text', 'design'); $opts = new CommandLineOptions($args); self::assertEquals(__FILE__, $opts->getInputPath()); } /** * testAssignsFormatArgumentToReportFormatProperty * * @return void * @since 1.1.0 */ public function testAssignsFormatArgumentToReportFormatProperty() { $args = array('foo.php', __FILE__, 'text', 'design'); $opts = new CommandLineOptions($args); self::assertEquals('text', $opts->getReportFormat()); } /** * testAssignsRuleSetsArgumentToRuleSetProperty * * @return void * @since 1.1.0 */ public function testAssignsRuleSetsArgumentToRuleSetProperty() { $args = array('foo.php', __FILE__, 'text', 'design'); $opts = new CommandLineOptions($args); self::assertEquals('design', $opts->getRuleSets()); } /** * testThrowsExpectedExceptionWhenRequiredArgumentsNotSet * * @return void * @since 1.1.0 * @expectedException \InvalidArgumentException */ public function testThrowsExpectedExceptionWhenRequiredArgumentsNotSet() { $args = array(__FILE__, 'text', 'design'); new CommandLineOptions($args); } /** * testAssignsInputFileOptionToInputPathProperty * * @return void * @since 1.1.0 */ public function testAssignsInputFileOptionToInputPathProperty() { $uri = self::createResourceUriForTest('inputfile.txt'); $args = array('foo.php', 'text', 'design', '--inputfile', $uri); $opts = new CommandLineOptions($args); self::assertEquals('Dir1/Class1.php,Dir2/Class2.php', $opts->getInputPath()); } /** * testAssignsFormatArgumentCorrectWhenCalledWithInputFile * * @return void * @since 1.1.0 */ public function testAssignsFormatArgumentCorrectWhenCalledWithInputFile() { $uri = self::createResourceUriForTest('inputfile.txt'); $args = array('foo.php', 'text', 'design', '--inputfile', $uri); $opts = new CommandLineOptions($args); self::assertEquals('text', $opts->getReportFormat()); } /** * testAssignsRuleSetsArgumentCorrectWhenCalledWithInputFile * * @return void * @since 1.1.0 */ public function testAssignsRuleSetsArgumentCorrectWhenCalledWithInputFile() { $uri = self::createResourceUriForTest('inputfile.txt'); $args = array('foo.php', 'text', 'design', '--inputfile', $uri); $opts = new CommandLineOptions($args); self::assertEquals('design', $opts->getRuleSets()); } /** * testThrowsExpectedExceptionWhenInputFileNotExists * * @return void * @since 1.1.0 * @expectedException \InvalidArgumentException */ public function testThrowsExpectedExceptionWhenInputFileNotExists() { $args = array('foo.php', 'text', 'design', '--inputfile', 'inputfail.txt'); new CommandLineOptions($args); } /** * testHasVersionReturnsFalseByDefault * * @return void */ public function testHasVersionReturnsFalseByDefault() { $args = array(__FILE__, __FILE__, 'text', 'unusedcode'); $opts = new CommandLineOptions($args); self::assertFalse($opts->hasVersion()); } /** * testCliOptionsAcceptsVersionArgument * * @return void */ public function testCliOptionsAcceptsVersionArgument() { $args = array(__FILE__, '--version'); $opts = new CommandLineOptions($args); self::assertTrue($opts->hasVersion()); } /** * Tests if ignoreViolationsOnExit returns false by default * * @return void */ public function testIgnoreViolationsOnExitReturnsFalseByDefault() { $args = array(__FILE__, __FILE__, 'text', 'unusedcode'); $opts = new CommandLineOptions($args); self::assertFalse($opts->ignoreViolationsOnExit()); } /** * Tests if CLI options accepts ignoreViolationsOnExit argument * * @return void */ public function testCliOptionsAcceptsIgnoreViolationsOnExitArgument() { $args = array(__FILE__, __FILE__, 'text', 'unusedcode', '--ignore-violations-on-exit'); $opts = new CommandLineOptions($args); self::assertTrue($opts->ignoreViolationsOnExit()); } /** * Tests if CLI usage contains ignoreViolationsOnExit option * * @return void */ public function testCliUsageContainsIgnoreViolationsOnExitOption() { $args = array(__FILE__, __FILE__, 'text', 'codesize'); $opts = new CommandLineOptions($args); $this->assertContains('--ignore-violations-on-exit:', $opts->usage()); } /** * Tests if CLI usage contains the auto-discovered renderers * * @return void */ public function testCliUsageContainsAutoDiscoveredRenderers() { $args = array(__FILE__, __FILE__, 'text', 'codesize'); $opts = new CommandLineOptions($args); $this->assertContains('Available formats: ansi, html, json, text, xml.', $opts->usage()); } /** * testCliUsageContainsStrictOption * * @return void */ public function testCliUsageContainsStrictOption() { $args = array(__FILE__, __FILE__, 'text', 'codesize'); $opts = new CommandLineOptions($args); $this->assertContains('--strict:', $opts->usage()); } /** * testCliOptionsIsStrictReturnsFalseByDefault * * @return void * @since 1.2.0 */ public function testCliOptionsIsStrictReturnsFalseByDefault() { $args = array(__FILE__, __FILE__, 'text', 'codesize'); $opts = new CommandLineOptions($args); self::assertFalse($opts->hasStrict()); } /** * testCliOptionsAcceptsStrictArgument * * @return void * @since 1.2.0 */ public function testCliOptionsAcceptsStrictArgument() { $args = array(__FILE__, '--strict', __FILE__, 'text', 'codesize'); $opts = new CommandLineOptions($args); self::assertTrue($opts->hasStrict()); } /** * @return void */ public function testCliOptionsAcceptsMinimumpriorityArgument() { $args = array(__FILE__, '--minimumpriority', 42, __FILE__, 'text', 'codesize'); $opts = new CommandLineOptions($args); $this->assertEquals(42, $opts->getMinimumPriority()); } /** * @return void */ public function testCliOptionsAcceptsMaximumpriorityArgument() { $args = array(__FILE__, '--maximumpriority', 42, __FILE__, 'text', 'codesize'); $opts = new CommandLineOptions($args); $this->assertEquals(42, $opts->getMaximumPriority()); } /** * @return void */ public function testGetMinimumPriorityReturnsLowestValueByDefault() { $args = array(__FILE__, __FILE__, 'text', 'codesize'); $opts = new CommandLineOptions($args); $this->assertEquals(Rule::LOWEST_PRIORITY, $opts->getMinimumPriority()); } /** * @return void */ public function testGetCoverageReportReturnsNullByDefault() { $args = array(__FILE__, __FILE__, 'text', 'codesize'); $opts = new CommandLineOptions($args); $this->assertNull($opts->getCoverageReport()); } /** * @return void */ public function testGetCoverageReportWithCliOption() { $opts = new CommandLineOptions( array( __FILE__, __FILE__, 'text', 'codesize', '--coverage', __METHOD__ ) ); $this->assertEquals(__METHOD__, $opts->getCoverageReport()); } /** * @param string $reportFormat * @param string $expectedClass * @return void * @dataProvider dataProviderCreateRenderer */ public function testCreateRenderer($reportFormat, $expectedClass) { $args = array(__FILE__, __FILE__, $reportFormat, 'codesize'); $opts = new CommandLineOptions($args); $this->assertInstanceOf($expectedClass, $opts->createRenderer($reportFormat)); } /** * @return array */ public function dataProviderCreateRenderer() { return array( array('html', 'PHPMD\\Renderer\\HtmlRenderer'), array('text', 'PHPMD\\Renderer\\TextRenderer'), array('xml', 'PHPMD\\Renderer\\XmlRenderer'), array('ansi', 'PHPMD\\Renderer\\AnsiRenderer'), array('PHPMD_Test_Renderer_PEARRenderer', 'PHPMD_Test_Renderer_PEARRenderer'), array('PHPMD\\Test\\Renderer\\NamespaceRenderer', 'PHPMD\\Test\\Renderer\\NamespaceRenderer'), /* Test what happens when class already exists. */ array('PHPMD\\Test\\Renderer\\NamespaceRenderer', 'PHPMD\\Test\\Renderer\\NamespaceRenderer'), ); } /** * @param string $reportFormat * @return void * @expectedException \InvalidArgumentException * @expectedExceptionMessageRegExp (^Can\'t ) * @dataProvider dataProviderCreateRendererThrowsException */ public function testCreateRendererThrowsException($reportFormat) { $args = array(__FILE__, __FILE__, $reportFormat, 'codesize'); $opts = new CommandLineOptions($args); $opts->createRenderer(); } /** * @return array */ public function dataProviderCreateRendererThrowsException() { return array( array(''), array('PHPMD\\Test\\Renderer\\NotExistsRenderer') ); } /** * @param string $deprecatedName * @param string $newName * @dataProvider dataProviderDeprecatedCliOptions */ public function testDeprecatedCliOptions($deprecatedName, $newName) { stream_filter_register('stderr_stream', 'PHPMD\\TextUI\\StreamFilter'); $this->stderrStreamFilter = stream_filter_prepend(STDERR, 'stderr_stream'); $args = array(__FILE__, __FILE__, 'text', 'codesize', sprintf('--%s', $deprecatedName), 42); new CommandLineOptions($args); $this->assertContains( sprintf( 'The --%s option is deprecated, please use --%s instead.', $deprecatedName, $newName ), StreamFilter::$streamHandle ); } /** * @return array */ public function dataProviderDeprecatedCliOptions() { return array( array('extensions', 'suffixes'), array('ignore', 'exclude') ); } /** * @param array $options * @param array $expected * @return void * @dataProvider dataProviderGetReportFiles */ public function testGetReportFiles(array $options, array $expected) { $args = array_merge(array(__FILE__, __FILE__, 'text', 'codesize'), $options); $opts = new CommandLineOptions($args); $this->assertEquals($expected, $opts->getReportFiles()); } public function dataProviderGetReportFiles() { return array( array( array('--reportfile-xml', __FILE__), array('xml' => __FILE__) ), array( array('--reportfile-html', __FILE__), array('html' => __FILE__) ), array( array('--reportfile-text', __FILE__), array('text' => __FILE__) ), array( array( '--reportfile-text', __FILE__, '--reportfile-xml', __FILE__, '--reportfile-html', __FILE__, ), array('text' => __FILE__, 'xml' => __FILE__, 'html' => __FILE__) ), ); } } phpmd-2.8.1/src/test/php/PHPMD/TextUI/CommandTest.php000066400000000000000000000126701360164303200221540ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\TextUI; use PHPMD\AbstractTest; /** * Test case for the {@link \PHPMD\TextUI\Command} class. * * @covers \PHPMD\TextUI\Command */ class CommandTest extends AbstractTest { /** * @var resource */ private $stderrStreamFilter; /** * @return void */ protected function tearDown() { if (is_resource($this->stderrStreamFilter)) { stream_filter_remove($this->stderrStreamFilter); } $this->stderrStreamFilter = null; parent::tearDown(); } /** * @param $sourceFile * @param $expectedExitCode * @param array|null $options * @return void * @dataProvider dataProviderTestMainWithOption */ public function testMainStrictOptionIsOfByDefault($sourceFile, $expectedExitCode, array $options = null) { $args = array_filter( array_merge( array( __FILE__, self::createFileUri($sourceFile), 'html', 'codesize', '--reportfile', self::createTempFileUri(), ), (array) $options ) ); $exitCode = Command::main($args); $this->assertEquals($expectedExitCode, $exitCode); } /** * @return array */ public function dataProviderTestMainWithOption() { return array( array( 'source/source_without_violations.php', Command::EXIT_SUCCESS ), array( 'source/source_with_npath_violation.php', Command::EXIT_VIOLATION ), array( 'source/source_with_npath_violation.php', Command::EXIT_SUCCESS, array('--ignore-violations-on-exit') ), array( 'source/ccn_suppress_function.php', Command::EXIT_VIOLATION, array('--strict') ), array( 'source/ccn_suppress_function.php', Command::EXIT_SUCCESS ), ); } /** * @return void */ public function testWithMultipleReportFiles() { $args = array( __FILE__, self::createFileUri('source/source_with_npath_violation.php'), 'xml', 'design', '--reportfile', self::createTempFileUri(), '--reportfile-xml', $xml = self::createTempFileUri(), '--reportfile-html', $html = self::createTempFileUri(), '--reportfile-text', $text = self::createTempFileUri(), '--reportfile-json', $json = self::createTempFileUri(), ); Command::main($args); $this->assertFileExists($xml); $this->assertFileExists($html); $this->assertFileExists($text); $this->assertFileExists($json); } /** * @param string $option * @param string $value * @return void * @dataProvider dataProviderWithFilter */ public function testWithFilter($option, $value) { $args = array( __FILE__, self::createFileUri('source/'), 'text', 'codesize', '--reportfile', self::createTempFileUri(), $option, $value, ); $exitCode = Command::main($args); $this->assertEquals(Command::EXIT_SUCCESS, $exitCode); } /** * @return array */ public function dataProviderWithFilter() { return array( array('--suffixes', '.class.php'), array('--exclude', 'ccn_,npath_'), ); } /* * @return void */ public function testMainWritesExceptionMessageToStderr() { stream_filter_register('stderr_stream', 'PHPMD\\TextUI\\StreamFilter'); $this->stderrStreamFilter = stream_filter_prepend(STDERR, 'stderr_stream'); Command::main( array( __FILE__, self::createFileUri('source/source_with_npath_violation.php'), "''", 'naming' ) ); $this->assertContains( 'Can\'t find the custom report class: ', StreamFilter::$streamHandle ); } /* * @return void */ public function testMainPrintsVersionToStdout() { stream_filter_register('stderr_stream', 'PHPMD\\TextUI\\StreamFilter'); $this->stderrStreamFilter = stream_filter_prepend(STDOUT, 'stderr_stream'); Command::main( array( __FILE__, '--version' ) ); $data = @parse_ini_file(__DIR__ . '/../../../../../build.properties'); $version = $data['project.version']; $this->assertEquals('PHPMD ' . $version, trim(StreamFilter::$streamHandle)); } } phpmd-2.8.1/src/test/php/PHPMD/TextUI/StreamFilter.php000066400000000000000000000017051360164303200223340ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\TextUI; /** * Utility to test stream related stuff */ class StreamFilter extends \php_user_filter { public static $streamHandle; public function filter($in, $out, &$consumed, $closing) { self::$streamHandle = ''; while ($bucket = stream_bucket_make_writeable($in)) { self::$streamHandle .= $bucket->data; $consumed += $bucket->datalen; } return PSFS_PASS_ON; } } phpmd-2.8.1/src/test/php/bootstrap.php000066400000000000000000000013671360164303200177220ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ require_once __DIR__ . '/../../../vendor/autoload.php'; spl_autoload_register( function ($class) { $file = __DIR__ . '/' . strtr($class, '\\', '/') . '.php'; if (file_exists($file)) { include $file; } } ); phpmd-2.8.1/src/test/resources/000077500000000000000000000000001360164303200164105ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/000077500000000000000000000000001360164303200175125ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Integration/000077500000000000000000000000001360164303200217755ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Integration/CommandLineInputFileOption/000077500000000000000000000000001360164303200271745ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Integration/CommandLineInputFileOption/Class1.php000077500000000000000000000010771360164303200310430ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class Class1 { function foo() { $foo = 42; } } phpmd-2.8.1/src/test/resources/files/Integration/CommandLineInputFileOption/Class2.php000077500000000000000000000011101360164303200310300ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class Class2 { function foo($foo) { return ($foo * 42); } } phpmd-2.8.1/src/test/resources/files/Integration/CommandLineInputFileOption/Class3.php000077500000000000000000000011061360164303200310360ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class Class3 { public function bar() { $bar = 23; } } phpmd-2.8.1/src/test/resources/files/Integration/CommandLineInputFileOption/inputfile.txt000077500000000000000000000000251360164303200317340ustar00rootroot00000000000000Class1.php Class2.phpphpmd-2.8.1/src/test/resources/files/Integration/CouplingBetweenObjectsIntegration/000077500000000000000000000000001360164303200306055ustar00rootroot00000000000000testReportContainsCouplingBetweenObjectsWarning.php000077500000000000000000000045451360164303200427770ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Integration/CouplingBetweenObjectsIntegration. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testReportContainsCouplingBetweenObjectsWarning { /** * addParameter * * @param \ReflectionParameter $p * @return void * @throws \OutOfBoundsException */ public function addParameter(\ReflectionParameter $p) { } /** * setClass * * @param \ReflectionClass $c * @return void * @throws \OutOfBoundsException */ public function setClass(\ReflectionClass $c) { } /** * setParentClass * * @param \ReflectionClass $c * @return void * @throws \OutOfBoundsException */ public function setParentClass(\ReflectionClass $c) { } /** * addProperty * * @param \ReflectionProperty $p * @return void * @throws \OutOfBoundsException */ public function addProperty(\ReflectionProperty $p) { } /** * traverse * * @param DOMNode $node * @return void * @throws \InvalidArgumentException */ public function traverse(\DOMNode $node = null) { } /** * setStorage * * @param \SplObjectStorage $storage * @return void */ public function setStorage(\SplObjectStorage $storage) { } /** * getIterator * * @return \Iterator */ public function getIterator() { return new \ArrayIterator(array()); } /** * getElement * * @return DOMElement */ public function getElement() { } /** * getOwnerDocument * * @return DOMDocument */ public function getOwnerDocument() { } /** * find * * @param DOMXPath $xpath * @return DOMNodeList */ public function find(DOMXPath $xpath) { return $xpath->query(''); } public function fail() { throw new \ErrorException(); } } phpmd-2.8.1/src/test/resources/files/Integration/GotoStatementIntegration/000077500000000000000000000000001360164303200267765ustar00rootroot00000000000000testReportContainsGotoStatementWarning.php000077500000000000000000000012331360164303200373500ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Integration/GotoStatementIntegration. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testReportContainsGotoStatementWarning() { LABEL: echo 'You goto ' . __LINE__; if (time() % 42 === 23) { goto LABEL; } } phpmd-2.8.1/src/test/resources/files/Node/000077500000000000000000000000001360164303200203775ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Node/ClassNode/000077500000000000000000000000001360164303200222525ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Node/ClassNode/testGetConstantCount.php000066400000000000000000000011361360164303200271260ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testGetConstantCount { const PDEPEND = 42, PHPMD = 23, TEST = 17; } phpmd-2.8.1/src/test/resources/files/Node/InterfaceNode/000077500000000000000000000000001360164303200231055ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Node/InterfaceNode/testGetConstantCount.php000066400000000000000000000011421360164303200277560ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ interface testGetConstantCount { const PDEPEND = 42, PHPMD = 23, TEST = 17; } phpmd-2.8.1/src/test/resources/files/Node/MethodNode/000077500000000000000000000000001360164303200224255ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Node/MethodNode/testGetParentTypeReturnsClassForClassMethod.php000077500000000000000000000014201360164303200337400ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testGetParentTypeReturnsClassForClassMethodClass { public function testGetParentTypeReturnsClassForClassMethod() { } } class testGetParentTypeReturnsClassForClassMethodClass { public function testGetParentTypeReturnsClassForClassMethod() { } } testGetParentTypeReturnsInterfaceForInterfaceMethod.php000077500000000000000000000014321360164303200353520ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Node/MethodNode. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ interface testGetParentTypeReturnsInterfaceForInterfaceMethodInterface { function testGetParentTypeReturnsInterfaceForInterfaceMethod(); } interface testGetParentTypeReturnsInterfaceForInterfaceMethodInterface { function testGetParentTypeReturnsInterfaceForInterfaceMethod(); } phpmd-2.8.1/src/test/resources/files/Node/MethodNode/testGetParentTypeReturnsTrait.php000066400000000000000000000011451360164303200311610ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ trait testGetParentTypeReturnsTrait { public function testGetParentTypeReturnsTrait() { } } testHasSuppressWarningsDelegatesToParentClassMethod.php000077500000000000000000000015671360164303200354060ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Node/MethodNode. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ /** * @SuppressWarnings("PHPMD.FooBar") */ class testHasSuppressWarningsDelegatesToParentClassMethodClass { public function testHasSuppressWarningsDelegatesToParentClassMethod() {} } /** * @SuppressWarnings("PHPMD.FooBar") */ class testHasSuppressWarningsDelegatesToParentClassMethodClass { public function testHasSuppressWarningsDelegatesToParentClassMethod() {} } testHasSuppressWarningsDelegatesToParentInterfaceMethod.php000077500000000000000000000016051360164303200362320ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Node/MethodNode. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ /** * @SuppressWarnings("PHPMD.FooBar") */ interface testHasSuppressWarningsDelegatesToParentInterfaceMethodInterface { function testHasSuppressWarningsDelegatesToParentInterfaceMethod(); } /** * @SuppressWarnings("PHPMD.FooBar") */ interface testHasSuppressWarningsDelegatesToParentInterfaceMethodInterface { function testHasSuppressWarningsDelegatesToParentInterfaceMethod(); } testHasSuppressWarningsExecutesDefaultImplementation.php000077500000000000000000000016311360164303200356750ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Node/MethodNode. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testHasSuppressWarningsExecutesDefaultImplementationClass { /** * @SuppressWarnings("PHPMD.FooBar") */ function testHasSuppressWarningsExecutesDefaultImplementation() { } } class testHasSuppressWarningsExecutesDefaultImplementationClass { /** * @SuppressWarnings("PHPMD.FooBar") */ function testHasSuppressWarningsExecutesDefaultImplementation() { } } testHasSuppressWarningsIgnoresCaseFirstLetter.php000077500000000000000000000015751360164303200342760ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Node/MethodNode. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testHasSuppressWarningsIgnoresCaseFirstLetterClass { /** * @suppressWarnings("PHPMD.FooBar") */ function testHasSuppressWarningsIgnoresCaseFirstLetter() { } } class testHasSuppressWarningsIgnoresCaseFirstLetterClass { /** * @suppressWarnings("PHPMD.FooBar") */ function testHasSuppressWarningsIgnoresCaseFirstLetter() { } } testIsDeclarationReturnsFalseForImplementedAbstractMethod.php000077500000000000000000000016561360164303200365310ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Node/MethodNode. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testIsDeclarationReturnsFalseForImplementedAbstractMethodClass extends testIsDeclarationReturnsFalseForImplementedAbstractMethodParentClass { public function testIsDeclarationReturnsFalseForImplementedAbstractMethod($foo) { } } abstract class testIsDeclarationReturnsFalseForImplementedAbstractMethodParentClass { public abstract function testIsDeclarationReturnsFalseForImplementedAbstractMethod($foo); } testIsDeclarationReturnsFalseForImplementedInterfaceMethod.php000077500000000000000000000016351360164303200366630ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Node/MethodNode. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testIsDeclarationReturnsFalseForImplementedInterfaceMethodClass implements testIsDeclarationReturnsFalseForImplementedInterfaceMethodInterface { public function testIsDeclarationReturnsFalseForImplementedInterfaceMethod($foo) { } } interface testIsDeclarationReturnsFalseForImplementedInterfaceMethodInterface { function testIsDeclarationReturnsFalseForImplementedInterfaceMethod($foo); } testIsDeclarationReturnsFalseForInheritMethodDeclaration.php000077500000000000000000000016431360164303200363460ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Node/MethodNode. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testIsDeclarationReturnsFalseForInheritMethodDeclarationClass extends testIsDeclarationReturnsFalseForInheritMethodDeclarationParentClass { public function testIsDeclarationReturnsFalseForInheritMethodDeclaration($foo) { } } class testIsDeclarationReturnsFalseForInheritMethodDeclarationParentClass { public function testIsDeclarationReturnsFalseForInheritMethodDeclaration($foo) { } } testIsDeclarationReturnsTrueForMethodDeclaration.php000077500000000000000000000012241360164303200347030ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Node/MethodNode. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testIsDeclarationReturnsTrueForMethodDeclarationClass { public function testIsDeclarationReturnsTrueForMethodDeclaration($foo) { } } testIsDeclarationReturnsTrueForMethodDeclarationWithParent.php000077500000000000000000000016431360164303200367160ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Node/MethodNode. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testIsDeclarationReturnsTrueForMethodDeclarationWithParentClass extends testIsDeclarationReturnsTrueForMethodDeclarationWithParentParentClass { public function testIsDeclarationReturnsTrueForMethodDeclarationWithParent($foo) { } } class testIsDeclarationReturnsTrueForMethodDeclarationWithParentParentClass { public function testIsDeclarationReturnsTrueForMethodDeclaration($foo) { } } testIsDeclarationReturnsTrueForPrivateMethod.php000066400000000000000000000015711360164303200340720ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Node/MethodNode. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testIsDeclarationReturnsTrueForPrivateMethod extends testIsDeclarationReturnsTrueForPrivateMethod_parent { private function testIsDeclarationReturnsTrueForPrivateMethod() { return false; } } class testIsDeclarationReturnsTrueForPrivateMethod_parent { private function testIsDeclarationReturnsTrueForPrivateMethod() { return true; } } phpmd-2.8.1/src/test/resources/files/PHPMD/000077500000000000000000000000001360164303200203625ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/PHPMD/Test/000077500000000000000000000000001360164303200213015ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/PHPMD/Test/Renderer/000077500000000000000000000000001360164303200230475ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/PHPMD/Test/Renderer/NamespaceRenderer.php000066400000000000000000000012751360164303200271500ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMD\Test\Renderer; use PHPMD\AbstractRenderer; use PHPMD\Report; class NamespaceRenderer extends AbstractRenderer { public function renderReport(Report $report) { } } phpmd-2.8.1/src/test/resources/files/PHPMD/Test/Renderer/PEARRenderer.php000066400000000000000000000012271360164303200260000ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ use PHPMD\Report; class PHPMD_Test_Renderer_PEARRenderer extends PHPMD\AbstractRenderer { public function renderReport(Report $report) { } } phpmd-2.8.1/src/test/resources/files/ParserFactory/000077500000000000000000000000001360164303200222765ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/ParserFactory/Directory/000077500000000000000000000000001360164303200242425ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/ParserFactory/Directory/Test.php000077500000000000000000000010441360164303200256740ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class ParserFactory_Directory_Test { } phpmd-2.8.1/src/test/resources/files/ParserFactory/File/000077500000000000000000000000001360164303200231555ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/ParserFactory/File/Test.php000077500000000000000000000010371360164303200246110ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class ParserFactory_File_Test { } phpmd-2.8.1/src/test/resources/files/Regression/000077500000000000000000000000001360164303200216325ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Regression/001/000077500000000000000000000000001360164303200221325ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Regression/001/source/000077500000000000000000000000001360164303200234325ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Regression/001/source/FooBar.php000077500000000000000000000010631360164303200253160ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ /** * @package ticket001 */ class FooBarTicket001 {} phpmd-2.8.1/src/test/resources/files/Regression/007/000077500000000000000000000000001360164303200221405ustar00rootroot00000000000000testFormalParameterUsedInDoubleQuoteStringGetsNotReported.php000077500000000000000000000013511360164303200362370ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Regression/007. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testFormalParameterUsedInDoubleQuoteStringGetsNotReported { public function testFormalParameterUsedInDoubleQuoteStringGetsNotReported($usedParam) { echo "Testing {$usedParam} inside a double quoted string"; } } testLocalVariableUsedInDoubleQuoteStringGetsNotReported.php000077500000000000000000000013671360164303200356650ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Regression/007. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testLocalVariableUsedInDoubleQuoteStringGetsNotReported { public function testLocalVariableUsedInDoubleQuoteStringGetsNotReported() { $usedVar = "foobar"; echo "Testing {$usedVar} inside a double quoted string"; } } phpmd-2.8.1/src/test/resources/files/Regression/010096717/000077500000000000000000000000001360164303200226305ustar00rootroot00000000000000testRuleNotAppliesForLongPrivateProperty.php000077500000000000000000000011531360164303200334620ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Regression/010096717. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleNotAppliesForLongPrivateProperty { private $testRuleNotAppliesForLongPrivateProperty = 42; } testRuleNotAppliesForLongPrivateStaticProperty.php000077500000000000000000000011761360164303200346370ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Regression/010096717. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleNotAppliesForLongPrivateStaticProperty { private static $testRuleNotAppliesForLongPrivateStaticProperty = 23; } phpmd-2.8.1/src/test/resources/files/Regression/015/000077500000000000000000000000001360164303200221375ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Regression/015/testRuleSetInvokesRuleForClassInstance.php000077500000000000000000000011101360164303200324400ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleSetInvokesRuleForClassInstance { public $a, $b, $c, $d; } phpmd-2.8.1/src/test/resources/files/Regression/019/000077500000000000000000000000001360164303200221435ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Regression/019/testRuleDoesNotApplyToAnySuperGlobalVariable.php000077500000000000000000000016151360164303200335540ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToAnySuperGlobalVariable { function testRuleDoesNotApplyToAnySuperGlobalVariable() { $GLOBALS = 42; $HTTP_RAW_POST_DATA = 42; $_COOKIE = 42; $_ENV = 42; $_FILES = 42; $_GET = 42; $_POST = 42; $_REQUEST = 42; $_SERVER = 42; $_SESSION = 42; $argc = 42; $argv = 42; } } phpmd-2.8.1/src/test/resources/files/Regression/020/000077500000000000000000000000001360164303200221335ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Regression/020/testRuleDoesNotApplyToAnyStaticLocalVariable.php000077500000000000000000000013501360164303200335230ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToAnyStaticLocalVariable { public function testRuleDoesNotApplyToAnyStaticLocalVariable() { static $foo = 42, $bar = 23; static $baz = T_FOO_BAR; echo $foo, $bar, $baz; } } phpmd-2.8.1/src/test/resources/files/Regression/036/000077500000000000000000000000001360164303200221425ustar00rootroot00000000000000testRuleDoesNotApplyToPrivateMethodWithSuppressWarningsAnnotation.php000077500000000000000000000012751360164303200400610ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Regression/036. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToPrivateMethodWithSuppressWarningsAnnotation { /** * @SuppressWarnings(PHPMD.UnusedPrivateMethod) */ private function unusedMethod() { } } phpmd-2.8.1/src/test/resources/files/Regression/14990109/000077500000000000000000000000001360164303200225525ustar00rootroot00000000000000testRuleDoesNotApplyToFunctionParameterNamedArgv.php000077500000000000000000000011741360164303200347620ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Regression/14990109. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleDoesNotApplyToFunctionParameterNamedArgv($argv) { foreach ($argv as $arg) { echo $arg; } } testRuleDoesNotApplyToMethodParameterNamedArgv.php000077500000000000000000000013331360164303200344120ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Regression/14990109. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToMethodParameterNamedArgvClass { public function testRuleDoesNotApplyToMethodParameterNamedArgv($argv) { foreach ($argv as $arg) { echo $arg; } } } phpmd-2.8.1/src/test/resources/files/Regression/24975295/000077500000000000000000000000001360164303200225645ustar00rootroot00000000000000testLocalVariableUsedInDoubleQuoteStringGetsNotReported.php000077500000000000000000000164571360164303200363170ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Regression/24975295. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ use Route24975295 as Route; class Bootstrap extends Bootstrap24975295 { protected function initRouter() { $this->bootstrap('frontController'); $front = $this->getResource('frontController'); $router = $front->getRouter(); $route = new Hostname24975295('foo', array('module' => 'default' )); $router ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ->addRoute('default', $route->chain(new Route('x', array('controller' => 'index')))) ; } } phpmd-2.8.1/src/test/resources/files/Rule/000077500000000000000000000000001360164303200204215ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/000077500000000000000000000000001360164303200222365ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/DuplicatedArrayKey/000077500000000000000000000000001360164303200257645ustar00rootroot00000000000000testRuleAppliesCorrectlyToMultipleArrays.php000066400000000000000000000017201360164303200366330ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/DuplicatedArrayKey. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleAppliesCorrectlyToMultipleArrays() { $arrayOne = array( 'foo' => 'bar', 'foo' => 'bar', ); $arrayTwo = array( 'foo' => 'bar', ); $arrayThree = array( 'foo' => 'bar', 'foo' => 'bar', 'foo' => 'bar', ); $arrayFour = array( 'foo' => array( 'foo' => array( 'foo' => 'bar', 'foo' => 'bar', ), ), ); } testRuleAppliesCorrectlyWithNestedArrays.php000066400000000000000000000016511360164303200366160ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/DuplicatedArrayKey. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleAppliesCorrectlyWithNestedArrays() { return array( 'foo' => 40, 'foo' => 42, 'foo' => array( 'foo' => 43, array( 'foo' => 44, array( 'foo' => 45, 'foo' => 46, ), ), ), array( 'foo' => 47, 'foo' => 49, ) ); } testRuleAppliesMultipleTimesToFunctionWithAssotiativeArrayDefinitionWithDuplicatedKeys.php000066400000000000000000000013171360164303200500430ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/DuplicatedArrayKey. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleAppliesMultipleTimesToFunctionWithAssotiativeArrayDefinitionWithDuplicatedKeys() { return array( 'foo' => 42, 'foo' => 43, 'foo' => 44, 'foo' => 45, ); } testRuleAppliesMultipleTimesToMethodWithAssotiativeArrayDefinitionWithDuplicatedKeys.php000066400000000000000000000015551360164303200475020ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/DuplicatedArrayKey. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; class testRuleAppliesMultipleTimesToMethodWithAssotiativeArrayDefinitionWithDuplicatedKeys { public function testRuleAppliesMultipleTimesToMethodWithAssotiativeArrayDefinitionWithDuplicatedKeys() { return array( 'foo' => 42, 'foo' => 43, 'foo' => 44, 'foo' => 45, ); } } testRuleAppliesToFunctionWithAssotiativeArrayDefinitionWithDuplicatedKeys.php000066400000000000000000000012301360164303200453170ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/DuplicatedArrayKey. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleAppliesToFunctionWithAssotiativeArrayDefinitionWithDuplicatedKeys() { return array( 'foo' => 42, 'foo' => 43, ); } testRuleAppliesToFunctionWithAssotiativeArrayDefinitionWithDuplicatedMixedQuotedKeys.php000066400000000000000000000012431360164303200474740ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/DuplicatedArrayKey. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleAppliesToFunctionWithAssotiativeArrayDefinitionWithDuplicatedMixedQuotedKeys() { return array( 'foo' => 42, "foo" => 43, ); } testRuleAppliesToFunctionWithAssotiativeArrayDefinitionWithDuplicatedMixedTypeKeys.php000066400000000000000000000012371360164303200471570ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/DuplicatedArrayKey. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleAppliesToFunctionWithAssotiativeArrayDefinitionWithDuplicatedMixedTypeKeys() { return array( 123 => 42, '123' => 42, ); } testRuleAppliesToMethodWithAssotiativeArrayDefinitionWithDuplicatedKeys.php000066400000000000000000000014411360164303200447560ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/DuplicatedArrayKey. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; class testRuleAppliesToMethodWithAssotiativeArrayDefinitionWithDuplicatedKeys { public function testRuleAppliesToMethodWithAssotiativeArrayDefinitionWithDuplicatedKeys() { return array( 'foo' => 42, 'foo' => 43, ); } } testRuleAppliesToMethodWithAssotiativeArrayDefinitionWithDuplicatedMixedQuotedKeys.php000066400000000000000000000014671360164303200471370ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/DuplicatedArrayKey. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; class testRuleAppliesToMethodWithAssotiativeArrayDefinitionWithDuplicatedMixedQuotedKeys { public function testRuleAppliesToMethodWithAssotiativeArrayDefinitionWithDuplicatedMixedQuotedKeys() { return array( 'foo' => 42, "foo" => 42, ); } } testRuleAppliesToMethodWithAssotiativeArrayDefinitionWithDuplicatedMixedTypeKeys.php000066400000000000000000000014611360164303200466110ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/DuplicatedArrayKey. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; class testRuleAppliesToMethodWithAssotiativeArrayDefinitionWithDuplicatedMixedTypeKeys { public function testRuleAppliesToMethodWithAssotiativeArrayDefinitionWithDuplicatedMixedTypeKeys() { return array( 123 => 42, '123' => 43, ); } } testRuleAppliesWhenKeyIsDeclaredInNonStandardWay.php000066400000000000000000000103301360164303200400570ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/DuplicatedArrayKey. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; function global_function_duplicate() { return 'foo'; } class testRuleAppliesWhenKeyIsDeclaredInNonStandardWay extends testRuleAppliesWhenKeyIsDeclaredInNonStandardWayParent { const DUPLICATED_KEY = 'foo'; public static $classStaticPropertyDuplicate = 'foo'; private $classPrivatePropertyDuplicate = 'foo'; protected $classProtectedPropertyDuplicate = 'foo'; public $classPublicPropertyDuplicate = 'foo'; private static $classPrivateStaticPropertyDuplicate = 'foo'; public function testRuleAppliesWhenKeyIsDeclaredInNonStandardWay() { if (!defined('GLOBAL_DUPLICATE')) { define('GLOBAL_DUPLICATE', 'foo'); } $foo = 'foo'; $baz = $this->getDuplicatedName(); return array( // not applied - comment // 0 => 'bar', // not applied - comment with content 0 => 'bar', // not applied - first occurrence false => 'bar', // applied - shallow cast to integer 0 1 => 'bar', // not applied - first occurrence true => 'bar', // applied - shallow cast to integer 1 '' => 'bar', // not applied - first occurrence null => 'bar', // applied - shallow cast to empty string 'foo' => 'bar', // not applied - first occurrence 'f' . 'o' . 'o' => 'bar', // not applied - resolves in string 'foo' (not supported yet) 'f' . 'o' . (14 * 1) || 1 . 'o' => 'bar', // not applied - resolves in string 'foo' (to be implemented?) self::DUPLICATED_KEY => 'bar', // not applied (not supported yet) parent::DUPLICATED_KEY => 'bar', // not applied (not supported yet) static::DUPLICATED_KEY => 'bar', // not applied (not supported yet) self::INTERFACE_DUPLICATED_KEY => 'bar', // not applied (not supported yet) parent::INTERFACE_DUPLICATED_KEY => 'bar', // not applied (not supported yet) static::INTERFACE_DUPLICATED_KEY => 'bar', // not applied (not supported yet) $foo => 'bar', // not applied - resolving variables is impossible in this context $baz => 'bar', // not applied - resolving variables is impossible in this context $this->getDuplicatedName() => 'bar', // not applied - resolving variable depends on inheritance tree self::$classStaticPropertyDuplicate => 'bar', // not applied - static property may be modified externally self::$classPrivateStaticPropertyDuplicate, // not applied - static property may be modified externally $this->classPrivatePropertyDuplicate => 'bar', // not applied - may be modified at any time $this->classProtectedPropertyDuplicate => 'bar', // not applied - may be modified at any time $this->classPublicPropertyDuplicate => 'bar', // not applied - may be modified at any time global_function_duplicate() => 'bar', // not applied - may be different depending on namespace GLOBAL_DUPLICATE => 'bar', // not applied - may be different depending on context "foo" => 'bar', // applied - duplicated variable to check if none of above breaks execution ); } /** * @return string */ public function getDuplicatedName() { return 'foo'; } } interface testRuleAppliesWhenKeyIsDeclaredInNonStandardWayInterface { const INTERFACE_DUPLICATED_KEY = 'foo'; } abstract class testRuleAppliesWhenKeyIsDeclaredInNonStandardWayAbstract implements testRuleAppliesWhenKeyIsDeclaredInNonStandardWayInterface { const DUPLICATED_KEY = 'foo'; } class testRuleAppliesWhenKeyIsDeclaredInNonStandardWayParent extends testRuleAppliesWhenKeyIsDeclaredInNonStandardWayAbstract { const DUPLICATED_KEY = 'foo'; } testRuleNotAppliesToFunctionWithAssotiativeArrayDefinitionWithoutDuplicatedKeys.php000066400000000000000000000012361360164303200465360ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/DuplicatedArrayKey. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleNotAppliesToFunctionWithAssotiativeArrayDefinitionWithoutDuplicatedKeys() { return array( 'foo' => 42, 'bar' => 43, ); } testRuleNotAppliesToFunctionWithNonAssotiativeArrayDefinition.php000066400000000000000000000012061360164303200427670ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/DuplicatedArrayKey. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleNotAppliesToFunctionWithNonAssotiativeArrayDefinition() { return array( 42, 43, 43, ); } testRuleNotAppliesToFunctionWithoutArrayDefinition.php000066400000000000000000000011651360164303200406340ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/DuplicatedArrayKey. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleNotAppliesToFunctionWithoutArrayDefinition() { $foo = 'bar'; $foo .= 'baz'; return $foo; } testRuleNotAppliesToMethodWithAssotiativeArrayDefinitionWithoutDuplicatedKeys.php000066400000000000000000000014551360164303200461740ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/DuplicatedArrayKey. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; class testRuleNotAppliesToMethodWithAssotiativeArrayDefinitionWithoutDuplicatedKeys { public function testRuleNotAppliesToMethodWithAssotiativeArrayDefinitionWithoutDuplicatedKeys() { return array( 'foo' => 42, 'bar' => 43, ); } } testRuleNotAppliesToMethodWithNonAssotiativeArrayDefinition.php000066400000000000000000000013671360164303200424320ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/DuplicatedArrayKey. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; class testRuleNotAppliesToMethodWithNonAssotiativeArrayDefinition { public function testRuleNotAppliesToMethodWithNonAssotiativeArrayDefinition() { return array( 42, 43, ); } } testRuleNotAppliesToMethodWithoutArrayDefinition.php000066400000000000000000000012671360164303200402720ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/DuplicatedArrayKey. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; class testRuleNotAppliesToMethodWithoutArrayDefinition { public function testRuleNotAppliesToMethodWithoutArrayDefinition() { $someVar = ''; } } phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/ElseExpression/000077500000000000000000000000001360164303200252065ustar00rootroot00000000000000testRuleAppliesMultipleTimesToMethodWithMultipleElseExpressions.php000077500000000000000000000013711360164303200426000ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/ElseExpression. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class Foo { public function testRuleAppliesMultipleTimesToMethodWithMultipleElseExpressions() { if (true) { } else { } if (true) { } else { } if (true) { } else { } } } testRuleAppliesToMethodWithElseExpression.php000077500000000000000000000012051360164303200361570ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/ElseExpression. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class Foo { public function testRuleAppliesToMethodWithElseExpression() { if (true) { } else { } } } testRuleNotAppliesToMethodWithoutElseExpression.php000077500000000000000000000012161360164303200373720ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/ElseExpression. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class Foo { function testRuleNotAppliesToMethodWithoutElseExpression() { if (true) { } else if (true) { } } } phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/IfStatementAssignment/000077500000000000000000000000001360164303200265125ustar00rootroot00000000000000testRuleAppliesMultipleIfConditions.php000066400000000000000000000013171360164303200363200ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/IfStatementAssignment. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleAppliesMultipleIfConditions() { if (1 || 0) { // not applied // ... } if (1 == 1 || 1 && 0 and 4 % 2 || ($foo = 1) xor 5 * 4 * 3 * 2 * 1) { // applied // ... } } testRuleAppliesMultipleTimesInOneIfCondition.php000066400000000000000000000013161360164303200400670ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/IfStatementAssignment. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleAppliesMultipleTimesInOneIfCondition() { if (1 || 0) { // not applied // ... } if ($foo = 'bar' && $bar = 'baz' || $baz = 'foo') { // applied 3 times // ... } } testRuleAppliesToFunctions.php000066400000000000000000000012341360164303200344650ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/IfStatementAssignment. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleAppliesToFunctions() { if ('foo' || 'bar') { // not applied // ... } if ($foo = 'baz') { // applied // ... } } testRuleAppliesToMultilevelIfConditions.php000066400000000000000000000031561360164303200371550ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/IfStatementAssignment. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleAppliesToMultilevelIfConditions() { if (1 || 0) { // not applied if (1 == 1 || $foo = 'baz') { // applied // ... } elseif (1 != array() && 'foo' != 'baz' && $bar = 'baz') { // applied // ... } elseif (1 % 2 !== !false && $baz = 1 + 1 + 1 - 3) { // applied // ... if ($foo == 'baz') { // not applied // ... if (3 - 2 == 3) { // not applied // ... if (true) { // not applied // ... if (1) { // not applied // ... } elseif ($foo = 1) { // applied // ... } elseif ($foo = 2) { // applied // ... } elseif (5 % 5 == 0) { // not applied // ... } } } } } } if (1 == 1 || 1 && 0 and 4 % 2 || ($foo = 1) xor 5 * 4 * 3 * 2 * 1) { // applied // ... } } testRuleNotAppliesInsideClosure.php000066400000000000000000000013741360164303200354500ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/IfStatementAssignment. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; class Foo { public function testRuleNotAppliesInsideClosure() { if (true) { array_filter(array(), function ($foo) { $bar = $foo; echo $bar; }); } } } testRuleNotAppliesInsideClosureCallbacks.php000066400000000000000000000015431360164303200372460ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/IfStatementAssignment. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; class Foo { public function testRuleNotAppliesInsideClosureCallbacks($ids, $allocation) { if ('foo' === 'foo') { $ids->each(function () use ($allocation) { $allocation->status = 'paid'; $allocation->potato = 'round'; }); return true; } } } testRuleNotAppliesToIfsWithConditionsOnly.php000066400000000000000000000022741360164303200374540ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/IfStatementAssignment. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; class Foo { public function testRuleNotAppliesToIfsWithConditionsOnly() { $foo = 'bar'; if ($foo == 'bar') { // not applied // ... } if ($foo === 'bar') { // not applied // ... } if ($foo != 'bar') { // not applied // ... } if ($foo !== 'bar') { // not applied // ... } if ($foo > 1) { // not applied // ... } if ($foo >= 1) { // not applied // ... } if ($foo < 1) { // not applied // ... } if ($foo <= 1) { // not applied // ... } } } testRuleNotAppliesToIfsWithoutAssignment.php000066400000000000000000000016701360164303200373400ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/IfStatementAssignment. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; class Foo { public function testRuleNotAppliesToIfsWithoutAssignment() { $foo = 'bar'; if (true) { // not applied // ... } else { // not applied // ... } if (null) { // not applied // ... } if (rand()) { // not applied // ... } if ($foo) { // not applied // ... } } } testRuleNotAppliesToLogicalOperators.php000066400000000000000000000021731360164303200364520ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/IfStatementAssignment. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; class Foo { public function testRuleNotAppliesToLogicalOperators() { if (1 || 0) { // not applied // ... } if (1 && 1) { // not applied // ... } if (1 or 0) { // not applied // ... } if (1 and 1) { // not applied // ... } if (1 xor 1) { // not applied // ... } if (1 % 1) { // not applied // ... } if (1 || !1) { // not applied // ... } if (!1 % !1) { // not applied // ... } } } testRuleWorksCorrectlyWhenExpressionContainsMath.php000066400000000000000000000023621360164303200411060ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/IfStatementAssignment. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; class Foo { public function testRuleWorksCorrectlyWhenExpressionContainsMath() { $foo = 0; if ($foo == 1 * 1) { // not applied // ... } if ($foo == 1 % 2) { // not applied // ... } if ($foo == 1 + 2 + 2 / 1) { // not applied // ... } if ($foo == 'foo' . 'bar') { // not applied // ... } if ($foo == ('' . '')) { // not applied // ... } if ($foo = 1 * 1) { // applied // ... } if ($foo = '' . 1) { // applied // ... } if ($foo = (int)1.0 + (float)false % (string)1) { // applied // ... } } } phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/MissingImport/000077500000000000000000000000001360164303200250425ustar00rootroot00000000000000testRuleAppliesToClassWithNotImportedDependencies.php000066400000000000000000000013051360164303200374410ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/MissingImport. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; class Foo { public function testRuleAppliesToClassWithNotImportedDependencies() { $object = new \stdClass(); new \DateTime('2019-02-02 00:00:00'); } } testRuleAppliesToFunctionWithNotImportedDependencies.php000066400000000000000000000011571360164303200401660ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/MissingImport. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; function testRuleAppliesToFunctionWithNotImportedDependencies(){ $a = new \stdClass(); } testRuleNotAppliesToClassWithOnlyImportedDependencies.php000066400000000000000000000012511360164303200403030ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/MissingImport. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; use stdClass; class Foo { public function testRuleNotAppliesToClassWithOnlyImportedDependencies() { $object = new stdClass(); } } testRuleNotAppliesToClassWithSelfAndStaticCalls.php000066400000000000000000000012441360164303200370140ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/MissingImport. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; class Foo { public function testRuleNotAppliesToClassWithSelfAndStaticCalls() { $self = new self(); new static(); } } testRuleNotAppliesToClassWithoutAnyDependencies.php000066400000000000000000000011631360164303200371370ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/MissingImport. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; class Foo { public function testRuleNotAppliesToClassWithoutAnyDependencies() { } } testRuleNotAppliesToFunctionWithOnlyImportedDependencies.php000066400000000000000000000012011360164303200410160ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/MissingImport. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; use stdClass; function testRuleNotAppliesToFunctionWithOnlyImportedDependencies(){ $a = new stdClass(); } testRuleNotAppliesToFunctionWithoutAnyDependencies.php000066400000000000000000000011421360164303200376540ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/MissingImport. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; function testRuleNotAppliesToFunctionWithoutAnyDependencies(){ $a = null; } phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/StaticAccess/000077500000000000000000000000001360164303200246075ustar00rootroot00000000000000testRuleAppliesToStaticMethodAccess.php000077500000000000000000000011471360164303200343320ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/StaticAccess. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class Foo { public function testRuleAppliesToStaticMethodAccess() { Foo::create(); } } testRuleAppliesToStaticMethodAccessWhenNotAllExcluded.php000077500000000000000000000012271360164303200377430ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/StaticAccess. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class Foo { public function testRuleAppliesToStaticMethodAccessWhenNotAllExcluded() { Excluded::foo(); NotExcluded::bar(); } } testRuleNotAppliesToConstantAccess.php000077500000000000000000000011411360164303200342060ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/StaticAccess. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class Foo { public function testRuleNotAppliesToConstantAccess() { Foo::BAR; } } testRuleNotAppliesToDynamicMethodCall.php000077500000000000000000000012011360164303200346110ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/StaticAccess. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class Foo { public function testRuleNotAppliesToDynamicMethodCall() { $foo = new Foo(); $foo->bar(); } } testRuleNotAppliesToParentStaticCall.php000077500000000000000000000011721360164303200344740ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/StaticAccess. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class Foo extends Bar { public function testRuleNotAppliesToParentStaticCall() { parent::otherCall(); } } testRuleNotAppliesToSelfStaticCall.php000077500000000000000000000012501360164303200341310ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/StaticAccess. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace test\resources\files\Rule\CleanCode\StaticAccess; class Foo { static public function testRuleNotAppliesToSelfStaticCall() { self::bar(); } } testRuleNotAppliesToStaticMethodAccessWhenExcluded.php000077500000000000000000000012151360164303200373070ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/StaticAccess. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class Foo { public function testRuleNotAppliesToStaticMethodAccessWhenExcluded() { Excluded1::foo(); Excluded2::bar(); } } phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/UndefinedVariable/000077500000000000000000000000001360164303200256055ustar00rootroot00000000000000testRuleAppliesToUndefinedVariable.php000066400000000000000000000011701360164303200351560ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/UndefinedVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToUndefinedVariable { function testRuleAppliesToUndefinedVariable() { echo $x; } } testRuleAppliesToUndefinedVariableOnArray.php000066400000000000000000000012621360164303200364540ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/UndefinedVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToUndefinedVariableOnArray extends AbstractTest { function testRuleAppliesToUndefinedVariableOnArray() { $x = [42, $y]; echo $x; } } testRuleAppliesToUndefinedVariableOnArrayWithKeys.php000066400000000000000000000013101360164303200401360ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/UndefinedVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToUndefinedVariableOnArray extends AbstractTest { function testRuleAppliesToUndefinedVariableOnArrayWithKeys() { $x = ['a' => 42, 'b' => $y]; echo $x; } } testRuleAppliesToUndefinedVariableWithDefinedVariable.php000066400000000000000000000013101360164303200407330ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/UndefinedVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToUndefinedVariableWithDefinedVariable extends AbstractTest { function testRuleAppliesToUndefinedVariableWithDefinedVariable() { $x = 42; echo $x, $y; } } testRuleDoesNotApplyToSuperGlobals.php000066400000000000000000000013171360164303200352000ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/UndefinedVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToSuperGlobals { function testRuleDoesNotApplyToSuperGlobals() { return array($_POST, $_GET, $_COOKIE, $GLOBALS, $_SERVER, $_REQUEST, $_SERVER, $_ENV, $_FILES); } } testRuleDoesNotApplyToUsedProperties.php000066400000000000000000000012621360164303200355520ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/CleanCode/UndefinedVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToUsedProperties extends AbstractTest { protected $x = 'abc'; function testRuleDoesNotApplyToUsedProperties() { echo $this->x; } } phpmd-2.8.1/src/test/resources/files/Rule/Controversial/000077500000000000000000000000001360164303200232535ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Controversial/CamelCaseMethodName/000077500000000000000000000000001360164303200270325ustar00rootroot00000000000000testRuleAppliesToTestMethodWithTwoUnderscoresEvenWhenOneIsAllowed.php000066400000000000000000000012241360164303200445650ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Controversial/CamelCaseMethodName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToTestMethodWithTwoUnderscoresEvenWhenOneIsAllowed { public function testGivenSomeValue_expectSome_niceResult() { } } testRuleAppliesToTestMethodWithUnderscoreFollowedByCapital.php000066400000000000000000000012101360164303200432620ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Controversial/CamelCaseMethodName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToTestMethodWithUnderscoreFollowedByCapital { public function testGivenSomeValue_ExpectSomeResult() { } } testRuleDoesApplyForMethodNameWithCapital.php000077500000000000000000000011571360164303200376660ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Controversial/CamelCaseMethodName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesApplyForMethodNameWithCapital { public function NotValidCamelCaseMethodName() { } } testRuleDoesApplyForMethodNameWithUnderscores.php000077500000000000000000000011461360164303200406030ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Controversial/CamelCaseMethodName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesApplyForMethodNameWithUnderscores { public function not_camel_case() { } } testRuleDoesApplyForTestMethodWithUnderscoreWhenNotAllowed.php000066400000000000000000000012101360164303200432570ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Controversial/CamelCaseMethodName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesApplyForTestMethodWithUnderscoreWhenNotAllowed { public function testGivenSomeValue_expectSomeResult() { } } testRuleDoesApplyForValidMethodNameWithUnderscoreWhenNotAllowed.php000077500000000000000000000012231360164303200442070ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Controversial/CamelCaseMethodName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesApplyForValidMethodNameWithUnderscoreWhenNotAllowed { function _camelCaseMethodNameWithUnderscoreAtTheBeginning() { } } testRuleDoesNotApplyForTestMethodWithUnderscoreWhenAllowed.php000066400000000000000000000012101360164303200432570ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Controversial/CamelCaseMethodName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyForTestMethodWithUnderscoreWhenAllowed { public function testGivenSomeValue_expectSomeResult() { } } testRuleDoesNotApplyForValidMethodName.php000077500000000000000000000011441360164303200371710ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Controversial/CamelCaseMethodName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyForValidMethodName { public function camelCaseMethodName() { } } testRuleDoesNotApplyForValidMethodNameWithUnderscoreWhenAllowed.php000077500000000000000000000012321360164303200442070ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Controversial/CamelCaseMethodName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyForValidMethodNameWithUnderscoreWhenAllowed { public function _camelCaseMethodNameWithUnderscoreAtTheBeginning() { } } phpmd-2.8.1/src/test/resources/files/Rule/Controversial/CamelCasePropertyName/000077500000000000000000000000001360164303200274365ustar00rootroot00000000000000testRuleDoesApplyForPropertyNameWithUnderscores.php000077500000000000000000000011401360164303200416050ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Controversial/CamelCasePropertyName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesApplyForPropertyNameWithUnderscores { public $not_camel_case_property_name; } testRuleDoesApplyForValidPropertyNameWithUnderscoreWhenNotAllowed.php000077500000000000000000000012101360164303200452130ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Controversial/CamelCasePropertyName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesApplyForValidPropertyNameWithUnderscoreWhenNotAllowed { public $_camelCasePropertyNameWithUnderscoreAtTheBeginning; } testRuleDoesNotApplyForPropertyNameWithCapital.php000077500000000000000000000011301360164303200413460ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Controversial/CamelCasePropertyName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyForPropertyNameWithCapital { public $AlsoValidPropertyName; } testRuleDoesNotApplyForValidPropertyName.php000077500000000000000000000011221360164303200401750ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Controversial/CamelCasePropertyName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyForValidPropertyName { public $camelCasePropertyName; } testRuleDoesNotApplyForValidPropertyNameWithNoUnderscoreWhenAllowed.php000066400000000000000000000012131360164303200455100ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Controversial/CamelCasePropertyName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyForValidPropertyNameWithNoUnderscoreWhenAllowed { public $camelCasePropertyNameWithNoUnderscoreAtTheBeginning; } testRuleDoesNotApplyForValidPropertyNameWithUnderscoreWhenAllowed.php000077500000000000000000000012101360164303200452130ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Controversial/CamelCasePropertyName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyForValidPropertyNameWithUnderscoreWhenAllowed { public $_camelCasePropertyNameWithUnderscoreAtTheBeginning; } phpmd-2.8.1/src/test/resources/files/Rule/Controversial/CamelCaseVariableName/000077500000000000000000000000001360164303200273375ustar00rootroot00000000000000testRuleDoesApplyForInvariableNameWithUnderscore.php000066400000000000000000000012311360164303200415510ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Controversial/CamelCaseVariableName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesApplyForInvariableNameWithUnderscore { public function invalidVariableNameWithUnderscore() { $data_module = 'foo'; } } testRuleDoesApplyForVariableNameWithCapital.php000066400000000000000000000012121360164303200404650ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Controversial/CamelCaseVariableName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesApplyForVariableNameWithCapital { public function validCapitalVariableName() { $DataModule = 'foo'; } } testRuleDoesNotApplyForStaticVariableAccess.php000066400000000000000000000012571360164303200405160ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Controversial/CamelCaseVariableName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyForStaticVariableAccess { public function validVariableName() { if (!in_array('foo', self::$invalid_variable_name)) { } } } testRuleDoesNotApplyForValidVariableName.php000066400000000000000000000012001360164303200377710ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Controversial/CamelCaseVariableName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyForValidVariableName { public function validVariableName() { $dataModule = 'foo'; } } phpmd-2.8.1/src/test/resources/files/Rule/Design/000077500000000000000000000000001360164303200216325ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/CountInLoopExpression/000077500000000000000000000000001360164303200261235ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/CountInLoopExpression/testMutedRuleAtClassLevel.php000066400000000000000000000015021360164303200337030ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; /** * @SuppressWarnings(PHPMD.CountInLoopExpression) */ class testMutedRuleAtClassLevel { public function testMutedRuleAtClassLevel() { $arr = array(0, 1, 2, 3, 4, 5); for ($i = 0; count($arr) < 0; $i++) { $foo = $arr[0] % 0; } return $foo; } } testMutedRuleAtMethodLevel.php000066400000000000000000000015201360164303200337770ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/CountInLoopExpression. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; class testMutedRuleAtMethodLevel { /** * @SuppressWarnings(PHPMD.CountInLoopExpression) */ public function testMutedRuleAtMethodLevel() { $arr = array(0, 1, 2, 3, 4, 5); for ($i = 0; count($arr) < 0; $i++) { $foo = $arr[0] % 0; } return $foo; } } testRuleAppliesToAllTypesOfLoops.php000066400000000000000000000016741360164303200351750ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/CountInLoopExpression. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; class testRuleAppliesToAllTypesOfLoops { public function testRuleAppliesToAllTypesOfLoops() { $arr = array(0, 1, 2, 3, 4, 5); for ($i = 0; count($arr) < 0; $i++) { $foo = $arr[0] % 0; } while (count($arr) || $foo === 'baz') { $foo = 0 < $arr[0]; } do { $foo = end($arr); } while (count($arr)); return $foo; } } testRuleApplyToNestedLoops.php000066400000000000000000000021361360164303200340570ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/CountInLoopExpression. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleApplyToNestedLoops() { $foo = 'foo'; for ($i = 0; sizeof($i) < 5 || $i < 5; $i++) { while ($i !== 'baz' && count($foo) || $i < 5) { $foo .= $i; do { $i += 2; } while (5 - 0 < sizeof($foo) && 3 < $foo . 'bar'); while (count($foo) < 5 && sizeof($foo) < 5 && count($foo) < 5) { while (count($_GET) > -1 && 0) { for ($j = 0; $j < count($_GET); $j++) { $i += $j * 2; } } } } } return $foo; } testRuleNotApplyToExpressionElsewhere.php000066400000000000000000000020251360164303200363010ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/CountInLoopExpression. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; class testRuleNotApplyToExpressionElsewhere { public function testRuleNotApplyToExpressionElsewhere() { $foo = 'foo'; $bar = 'bar'; for ($i = 0; $i < 5; $i++) { $foo .= $i; } if (sizeof($foo) < 5) { $bar = $foo; } for ($j = 0; $j < 1; $j++) { if (count($bar)) { return $foo; } elseif (sizeof($foo)) { return $bar; } } return $bar; } } phpmd-2.8.1/src/test/resources/files/Rule/Design/DevelopmentCodeFragment/000077500000000000000000000000001360164303200263735ustar00rootroot00000000000000testRuleAppliesToFunctionWithMultipleSuspectFunctionCall.php000066400000000000000000000012341360164303200424040ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/DevelopmentCodeFragment. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleAppliesToFunctionWithMultipleSuspectFunctionCall() { var_dump(__FUNCTION__); debug_print_backtrace(); debug_zval_dump($GLOBALS); } testRuleAppliesToFunctionWithSuspectFunctionCall.php000066400000000000000000000011271360164303200406710ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/DevelopmentCodeFragment. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleAppliesToFunctionWithSuspectFunctionCall() { print_r(__FUNCTION__); } testRuleAppliesToMethodWithMultipleSuspectFunctionCall.php000066400000000000000000000013711360164303200420410ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/DevelopmentCodeFragment. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class class_testRuleAppliesToMethodWithMultipleSuspectFunctionCall { public function testRuleAppliesToMethodWithMultipleSuspectFunctionCall() { var_dump(__FUNCTION__); print_r(__METHOD__); debug_zval_dump($this); } } testRuleAppliesToMethodWithSuspectFunctionCall.php000066400000000000000000000012521360164303200403230ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/DevelopmentCodeFragment. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class class_testRuleAppliesToMethodWithSuspectFunctionCall { public function testRuleAppliesToMethodWithSuspectFunctionCall() { var_dump(__METHOD__); } } testRuleAppliesToMethodWithinNamespace.php000066400000000000000000000012321360164303200366140ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/DevelopmentCodeFragment. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToMethodWithinNamespace { public function __construct($test = 'Test') { var_dump($test); } } testRuleNotAppliesToFunctionWithoutSuspectFunctionCall.php000066400000000000000000000011311360164303200420750ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/DevelopmentCodeFragment. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleNotAppliesToFunctionWithoutSuspectFunctionCall() { echo __FUNCTION__; } testRuleNotAppliesToMethodWithinNamespaceByDefault.php000066400000000000000000000012461360164303200411020ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/DevelopmentCodeFragment. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleNotAppliesToMethodWithinNamespaceByDefault { public function __construct($test = 'Test') { var_dump($test); } } testRuleNotAppliesToMethodWithoutSuspectFunctionCall.php000066400000000000000000000012631360164303200415360ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/DevelopmentCodeFragment. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class class_testRuleNotAppliesToMethodWithoutSuspectFunctionCall { public function testRuleNotAppliesToMethodWithoutSuspectFunctionCall() { echo __FUNCTION__; } } phpmd-2.8.1/src/test/resources/files/Rule/Design/EmptyCatchBlock/000077500000000000000000000000001360164303200246465ustar00rootroot00000000000000testRuleAppliesToFunctionWithEmptyCatchBlock.php000066400000000000000000000013741360164303200362340ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/EmptyCatchBlock. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleAppliesToFunctionWithEmptyCatchBlock() { try { // ... } catch (Exception $e) { } try { // ... } catch (OutOfRangeException $e) { } try { // ... } catch (\ErrorException $e) { } } testRuleNotAppliesToCatchBlockWithComments.php000066400000000000000000000020331360164303200356670ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/EmptyCatchBlock. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleNotAppliesToCatchBlockWithComments() { try { // ... } catch (Exception $e) { // valid line of code } try { // ... } catch (Exception $e) { /** * valid line of code */ } try { // ... } catch (Exception $e) { /** valid line of code */ } try { // ... } catch (Exception $e) { /** /** valid line of code */ } try { // ... } catch (Exception $e) { # valid line of code } } testRuleNotAppliesToFunctionWithNonEmptyCatchBlock.php000066400000000000000000000012341360164303200373630ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/EmptyCatchBlock. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleNotAppliesToFunctionWithNonEmptyCatchBlock() { try { // ... } catch (OutOfBoundsException $e) { $e->getLine(); } } testRuleNotAppliesToMethodWithoutTryCatchBlock.php000066400000000000000000000013651360164303200365600ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/EmptyCatchBlock. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; class Foo { public function testRuleNotAppliesToMethodWithoutTryCatchBlock() { $foo = 'bar'; $abc = 'xyz'; if ($foo === 'baz') { $abc = 'def'; } return $abc; } } testRuleWorksWithNestedTryCatchBlocksAndNonSPLExceptions.php000066400000000000000000000015041360164303200404530ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/EmptyCatchBlock. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleWorksWithNestedTryCatchBlocksAndNonSPLExceptions() { try { // ... } catch (OutOfRangeException $e) { try { // ... } catch (PHPUnit_Framework_Exception $e) { try { // ... } catch (Exception $e) { } } } } phpmd-2.8.1/src/test/resources/files/Rule/Design/EvalExpression/000077500000000000000000000000001360164303200246015ustar00rootroot00000000000000testRuleAppliesMultipleTimesToFunctionWithEvalExpression.php000077500000000000000000000013101360164303200406310ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/EvalExpression. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleAppliesMultipleTimesToFunctionWithEvalExpression() { if (true) { eval('$a = 17;'); } else if (time() % 42 === 0) { eval('$a = 23;'); } eval('$a = 42;'); } testRuleAppliesMultipleTimesToMethodWithEvalExpression.php000077500000000000000000000014621360164303200402740ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/EvalExpression. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesMultipleTimesToMethodWithEvalExpression { public function testRuleAppliesMultipleTimesToMethodWithEvalExpression() { if (true) { eval('$a = 17;'); } else if (time() % 42 === 0) { eval('$a = 23;'); } eval('$a = 42;'); } } testRuleAppliesToFunctionWithEvalExpression.php000077500000000000000000000011151360164303200361160ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/EvalExpression. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleAppliesToFunctionWithEvalExpression() { eval('$a = 42;'); } testRuleAppliesToMethodWithEvalExpression.php000077500000000000000000000012311360164303200355500ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/EvalExpression. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToMethodWithEvalExpression { protected function testRuleAppliesToMethodWithEvalExpression() { eval('$a = 42;'); } } testRuleNotAppliesToFunctionWithoutEvalExpression.php000077500000000000000000000011241360164303200373270ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/EvalExpression. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleNotAppliesToFunctionWithoutEvalExpression() { echo __FUNCTION__; } testRuleNotAppliesToMethodWithoutEvalExpression.php000077500000000000000000000012411360164303200367620ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/EvalExpression. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleNotAppliesToMethodWithoutEvalExpression { public function testRuleNotAppliesToMethodWithoutEvalExpression() { echo __METHOD__; } } phpmd-2.8.1/src/test/resources/files/Rule/Design/ExitExpression/000077500000000000000000000000001360164303200246235ustar00rootroot00000000000000testRuleAppliesMultipleTimesToFunctionWithExitExpression.php000077500000000000000000000012551360164303200407050ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/ExitExpression. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleAppliesMultipleTimesToFunctionWithExitExpression() { if (true) { exit(0); } else if (time() % 42 === 0) { exit(1); } exit(2); } testRuleAppliesMultipleTimesToMethodWithExitExpression.php000077500000000000000000000014271360164303200403410ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/ExitExpression. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesMultipleTimesToMethodWithExitExpression { public function testRuleAppliesMultipleTimesToMethodWithExitExpression() { if (true) { exit(0); } else if (time() % 42 === 0) { exit(1); } exit(2); } } testRuleAppliesToFunctionWithExitExpression.php000077500000000000000000000011041360164303200361600ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/ExitExpression. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleAppliesToFunctionWithExitExpression() { exit(0); } testRuleAppliesToMethodWithExitExpression.php000077500000000000000000000012201360164303200356120ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/ExitExpression. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToMethodWithExitExpression { protected function testRuleAppliesToMethodWithExitExpression() { exit(0); } } testRuleNotAppliesToFunctionWithoutExitExpression.php000077500000000000000000000011241360164303200373730ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/ExitExpression. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleNotAppliesToFunctionWithoutExitExpression() { echo __FUNCTION__; } testRuleNotAppliesToMethodWithoutExitExpression.php000077500000000000000000000012411360164303200370260ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/ExitExpression. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleNotAppliesToMethodWithoutExitExpression { public function testRuleNotAppliesToMethodWithoutExitExpression() { echo __METHOD__; } } phpmd-2.8.1/src/test/resources/files/Rule/Design/GotoStatement/000077500000000000000000000000001360164303200244275ustar00rootroot00000000000000testRuleAppliesToFunctionWithGotoStatement.php000077500000000000000000000012211360164303200355700ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/GotoStatement. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleAppliesToFunctionWithGotoStatement() { LABEL: echo 'FOOBAR'; if (time() % 23 === 42) { goto LABEL; } } testRuleAppliesToMethodWithGotoStatement.php000077500000000000000000000013521360164303200352300ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/GotoStatement. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToMethodWithGotoStatementClass { public function testRuleAppliesToMethodWithGotoStatement() { LABEL: echo 'YES'; if (time() % 42 === 0) { goto LABEL; } } } testRuleNotAppliesToFunctionWithoutGotoStatement.php000077500000000000000000000011261360164303200370050ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/GotoStatement. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleNotAppliesToFunctionWithoutGotoStatement($foo) { return 42 * $foo; } testRuleNotAppliesToMethodWithoutGotoStatement.php000077500000000000000000000012441360164303200364410ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Design/GotoStatement. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleNotAppliesToMethodWithoutGotoStatementClass { public function testRuleNotAppliesToMethodWithoutGotoStatement($foo) { return $foo; } } phpmd-2.8.1/src/test/resources/files/Rule/Naming/000077500000000000000000000000001360164303200216325ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/BooleanGetMethodName/000077500000000000000000000000001360164303200256135ustar00rootroot00000000000000testRuleAppliesToMethodStartingWithGetAndReturningBool.php000077500000000000000000000012011360164303200412000ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/BooleanGetMethodName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToMethodStartingWithGetAndReturningBool { /** * @return Bool */ public function getBaz() {} } testRuleAppliesToMethodStartingWithGetAndReturningBoolean.php000077500000000000000000000012241360164303200416710ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/BooleanGetMethodName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToMethodStartingWithGetAndReturningBoolean { /** * @return boolean */ public function getFooBar() { } } testRuleAppliesToPearPrivateMethodStartingWithGetAndReturningBoolean.php000077500000000000000000000012401360164303200440320ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/BooleanGetMethodName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToPearPrivateMethodStartingWithGetAndReturningBoolean { /** * @return boolean */ private function getFooBar() { } } testRuleIgnoresParametersWhenNotExplicitConfigured.php000077500000000000000000000011751360164303200404510ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/BooleanGetMethodName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleIgnoresParametersWhenNotExplicitConfigured { /** * @return boolean */ function getBaz($foo) {} } testRuleNotAppliesToMethodStartingWithHas.php000077500000000000000000000011561360164303200365310ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/BooleanGetMethodName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleNotAppliesToMethodStartingWithHas { /** * @return boolean */ function hasX() {} } testRuleNotAppliesToMethodStartingWithIs.php000077500000000000000000000011561360164303200363710ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/BooleanGetMethodName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleNotAppliesToMethodStartingWithIs { /** * @return boolean */ function isBaz() {} } testRuleNotAppliesToMethodWithReturnTypeNotBoolean.php000077500000000000000000000012031360164303200403750ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/BooleanGetMethodName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleNotAppliesToMethodWithReturnTypeNotBoolean { /** * @return array(boolean) */ function getFooBar() {} } testRuleNotAppliesWhenParametersAreExplicitEnabled.php000077500000000000000000000012041360164303200403260ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/BooleanGetMethodName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleNotAppliesWhenParametersAreExplicitEnabled { /** * @return boolean */ public function getBaz($foo) {} } phpmd-2.8.1/src/test/resources/files/Rule/Naming/ConstantNamingConventions/000077500000000000000000000000001360164303200270035ustar00rootroot00000000000000testRuleAppliesToClassConstantWithLowerCaseCharacters.php000077500000000000000000000011761360164303200422360ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ConstantNamingConventions. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToClassConstantWithLowerCaseCharacters { const T_FOO = 42; const T_Bar = 23, t_baz = 17; } testRuleAppliesToInterfaceConstantWithLowerCaseCharacters.php000077500000000000000000000011621360164303200430640ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ConstantNamingConventions. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ interface testRuleAppliesToInterfaceConstantWithLowerCaseCharacters { const t_foo = 42, t_bar = 23, t_baz = 17; } testRuleNotAppliesToClassConstantWithUpperCaseCharacters.php000077500000000000000000000012001360164303200427060ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ConstantNamingConventions. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleNotAppliesToClassConstantWithUpperCaseCharacters { const T_FOO =42, T_BAR = 23, T_BAZ = 17; } testRuleNotAppliesToInterfaceConstantWithUpperCaseCharacters.php000077500000000000000000000012131360164303200435450ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ConstantNamingConventions. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ interface testRuleNotAppliesToInterfaceConstantWithUpperCaseCharacters { const T_FOO = 42; const T_BAR = 23; const T_BAZ = 17; } phpmd-2.8.1/src/test/resources/files/Rule/Naming/ConstructorWithNameAsEnclosingClass/000077500000000000000000000000001360164303200307305ustar00rootroot00000000000000testRuleAppliesToConstructorMethodNamedAsEnclosingClass.php000077500000000000000000000012221360164303200445020ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ConstructorWithNameAsEnclosingClass. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToConstructorMethodNamedAsEnclosingClass { function testRuleAppliesToConstructorMethodNamedAsEnclosingClass() { } } testRuleAppliesToConstructorMethodNamedAsEnclosingClassCaseInsensitive.php000077500000000000000000000012601360164303200475210ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ConstructorWithNameAsEnclosingClass. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testruleappliestoconstructormethodnamedasenclosingclasscaseinsensitive { function testRuleAppliesToConstructorMethodNamedAsEnclosingClassCaseInsensitive() { } } testRuleNotAppliesToMethodInNamespaces.php000077500000000000000000000012001360164303200411170ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ConstructorWithNameAsEnclosingClass. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace Foo; class testRuleNotAppliesToMethodInNamespaces { function testRuleNotAppliesToMethodInNamespaces() { } } testRuleNotAppliesToMethodNamedAsEnclosingInterface.php000077500000000000000000000012021360164303200435460ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ConstructorWithNameAsEnclosingClass. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ interface testRuleNotAppliesToMethodNamedAsEnclosingInterface { function testRuleNotAppliesToMethodNamedAsEnclosingInterface(); } testRuleNotAppliesToMethodNamedSimilarToEnclosingClass.php000077500000000000000000000012141360164303200442560ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ConstructorWithNameAsEnclosingClass. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class RuleNotAppliesToMethodNamedSimilarToEnclosingClass { function testRuleNotAppliesToMethodNamedSimilarToEnclosingClass() { } } phpmd-2.8.1/src/test/resources/files/Rule/Naming/LongVariable/000077500000000000000000000000001360164303200241775ustar00rootroot00000000000000testRuleAppliesForLongPrivateProperty.php000077500000000000000000000011501360164303200343450ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/LongVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesForLongPrivateProperty { private $testRuleNotAppliesForLongPrivateProperty = 42; } testRuleAppliesForLongPrivateStaticProperty.php000077500000000000000000000011731360164303200355220ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/LongVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesForLongPrivateStaticProperty { private static $testRuleNotAppliesForLongPrivateStaticProperty = 23; } testRuleAppliesToFieldAndParameterWithNameLongerThanThreshold.php000077500000000000000000000013031360164303200410050ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/LongVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToFieldAndParameterWithNameLongerThanThreshold { protected $_foo; protected function testRuleAppliesToFieldAndParameterWithNameLongerThanThreshold($fooB) { } } testRuleAppliesToFieldWithNameLongerThanThreshold.php000077500000000000000000000011521360164303200365230ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/LongVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToFieldWithNameLongerThanThreshold { protected $thisReallyLongClassFieldName = 42; } testRuleAppliesToFunctionParameterWithNameLongerThanThreshold.php000077500000000000000000000011501360164303200411240ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/LongVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleAppliesToFunctionParameterWithNameLongerThanThreshold($thisIsAReallyLongParameterName) { } testRuleAppliesToIdenticalVariableOnlyOneTime.php000077500000000000000000000014771360164303200357030ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/LongVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToIdenticalVariableOnlyOneTime { function testRuleAppliesToIdenticalVariableOnlyOneTime() { $thisIsTheFirstReallyLongVariable = 23; $thisIsTheSecondReallyLongVariable = 42; $thisIsTheFirstReallyLongVariable = 42; $thisIsTheSecondReallyLongVariable = 23; } } testRuleAppliesToIdenticalVariablesInDifferentContextsSeveralTimes.php000077500000000000000000000015371360164303200421320ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/LongVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToIdenticalVariablesInDifferentContextsSeveralTimes { function testRuleAppliesToIdenticalVariablesInDifferentContextsSeveralTimes() { $reallyLongLocalVariableName = 23; } function testRuleAppliesToIdenticalVariablesInDifferentContextsSeveralTimesTwo() { $reallyLongLocalVariableName = 42; } } testRuleAppliesToLocalVariableInFunctionWithNameLongerThanThreshold.php000077500000000000000000000011611360164303200421750ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/LongVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleAppliesToLocalVariableInFunctionWithNameLongerThanThreshold() { $reallyLongVariableName = 42; } testRuleAppliesToLocalVariableInMethodWithNameLongerThanThreshold.php000077500000000000000000000013231360164303200416300ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/LongVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToLocalVariableInMethodWithNameLongerThanThreshold { function testRuleAppliesToLocalVariableInMethodWithNameLongerThanThreshold() { $thisIsAReallyLongLocalVariable = 42; } } testRuleAppliesToMethodParameterWithNameLongerThanThreshold.php000077500000000000000000000012701360164303200405620ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/LongVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToMethodParameterWithNameLongerThanThreshold { function testRuleAppliesToMethodParameterWithNameLongerThanThreshold($thisIsLongMethodParameterName) { } } testRuleNotAppliesToFieldWithNameEqualToThreshold.php000077500000000000000000000011151360164303200365140ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/LongVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleNotAppliesToFieldWithNameEqualToThreshold { private $fooBar; } testRuleNotAppliesToFieldWithNameShorterThanThreshold.php000077500000000000000000000011251360164303200374040ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/LongVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleNotAppliesToFieldWithNameShorterThanThreshold { private $fooBar = 0; } testRuleNotAppliesToFunctionParameterWithNameSmallerThanThreshold.php000077500000000000000000000011241360164303200417570ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/LongVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleNotAppliesToFunctionParameterWithNameSmallerThanThreshold($fooBar) { } testRuleNotAppliesToLocalVariableInFunctionWithNameEqualToThreshold.php000077500000000000000000000011411360164303200421650ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/LongVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleNotAppliesToLocalVariableInFunctionWithNameEqualToThreshold() { $fooBar = 42; } testRuleNotAppliesToLocalVariableInFunctionWithNameSmallerThanThreshold.php000077500000000000000000000011451360164303200430310ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/LongVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleNotAppliesToLocalVariableInFunctionWithNameSmallerThanThreshold() { $fooBar = 42; } testRuleNotAppliesToLocalVariableInMethodWithNameEqualToThreshold.php000077500000000000000000000012731360164303200416260ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/LongVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleNotAppliesToLocalVariableInMethodWithNameEqualToThreshold { function testRuleNotAppliesToLocalVariableInMethodWithNameEqualToThreshold() { $fooBar = 42; } } testRuleNotAppliesToLocalVariableInMethodWithNameShorterThanThreshold.php000077500000000000000000000013031360164303200425070ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/LongVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleNotAppliesToLocalVariableInMethodWithNameShorterThanThreshold { function testRuleNotAppliesToLocalVariableInMethodWithNameShorterThanThreshold() { $fooBar = 42; } } testRuleNotAppliesToMethodParameterWithNameShorterThanThreshold.php000077500000000000000000000012511360164303200414420ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/LongVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleNotAppliesToMethodParameterWithNameShorterThanThreshold { function testRuleNotAppliesToMethodParameterWithNameShorterThanThreshold($fooBar) { } } testRuleNotAppliesToStaticMembersAccessedInMethod.php000077500000000000000000000014471360164303200365210ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/LongVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleNotAppliesToStaticMembersAccessedInMethodClass { private static $testRuleNotAppliesToStaticMembersAccessedInMethod; public static function testRuleNotAppliesToStaticMembersAccessedInMethod() { self::$testRuleNotAppliesToStaticMembersAccessedInMethod = 42; } } phpmd-2.8.1/src/test/resources/files/Rule/Naming/ShortMethodName/000077500000000000000000000000001360164303200246735ustar00rootroot00000000000000testRuleAppliesToFunctionWithNameShorterThanThreshold.php000077500000000000000000000011021360164303200401540ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ShortMethodName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleAppliesToFunctionWithNameShorterThanThreshold() { } testRuleAppliesToMethodWithNameShorterThanThreshold.php000077500000000000000000000012121360164303200376110ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ShortMethodName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToMethodWithNameShorterThanThreshold { function testRuleAppliesToMethodWithNameShorterThanThreshold() { } } testRuleNotAppliesToFunctionWithNameEqualToThreshold.php000077500000000000000000000011001360164303200377440ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ShortMethodName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleNotAppliesToFunctionWithNameEqualToThreshold() { } testRuleNotAppliesToFunctionWithNameLongerThanThreshold.php000077500000000000000000000011041360164303200404370ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ShortMethodName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleNotAppliesToFunctionWithNameLongerThanThreshold() { } testRuleNotAppliesToMethodWithNameEqualToThreshold.php000077500000000000000000000012101360164303200374010ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ShortMethodName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleNotAppliesToMethodWithNameEqualToThreshold { function testRuleNotAppliesToMethodWithNameEqualToThreshold() { } } testRuleNotAppliesToMethodWithNameLongerThanThreshold.php000077500000000000000000000012161360164303200400760ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ShortMethodName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleNotAppliesToMethodWithNameLongerThanThreshold { function testRuleNotAppliesToMethodWithNameLongerThanThreshold() { } } testRuleNotAppliesToMethodWithShortNameWhenException.php000077500000000000000000000012231360164303200377560ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ShortMethodName. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleNotAppliesToMethodWithShortNameWhenException { public function testRuleNotAppliesToMethodWithShortNameWhenException() { } } phpmd-2.8.1/src/test/resources/files/Rule/Naming/ShortVariable/000077500000000000000000000000001360164303200243775ustar00rootroot00000000000000testRuleAppliesToFieldAndParameterWithNameShorterThanThreshold.php000077500000000000000000000012631360164303200414120ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ShortVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToFieldAndParameterWithNameShorterThanThreshold { protected $_x; public function testRuleAppliesToFieldAndParameterWithNameShorterThanThreshold($x) {} } testRuleAppliesToFieldWithNameShorterThanThreshold.php000077500000000000000000000011161360164303200371230ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ShortVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToFieldWithNameShorterThanThreshold { private $fo = 0; } testRuleAppliesToFunctionParameterWithNameShorterThanThreshold.php000077500000000000000000000011151360164303200415250ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ShortVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleAppliesToFunctionParameterWithNameShorterThanThreshold($x) { } testRuleAppliesToIdenticalVariableOnlyOneTime.php000077500000000000000000000013011360164303200360650ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ShortVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToIdenticalVariableOnlyOneTime { function testRuleAppliesToIdenticalVariableOnlyOneTime() { $x = 23; $y = 42; $x = 42; $y = 23; } } testRuleAppliesToIdenticalVariablesInDifferentContextsSeveralTimes.php000077500000000000000000000014541360164303200423300ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ShortVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToIdenticalVariablesInDifferentContextsSeveralTimes { function testRuleAppliesToIdenticalVariablesInDifferentContextsSeveralTimes() { $x = 42; } function testRuleAppliesToIdenticalVariablesInDifferentContextsSeveralTimesNext() { $x = 23; } } testRuleAppliesToLocalVariableInFunctionWithNameShorterThanThreshold.php000077500000000000000000000011361360164303200425770ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ShortVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleAppliesToLocalVariableInFunctionWithNameShorterThanThreshold() { $xy = 42; } testRuleAppliesToLocalVariableInMethodWithNameShorterThanThreshold.php000077500000000000000000000012711360164303200422320ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ShortVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToLocalVariableInMethodWithNameShorterThanThreshold { function testRuleAppliesToLocalVariableInMethodWithNameShorterThanThreshold() { $fo = 42; } } testRuleAppliesToMethodParameterWithNameShorterThanThreshold.php000077500000000000000000000012341360164303200411620ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ShortVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToMethodParameterWithNameShorterThanThreshold { public function testRuleAppliesToMethodParameterWithNameShorterThanThreshold($fo) {} } testRuleNotAppliesToFieldWithNameEqualToThreshold.php000077500000000000000000000011171360164303200367160ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ShortVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleNotAppliesToFieldWithNameEqualToThreshold { private $foo = 42; } testRuleNotAppliesToFieldWithNameGreaterThanThreshold.php000077500000000000000000000011231360164303200375450ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ShortVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleNotAppliesToFieldWithNameGreaterThanThreshold { private $foo = 42; } testRuleNotAppliesToFunctionParameterWithNameLongerThanThreshold.php000077500000000000000000000011231360164303200420050ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ShortVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleNotAppliesToFunctionParameterWithNameLongerThanThreshold($fooBar) { } testRuleNotAppliesToLocalVariableInFunctionWithNameEqualToThreshold.php000077500000000000000000000011361360164303200423710ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ShortVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleNotAppliesToLocalVariableInFunctionWithNameEqualToThreshold() { $foo = 42; } testRuleNotAppliesToLocalVariableInFunctionWithNameLongerThanThreshold.php000077500000000000000000000011441360164303200430570ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ShortVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleNotAppliesToLocalVariableInFunctionWithNameLongerThanThreshold() { $foo = "BAR"; } testRuleNotAppliesToLocalVariableInMethodWithNameEqualToThreshold.php000077500000000000000000000012701360164303200420230ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ShortVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleNotAppliesToLocalVariableInMethodWithNameEqualToThreshold { function testRuleNotAppliesToLocalVariableInMethodWithNameEqualToThreshold() { $foo = 42; } } testRuleNotAppliesToLocalVariableInMethodWithNameLongerThanThreshold.php000077500000000000000000000013131360164303200425100ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ShortVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleNotAppliesToLocalVariableInMethodWithNameLongerThanThreshold { protected function testRuleNotAppliesToLocalVariableInMethodWithNameLongerThanThreshold() { $foo = "BAR"; } } testRuleNotAppliesToMethodParameterWithNameLongerThanThreshold.php000077500000000000000000000012321360164303200414410ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ShortVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleNotAppliesToMethodParameterWithNameLongerThanThreshold { function testRuleNotAppliesToMethodParameterWithNameLongerThanThreshold($foo) {} } testRuleNotAppliesToShortVariableNameAsForLoopIndex.php000077500000000000000000000011501360164303200372060ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ShortVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleNotAppliesToShortVariableNameAsForLoopIndex() { for ($i = 0; $i < 42; ++$i) { } } testRuleNotAppliesToShortVariableNameAsForeachLoopIndex.php000077500000000000000000000011611360164303200400310ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ShortVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleNotAppliesToShortVariableNameAsForeachLoopIndex() { foreach ($array as $i => $value) { } } testRuleNotAppliesToShortVariableNameInCatchStatement.php000077500000000000000000000011701360164303200375520ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ShortVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleNotAppliesToShortVariableNameInCatchStatement() { try { foo(); } catch (Exception $e) {} } testRuleNotAppliesToStaticMembersAccessedInMethod.php000077500000000000000000000013161360164303200367140ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ShortVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleNotAppliesToStaticMembersAccessedInMethodClass { private static $fo = 42; public static function testRuleNotAppliesToStaticMembersAccessedInMethod() { self::$fo = 42; } } testRuleNotAppliesToVariablesFromExceptionsList.php000077500000000000000000000012151360164303200365170ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/Naming/ShortVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleNotAppliesToVariablesFromExceptionsList { private $id; public function setID($id) { $this->id = $id; } } phpmd-2.8.1/src/test/resources/files/Rule/UnusedFormalParameter/000077500000000000000000000000001360164303200246665ustar00rootroot00000000000000testCompactFunctionRuleDoesNotApply.php000077500000000000000000000012401360164303200344460ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedFormalParameter. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testCompactFunctionRuleDoesNotApply { public function testCompactFunctionRuleDoesNotApply($foo, $bar) { return compact('foo', 'bar'); } } testCompactFunctionRuleOnlyAppliesToUsedParameters.php000077500000000000000000000012751360164303200375040ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedFormalParameter. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testCompactFunctionRuleOnlyAppliesToUsedParameters { public function testCompactFunctionRuleOnlyAppliesToUsedParameters($foo, $bar, $baz) { return compact('bar'); } } testCompactFunctionRuleWorksCaseInsensitive.php000077500000000000000000000012601360164303200362110ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedFormalParameter. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testCompactFunctionRuleWorksCaseInsensitive { public function testCompactFunctionRuleWorksCaseInsensitive($foo, $bar) { return Compact('foo', 'bar'); } } testFuncGetArgsRuleWorksCaseInsensitive.php000077500000000000000000000012411360164303200352640ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedFormalParameter. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testFuncGetArgsRuleWorksCaseInsensitive { function testFuncGetArgsRuleWorksCaseInsensitive($foo, $bar, $baz) { return Func_Get_Args(); } } testNamespacedCompactFunctionRuleDoesNotApply.php000077500000000000000000000013121360164303200364270ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedFormalParameter. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; class testNamespacedCompactFunctionRuleDoesNotApply { public function testNamespacedCompactFunctionRuleDoesNotApply($foo, $bar) { return compact('foo', 'bar'); } } testNamespacedCompactFunctionRuleOnlyAppliesToUsedParameters.php000077500000000000000000000013471360164303200414650ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedFormalParameter. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; class testNamespacedCompactFunctionRuleOnlyAppliesToUsedParameters { public function testNamespacedCompactFunctionRuleOnlyAppliesToUsedParameters($foo, $bar, $baz) { return compact('bar'); } } testNamespacedCompactFunctionRuleWorksCaseInsensitive.php000077500000000000000000000013321360164303200401720ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedFormalParameter. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; class testNamespacedCompactFunctionRuleWorksCaseInsensitive { public function testNamespacedCompactFunctionRuleWorksCaseInsensitive($foo, $bar) { return Compact('foo', 'bar'); } } testRuleAppliesToFormalParameterWhenSimilarStaticMemberIsAccessed.php000077500000000000000000000013561360164303200423540ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedFormalParameter. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToFormalParameterWhenSimilarStaticMemberIsAccessed { public static $foo = array(); public function testRuleAppliesToFormalParameterWhenSimilarStaticMemberIsAccessed($foo) { self::$foo[] = 42; } } testRuleAppliesToFunctionUnusedFormalParameter.php000077500000000000000000000011211360164303200366420ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedFormalParameter. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleAppliesToFunctionUnusedFormalParameter($a, $b, $c) { $b = $c; } testRuleAppliesToMethodUnusedFormalParameter.php000077500000000000000000000012051360164303200363000ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedFormalParameter. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToMethodUnusedFormalParameter { public function testRuleAppliesToMethodUnusedFormalParameter($x) { } } testRuleAppliesToMultipleFunctionUnusedFormalParameter.php000077500000000000000000000011401360164303200403570ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedFormalParameter. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleAppliesToMultipleFunctionUnusedFormalParameter($x, $y, $z) { return $foobar; } testRuleAppliesToMultipleMethodUnusedFormalParameter.php000077500000000000000000000012531360164303200400170ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedFormalParameter. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToMultipleMethodUnusedFormalParameter { public function testRuleAppliesToMultipleMethodUnusedFormalParameter($x, $y) { return $z; } } testRuleDoesNotApplyToAbstractMethodFormalParameter.php000077500000000000000000000012321360164303200375640ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedFormalParameter. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ abstract class testRuleDoesNotApplyToAbstractMethodFormalParameter { abstract function testRuleDoesNotApplyToAbstractMethodFormalParameter($x, $y, $z); } testRuleDoesNotApplyToFormalParameterUsedAsParameterInStringCompoundVariable.php000066400000000000000000000004671360164303200445440ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedFormalParameterbar("${foo}"); } private function bar($foo) { return "who $foo?"; } } testRuleDoesNotApplyToFormalParameterUsedInCompoundExpression.php000077500000000000000000000013441360164303200416400ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedFormalParameter. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToFormalParameterUsedInCompoundExpression { public static $foo = null; public function testRuleDoesNotApplyToFormalParameterUsedInCompoundExpression($bar) { self::${$bar} = 42; } } testRuleDoesNotApplyToFormalParameterUsedInStringCompoundVariable.php000066400000000000000000000003271360164303200424120ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedFormalParameter. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToImplementedAbstractMethodClass extends testRuleDoesNotApplyToImplementedAbstractMethodParentClass { public function testRuleDoesNotApplyToImplementedAbstractMethod($foo, $bar, $baz) { } } abstract class testRuleDoesNotApplyToImplementedAbstractMethodParentClass { public abstract function testRuleDoesNotApplyToImplementedAbstractMethod($foo, $bar, $baz); } testRuleDoesNotApplyToImplementedInterfaceMethod.php000077500000000000000000000016021360164303200371040ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedFormalParameter. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToImplementedInterfaceMethodClass implements testRuleDoesNotApplyToImplementedInterfaceMethodInterface { public function testRuleDoesNotApplyToImplementedInterfaceMethod($foo, $bar, $baz) { } } interface testRuleDoesNotApplyToImplementedInterfaceMethodInterface { function testRuleDoesNotApplyToImplementedInterfaceMethod($foo, $bar, $baz); } testRuleDoesNotApplyToInheritMethod.php000077500000000000000000000015051360164303200344240ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedFormalParameter. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToInheritMethodClass extends testRuleDoesNotApplyToInheritMethodParentClass { public function testRuleDoesNotApplyToInheritMethod($foo, $bar) { } } class testRuleDoesNotApplyToInheritMethodParentClass { public function testRuleDoesNotApplyToInheritMethod($foo, $bar) { } } testRuleDoesNotApplyToInnerFunctionDeclaration.php000077500000000000000000000013171360164303200366110ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedFormalParameter. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleDoesNotApplyToInnerFunctionDeclaration($x, $y, $z) { function z_testRuleDoesNotApplyToInnerFunctionDeclaration( $a, $b, $c ) { } return ($x + $y + $z); } testRuleDoesNotApplyToInterfaceMethodFormalParameter.php000077500000000000000000000012161360164303200377230ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedFormalParameter. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ interface testRuleDoesNotApplyToInterfaceMethodFormalParameter { function testRuleDoesNotApplyToInterfaceMethodFormalParameter($x, $y, $z); } testRuleDoesNotApplyToMagicMethod.php000077500000000000000000000011631360164303200340420ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedFormalParameter. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToMagicMethod { public function __call($name, $args) { return $name; } } testRuleDoesNotApplyToMethodArgument.php000077500000000000000000000012201360164303200345760ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedFormalParameter. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToMethodArgument { public function testRuleDoesNotApplyToMethodArgument($foo) { $this->bar($foo); } } testRuleDoesNotApplyToMethodArgumentUsedAsArrayIndex.php000077500000000000000000000014271360164303200377030ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedFormalParameter. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToMethodArgumentUsedAsArrayIndex { private static $staticAttributes = array(); public function testRuleDoesNotApplyToMethodArgumentUsedAsArrayIndex(array $declaredClasses) { self::$staticAttributes[$declaredClasses[42]] = true; } } testRuleDoesNotApplyToMethodWithFuncGetArgs.php000077500000000000000000000012571360164303200360320ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedFormalParameter. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleNotDoesNotApplyToMethodWithFuncGetArgs { public function testRuleDoesNotApplyToMethodWithFuncGetArgs($foo, $bar) { print_r(func_get_args()); } } testRuleDoesNotApplyToMethodWithInheritdocAnnotation.php000077500000000000000000000013061360164303200400000ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedFormalParameter. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToMethodWithInheritdocAnnotation { /** * @inheritdoc */ public function testRuleDoesNotApplyToMethodWithInheritdocAnnotation($foo, $bar, $baz) { } } testRuleDoesNotApplyToMethodWithInheritdocAnnotationCamelCase.php000077500000000000000000000013301360164303200415330ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedFormalParameter. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToMethodWithInheritdocAnnotationCamelCase { /** * @inheritDoc */ public function testRuleDoesNotApplyToMethodWithInheritdocAnnotationCamelCase($foo, $bar, $baz) { } } testRuleDoesNotApplyToParameterUsedAsArrayIndex.php000077500000000000000000000012461360164303200366770ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedFormalParameter. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToParameterUsedAsArrayIndex { public function testRuleDoesNotApplyToParameterUsedAsArrayIndex($foo) { self::$bar[$foo]; } } testRuleDoesNotApplyToParameterUsedAsStringIndex.php000077500000000000000000000012501360164303200370620ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedFormalParameter. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToParameterUsedAsStringIndex { public function testRuleDoesNotApplyToParameterUsedAsStringIndex($foo) { self::$bar{$foo}; } } testRuleNotAppliesToFormalParameterUsedInMethodCompoundVariable.php000077500000000000000000000013051360164303200420610ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedFormalParameter. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleNotAppliesToFormalParameterUsedInMethodCompoundVariable { public function testRuleNotAppliesToFormalParameterUsedInMethodCompoundVariable($foo) { self::${$foo}(); } } testRuleNotAppliesToFormalParameterUsedInPropertyCompoundVariable.php000077500000000000000000000013051360164303200424650ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedFormalParameter. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleNotAppliesToFormalParameterUsedInPropertyCompoundVariable { function testRuleNotAppliesToFormalParameterUsedInPropertyCompoundVariable($foo) { self::${$foo} = 42; } } phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable/000077500000000000000000000000001360164303200243055ustar00rootroot00000000000000testCompactFunctionRuleWorksCaseInsensitive.php000077500000000000000000000013241360164303200356310ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testCompactFunctionRuleWorksCaseInsensitive { public function testCompactFunctionRuleWorksCaseInsensitive() { $foo = 1; $bar = 2; $baz = 0; return Compact('foo', 'bar', 'baz'); } } testInnerFunctionParametersDoNotHideUnusedVariables.php000077500000000000000000000012401360164303200372170ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testInnerFunctionParametersDoNotHideUnusedVariables() { $x = 42; function z_testInnerFunctionParametersDoNotHideUnusedVariables($x) { } } testNamespacedCompactFunctionRuleWorksCaseInsensitive.php000077500000000000000000000013761360164303200376210ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; class testNamespacedCompactFunctionRuleWorksCaseInsensitive { public function testNamespacedCompactFunctionRuleWorksCaseInsensitive() { $foo = 1; $bar = 2; $baz = 0; return Compact('foo', 'bar', 'baz'); } } testRuleAppliesToLocalVariableWithSameNameAsStaticArrayProperty.php000077500000000000000000000014071360164303200414600ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToLocalVariableWithSameNameAsStaticArrayProperty { protected $foo = array(array(1=>42)); public function testRuleAppliesToLocalVariableWithSameNameAsStaticArrayProperty() { $foo = 23; return self::$foo[0][1]; } } testRuleAppliesToLocalVariableWithSameNameAsStaticProperty.php000077500000000000000000000013341360164303200404600ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToLocalVariableWithSameNameAsStaticProperty { protected $foo = 42; function testRuleAppliesToLocalVariableWithSameNameAsStaticProperty() { $foo = 23; echo self::$foo; } } testRuleAppliesToUnusedForeachKeyWhenNotIgnored.php000077500000000000000000000013561360164303200363370ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToUnusedForeachKeyWhenNotIgnored { public function testRuleAppliesToUnusedForeachKeyWhenNotIgnored() { foreach ($this->index as $key => $value) { self::$string{$value} = 'a'; } } } testRuleAppliesToUnusedForeachValueWhenNotIgnored.php000077500000000000000000000013601360164303200366560ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToUnusedForeachValueWhenNotIgnored { public function testRuleAppliesToUnusedForeachValueWhenNotIgnored() { foreach ($this->index as $key => $value) { self::$string{$key} = 'a'; } } } testRuleAppliesToUnusedLocalVariable.php000077500000000000000000000011741360164303200342020ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToUnusedLocalVariable { function testRuleAppliesToUnusedLocalVariable() { $x = 42; } } testRuleDoesApplyToCompoundVariableInString.php000066400000000000000000000012621360164303200355240ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesApplyToCompoundVariableInString { public function testRuleDoesApplyToCompoundVariableInString() { $bar = 'foo'; return "${bar}_me"; } } testRuleDoesNotAppliesToWhitelistedUnusedLocaleVariable.php000066400000000000000000000002541360164303200400440ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToArgcSuperGlobal { function testRuleDoesNotApplyToArgcSuperGlobal() { return $argc; } } testRuleDoesNotApplyToArgvSuperGlobal.php000077500000000000000000000012031360164303200343320ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToArgvSuperGlobal { function testRuleDoesNotApplyToArgvSuperGlobal() { return $argv; } } testRuleDoesNotApplyToCatchStatement.php000077500000000000000000000012531360164303200342070ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToCatchStatement { public function testRuleDoesNotApplyToCatchStatement() { try { } catch (Exception $e) { } } } testRuleDoesNotApplyToCompactFunction.php000077500000000000000000000012501360164303200343710ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToCompactFunction { public function testRuleDoesNotApplyToCompactFunction() { $key = 'ok'; return compact('key'); } } testRuleDoesNotApplyToCookieSuperGlobal.php000077500000000000000000000012121360164303200346440ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToCookieSuperGlobal { function testRuleDoesNotApplyToCookieSuperGlobal() { return $_COOKIE; } } testRuleDoesNotApplyToDynamicProperty.php000077500000000000000000000012311360164303200344250ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToDynamicProperty { function testRuleDoesNotApplyToDynamicProperty() { $x = 'foo'; $this->$x = 42; } } testRuleDoesNotApplyToEnvSuperGlobal.php000077500000000000000000000012011360164303200341610ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToEnvSuperGlobal { function testRuleDoesNotApplyToEnvSuperGlobal() { return $_ENV; } } testRuleDoesNotApplyToFilesSuperGlobal.php000077500000000000000000000012071360164303200345010ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToFilesSuperGlobal { function testRuleDoesNotApplyToFilesSuperGlobal() { return $_FILES; } } testRuleDoesNotApplyToGetSuperGlobal.php000077500000000000000000000012011360164303200341500ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToGetSuperGlobal { function testRuleDoesNotApplyToGetSuperGlobal() { return $_GET; } } testRuleDoesNotApplyToGlobalsSuperGlobal.php000077500000000000000000000012141360164303200350200ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToGlobalsSuperGlobal { function testRuleDoesNotApplyToGlobalsSuperGlobal() { return $GLOBALS; } } testRuleDoesNotApplyToHttpRawPostDataSuperGlobal.php000077500000000000000000000012471360164303200364740ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToHttpRawPostDataSuperGlobal { function testRuleDoesNotApplyToHttpRawPostDataSuperGlobal() { return $HTTP_RAW_POST_DATA; } } testRuleDoesNotApplyToLocalVariableUsedAsArrayIndex.php000077500000000000000000000013501360164303200370720ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToLocalVariableUsedAsArrayIndex { public function testRuleDoesNotApplyToLocalVariableUsedAsArrayIndex() { foreach ($this->keys as $key) { self::$values[$key] = 42; } } } testRuleDoesNotApplyToLocalVariableUsedAsStringIndex.php000077500000000000000000000013541360164303200372660ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToLocalVariableUsedAsStringIndex { public function testRuleDoesNotApplyToLocalVariableUsedAsStringIndex() { foreach ($this->index as $idx) { self::$string{$idx} = 'a'; } } } testRuleDoesNotApplyToLocalVariableUsedInCompoundVariable.php000077500000000000000000000013631360164303200402650ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToLocalVariableUsedInCompoundVariable { protected static $foo = null; public function testRuleDoesNotApplyToLocalVariableUsedInCompoundVariable() { $bar = 'foo'; return self::${$bar}; } } testRuleDoesNotApplyToMethodArgument.php000077500000000000000000000012371360164303200342250ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToMethodArgument { public function testRuleDoesNotApplyToMethodArgument() { $foo = 42; $this->bar($foo); } } testRuleDoesNotApplyToNamespacedCompactFunction.php000077500000000000000000000013221360164303200363520ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; class testRuleDoesNotApplyToNamespacedCompactFunction { public function testRuleDoesNotApplyToNamespacedCompactFunction() { $key = 'ok'; return compact('key'); } } testRuleDoesNotApplyToPostSuperGlobal.php000077500000000000000000000012041360164303200343610ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToPostSuperGlobal { function testRuleDoesNotApplyToPostSuperGlobal() { return $_POST; } } testRuleDoesNotApplyToRequestSuperGlobal.php000077500000000000000000000012151360164303200350660ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToRequestSuperGlobal { function testRuleDoesNotApplyToRequestSuperGlobal() { return $_REQUEST; } } testRuleDoesNotApplyToServerSuperGlobal.php000077500000000000000000000012121360164303200347010ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToServerSuperGlobal { function testRuleDoesNotApplyToServerSuperGlobal() { return $_SERVER; } } testRuleDoesNotApplyToSessionSuperGlobal.php000077500000000000000000000012151360164303200350610ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToSessionSuperGlobal { function testRuleDoesNotApplyToSessionSuperGlobal() { return $_SESSION; } } testRuleDoesNotApplyToStaticArrayProperty.php000077500000000000000000000012741360164303200352760ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToStaticArrayProperty { protected static $a = array(); public function testRuleDoesNotApplyToStaticArrayProperty() { return self::$a[0]; } } testRuleDoesNotApplyToStaticObjectProperty.php000077500000000000000000000013041360164303200354200ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToStaticObjectProperty { protected static $c = null; public function testRuleDoesNotApplyToStaticObjectProperty() { return self::$c->getValue(); } } testRuleDoesNotApplyToStaticProperty.php000077500000000000000000000013121360164303200342700ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToStaticProperty { protected static $x = 42; public function testRuleDoesNotApplyToStaticProperty() { return testRuleDoesNotApplyToStaticProperty::$x; } } phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable/testRuleDoesNotApplyToThisVariable.php000077500000000000000000000012021360164303200337260ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToThisVariable { public function testRuleDoesNotApplyToThisVariable() { $this->foo; } } testRuleDoesNotApplyToUnusedForeachKeyWhenIgnored.php000077500000000000000000000013621360164303200366370ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToUnusedForeachKeyWhenIgnored { public function testRuleDoesNotApplyToUnusedForeachKeyWhenIgnored() { foreach ($this->index as $key => $value) { self::$string{$value} = 'a'; } } } testRuleDoesNotApplyToUnusedForeachKeyWhenWhitelisted.php000066400000000000000000000004021360164303200375240ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariableindex as $_ => $value) { self::$string{$value} = 'a'; } } } testRuleDoesNotApplyToUnusedForeachValueWhenIgnored.php000077500000000000000000000013641360164303200371650ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToUnusedForeachValueWhenIgnored { public function testRuleDoesNotApplyToUnusedForeachValueWhenIgnored() { foreach ($this->index as $key => $value) { self::$string{$key} = 'a'; } } } testRuleDoesNotApplyToUnusedLocalVariableInFunction.php000077500000000000000000000011401360164303200371540ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ function testRuleDoesNotApplyToUnusedLocalVariableInFunction() { static $bar; $bar = 42; } testRuleDoesNotApplyToUnusedLocalVariableInMethod.php000077500000000000000000000012621360164303200366140ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToUnusedLocalVariableInMethod { function testRuleDoesNotApplyToUnusedLocalVariableInMethod() { static $foo; return $foo++; } } testRuleDoesNotApplyToUnusedParameters.php000077500000000000000000000011721360164303200345670ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToUnusedParameters { function testRuleDoesNotApplyToUnusedParameters($x, $y, $z) { } } testRuleNotAppliesToPredefinedVariables.php000066400000000000000000000016151360164303200346720ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; class testRuleNotAppliesToPredefinedVariables { public function testRuleNotAppliesToPredefinedVariables() { $foo = 'bar'; $headers = array(); foreach ($http_response_header as $header) { $headers[] = $header; if (null !== $php_errormsg) { continue; } } return $headers; } } testRuleStillAppliesWhenSomeUnusedLocaleAreWhitelisted.php000066400000000000000000000002721360164303200377050ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedLocalVariable. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToUnusedPrivateField { private $foo = 0; } testRuleAppliesToUnusedPrivateStaticField.php000077500000000000000000000011121360164303200350760ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateField. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToUnusedPrivateStaticField { private static $_foo; } testRuleAppliesWhenFieldWithSameNameIsAccessedOnDifferentObject.php000077500000000000000000000012561360164303200412040ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateField. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesWhenFieldWithSameNameIsAccessedOnDifferentObject { private $foo = 42; public function __construct($object) { $object->foo = 23; } } testRuleAppliesWhenLocalVariableIsUsedInStaticMemberPrefix.php000077500000000000000000000014601360164303200402730ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateField. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesWhenLocalVariableIsUsedInStaticMemberPrefix { private static $_foo = 23; public static $foo = 17; public function bar() { self::${$_foo = 'foo'} = 42; } } $o = new testRuleAppliesWhenLocalVariableIsUsedInStaticMemberPrefix(); $o->bar(); var_dump($o::$foo); testRuleAppliesWhenStaticFieldWithSameNameIsAccessedOnDifferentClass.php000077500000000000000000000012551360164303200422120ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateField. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesWhenStaticFieldWithSameNameIsAccessedOnDifferentClass { private $foo = 23; public function __construct() { FooBar::$foo = 23; } } testRuleAppliesWhenStaticFieldWithSameNameIsAccessedOnParent.php000077500000000000000000000012651360164303200405500ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateField. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesWhenStaticFieldWithSameNameIsAccessedOnParent extends stdClass { private $foo = 23; public function __construct() { parent::$foo = 42; } } testRuleDoesNotApplyToClassNameAccessedPrivateField.php000077500000000000000000000013211360164303200367520ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateField. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToClassNameAccessedPrivateField { private static $_foo = 42; public function __construct() { testRuleDoesNotApplyToClassNameAccessedPrivateField::$_foo = 23; } } testRuleDoesNotApplyToFieldWithMethodsThatReturnArray.php000077500000000000000000000020661360164303200374040ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateField. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToFieldWithMethodsThatReturnArray { /** * @var mixed */ private $accountGateway; /** * @var mixed */ private $transactionGateway; /** * @param $slug * @return string * @link https://github.com/phpmd/phpmd/issues/324 */ public function testAction($slug) { $accountId = $this->accountGateway ->findBySlug($slug)['id']; $this->transactionGateway ->addTransaction($accountId, 'foo', 1234, '2015-11-07'); return 'Fine.'; } } testRuleDoesNotApplyToPrivateArrayFieldAccess.php000077500000000000000000000012271360164303200356560ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateField. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToPrivateArrayFieldAccess { private $foo = array(); private function bar() { return $this->foo[42]; } } testRuleDoesNotApplyToPrivateFieldInChainedMethodCall.php000077500000000000000000000013261360164303200372350ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateField. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToPrivateFieldInChainedMethodCall { /** * @var \SplObjectStorage */ private $foo = null; public function add($object) { $this->foo->attach($object); } } testRuleDoesNotApplyToPrivateStringIndexFieldAccess.php000077500000000000000000000012341360164303200370340ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateField. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToPrivateStringIndexFieldAccess { private $foo = "Manuel"; public function bar() { return $this->foo{3}; } } testRuleDoesNotApplyToSelfAccessedPrivateField.php000077500000000000000000000012361360164303200360020ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateField. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToSelfAccessedPrivateField { private static $_foo = 42; public function __construct() { self::$_foo = 23; } } testRuleDoesNotApplyToStaticAccessedPrivateField.php000077500000000000000000000012421360164303200363350ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateField. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToStaticAccessedPrivateField { private static $_foo = 23; public function __construct() { static::$_foo = 42; } } testRuleDoesNotApplyToThisAccessedPrivateField.php000077500000000000000000000012241360164303200360150ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateField. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToThisAccessedPrivateField { private $foo = 42; public function __construct() { $this->foo = 23; } } testRuleDoesNotApplyToUnusedProtectedField.php000077500000000000000000000011121360164303200352310ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateField. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToUnusedProtectedField { protected $foo = 23; } testRuleDoesNotApplyToUnusedPublicField.php000077500000000000000000000011041360164303200345170ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateField. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToUnusedPublicField { public $foo = 42; } testRuleDoesNotResultInFatalErrorByCallingNonObject.php000077500000000000000000000012321360164303200367600ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateField. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotResultInFatalErrorByCallingNonObject { private $foo = null; public function bar() { return self::${'_bar'}; } } phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateMethod/000077500000000000000000000000001360164303200243605ustar00rootroot00000000000000testRuleAppliesToParentReferencedUnusedPrivateMethod.php000077500000000000000000000013021360164303200374560ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateMethod. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToParentReferencedUnusedPrivateMethod extends stdClass { private static function foo() { } public function __construct() { parent::foo(); } } testRuleAppliesToUnusedPrivateMethod.php000077500000000000000000000011231360164303200343220ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateMethod. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToUnusedPrivateMethod { private function foo() { } } testRuleAppliesToUnusedStaticPrivateMethod.php000077500000000000000000000011401360164303200354710ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateMethod. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesToUnusedStaticPrivateMethod { private static function foo() { } } testRuleAppliesWhenMethodIsReferencedOnDifferentClass.php000077500000000000000000000012541360164303200375200ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateMethod. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesWhenMethodIsReferencedOnDifferentClass { private static function foo() { } public function bar() { FooBarBaz::foo(); } } testRuleAppliesWhenMethodIsReferencedOnDifferentObject.php000077500000000000000000000012531360164303200376600ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateMethod. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesWhenMethodIsReferencedOnDifferentObject { private function foo() { } public function bar($object) { $object->foo(); } } testRuleAppliesWhenMethodWithSimilarNameIsInInvocationChain.php000077500000000000000000000014221360164303200406620ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateMethod. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesWhenMethodWithSimilarNameIsInInvocationChain { /** * @var \SplObjectStorage */ protected $storage = null; public function run() { $this->storage->attach($object); } private function attach($object) { } } testRuleAppliesWhenPropertyWithSimilarNameIsReferenced.php000077500000000000000000000012451360164303200377700ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateMethod. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleAppliesWhenPropertyWithSimilarNameIsReferenced { private function foo() { } public function bar() { $this->foo = 42; } } testRuleDoesNotApplyToClassNameReferencedMethod.php000077500000000000000000000013231360164303200363430ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateMethod. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToClassNameReferencedMethod { private static function foo() { } public static function bar() { TestRuleDoesNotApplyToClassNameReferencedMethod::foo(); } } testRuleDoesNotApplyToPrivateCloneMethod.php000077500000000000000000000011341360164303200351050ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateMethod. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToPrivateCloneMethod { private function __clone() { } } testRuleDoesNotApplyToPrivateConstructor.php000077500000000000000000000011371360164303200352340ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateMethod. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToPrivateConstructor { private function __construct() { } } testRuleDoesNotApplyToPrivateMethodInChainedMethodCall.php000077500000000000000000000013501360164303200376240ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateMethod. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToPrivateMethodInChainedMethodCall { private function bar() { return new \SplObjectStorage(); } public function add($object) { return $this->bar()->attach($object); } } testRuleDoesNotApplyToPrivateMethodInChainedMethodCallInNumberBiggerThanTwo.php000066400000000000000000000027631360164303200437170ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateMethod. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ namespace PHPMDTest; /** * @link https://github.com/phpmd/phpmd/issues/110 */ class testRuleDoesNotApplyToPrivateMethodInChainedMethodCallInNumberBiggerThanTwo { public function foo() { $this ->bar() ->baz() ->baw(); } public function abc() { $this ->bar() ->baz(); $this->baw(); } public function xyz() { $this ->bar() ->baz() ->baw() ->bar() ->baz() ->baw() ->bar() ->baz() ->baw(); } /** * @return $this */ private function bar() { // Do some stuff ... return $this; } /** * @return $this */ private function baz() { // Do some stuff ... return $this; } /** * @return $this */ private function baw() { // Do some stuff ... return $this; } } testRuleDoesNotApplyToPrivatePhp4Constructor.php000077500000000000000000000012041360164303200357630ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateMethod. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToPrivatePhp4Constructor { private function testRuleDoesNotApplyToPrivatePhp4Constructor() { } } testRuleDoesNotApplyToSelfReferencedMethod.php000077500000000000000000000012341360164303200353670ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateMethod. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToSelfReferencedMethod { private static function foo() { } public function bar() { self::foo(); } } testRuleDoesNotApplyToStaticReferencedMethod.php000077500000000000000000000012471360164303200357310ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateMethod. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToStaticReferencedMethod { private static function foo() { } public static function bar() { static::foo(); } } testRuleDoesNotApplyToThisReferencedMethod.php000077500000000000000000000012311360164303200354020ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/Rule/UnusedPrivateMethod. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ class testRuleDoesNotApplyToThisReferencedMethod { private function foo() { } protected function bar() { $this->foo(); } } phpmd-2.8.1/src/test/resources/files/RuleSet/000077500000000000000000000000001360164303200210755ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/RuleSet/testApplyInvokesRuleWhenStrictModeIsSet.php000077500000000000000000000011231360164303200315520ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ /** * @SuppressWarnings(PHPMD) */ class testApplyInvokesRuleWhenStrictModeIsSet { } phpmd-2.8.1/src/test/resources/files/RuleSet/testApplyNotInvokesRuleWhenSuppressAnnotationExists.php000077500000000000000000000011371360164303200342720ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ /** * @SuppressWarnings(PHPMD) */ class testApplyNotInvokesRuleWhenSuppressAnnotationExists { } phpmd-2.8.1/src/test/resources/files/TextUI/000077500000000000000000000000001360164303200206745ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/TextUI/CommandLineOptions/000077500000000000000000000000001360164303200244365ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/TextUI/CommandLineOptions/inputfile.txt000077500000000000000000000000371360164303200272010ustar00rootroot00000000000000Dir1/Class1.php Dir2/Class2.phpphpmd-2.8.1/src/test/resources/files/classes/000077500000000000000000000000001360164303200211475ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/classes/does_not_follow_psr0.class.php000066400000000000000000000016671360164303200271360ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ /** * Some class that stands as an example for classes not following PSR-0. * * @author Gerrit Addiks */ class some_class_that_does_not_follow_psr0 extends \PHPMD\AbstractRule{ /** * A method that returns foo, bar and baz. * * @return string */ public function getFooBarBaz(){ return array('foo', 'bar', 'baz'); } public function apply(\PHPMD\AbstractNode $node){ } } phpmd-2.8.1/src/test/resources/files/pdepend.xml.dist000077500000000000000000000013521360164303200226210ustar00rootroot00000000000000 Arial 12 memory phpmd-2.8.1/src/test/resources/files/pmd/000077500000000000000000000000001360164303200202725ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/pmd/default-xml.xml000077500000000000000000000010301360164303200232330ustar00rootroot00000000000000 The function ccn_function() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10. phpmd-2.8.1/src/test/resources/files/pmd/single-directory.xml000077500000000000000000000034241360164303200243050ustar00rootroot00000000000000 The function ccn_function() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10. The method doSomething() has an NPath complexity of 80. The configured NPath complexity threshold is 50. The method doSomething() has a Cyclomatic Complexity of 25. The configured cyclomatic complexity threshold is 10. The method doSomething() has an NPath complexity of 50000. The configured NPath complexity threshold is 50. phpmd-2.8.1/src/test/resources/files/pmd/single-file.xml000077500000000000000000000010301360164303200232070ustar00rootroot00000000000000 The function ccn_function() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10. phpmd-2.8.1/src/test/resources/files/renderer/000077500000000000000000000000001360164303200213205ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/renderer/json_renderer_expected.json000066400000000000000000000035131360164303200267350ustar00rootroot00000000000000{ "version": "@package_version@", "package": "phpmd", "timestamp": "", "files": [ { "file": "\/bar.php", "violations": [ { "beginLine": 23, "endLine": 42, "package": "TestStubPackage", "function": null, "class": null, "method": null, "rule": "RuleStub", "ruleSet": "TestRuleSet", "description": "Test description", "externalInfoUrl": "https:\/\/phpmd.org\/rules\/index.html", "priority": 5 }, { "beginLine": 23, "endLine": 42, "package": "TestStubPackage", "function": null, "class": null, "method": null, "rule": "RuleStub", "ruleSet": "TestRuleSet", "description": "Test description", "externalInfoUrl": "https:\/\/phpmd.org\/rules\/index.html", "priority": 5 } ] }, { "file": "\/foo.php", "violations": [ { "beginLine": 23, "endLine": 42, "package": "TestStubPackage", "function": null, "class": null, "method": null, "rule": "RuleStub", "ruleSet": "TestRuleSet", "description": "Test description", "externalInfoUrl": "https:\/\/phpmd.org\/rules\/index.html", "priority": 5 } ] } ] } phpmd-2.8.1/src/test/resources/files/renderer/json_renderer_processing_errors.json000066400000000000000000000012371360164303200307050ustar00rootroot00000000000000{ "version": "@package_version@", "package": "phpmd", "timestamp": "", "files": [], "errors": [ { "fileName": "\/tmp\/foo.php", "message": "Failed for file \u0022\/tmp\/foo.php\u0022." }, { "fileName": "\/tmp\/bar.php", "message": "Failed for file \u0022\/tmp\/bar.php\u0022." }, { "fileName": "\/tmp\/baz.php", "message": "Failed for file \u0022\/tmp\/baz.php\u0022." }, { "fileName": "\/tmp\/foo.php", "message": "Cannot read file \u0022\/tmp\/foo.php\u0022. Permission denied." } ] } phpmd-2.8.1/src/test/resources/files/renderer/xml_renderer_expected1.xml000077500000000000000000000014441360164303200265000ustar00rootroot00000000000000 Test description Test description foo <?php bar phpmd-2.8.1/src/test/resources/files/renderer/xml_renderer_processing_errors.xml000077500000000000000000000005311360164303200303620ustar00rootroot00000000000000 phpmd-2.8.1/src/test/resources/files/rulesets/000077500000000000000000000000001360164303200213605ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/rulesets/alternative-property-value-syntax.xml000077500000000000000000000015421360164303200307450ustar00rootroot00000000000000 First description... ... 3 42 phpmd-2.8.1/src/test/resources/files/rulesets/exclude-pattern.xml000077500000000000000000000015051360164303200252120ustar00rootroot00000000000000 Test exclude-pattern ... 3 testCreateRuleWithExcludePattern some/excluded/files phpmd-2.8.1/src/test/resources/files/rulesets/pmd-refset1.xml000077500000000000000000000012211360164303200242300ustar00rootroot00000000000000 First description... phpmd-2.8.1/src/test/resources/files/rulesets/refset-exclude-all.xml000077500000000000000000000013211360164303200255670ustar00rootroot00000000000000 First description... phpmd-2.8.1/src/test/resources/files/rulesets/refset-exclude-one.xml000077500000000000000000000012351360164303200256040ustar00rootroot00000000000000 First description... phpmd-2.8.1/src/test/resources/files/rulesets/refset1.xml000077500000000000000000000007771360164303200234710ustar00rootroot00000000000000 First description... phpmd-2.8.1/src/test/resources/files/rulesets/refset2.xml000077500000000000000000000010551360164303200234600ustar00rootroot00000000000000 First description... phpmd-2.8.1/src/test/resources/files/rulesets/refset3.xml000077500000000000000000000013621360164303200234620ustar00rootroot00000000000000 First description... 4 description 42 phpmd-2.8.1/src/test/resources/files/rulesets/refset4.xml000077500000000000000000000012001360164303200234520ustar00rootroot00000000000000 First description... phpmd-2.8.1/src/test/resources/files/rulesets/ruleset-refs.xml000066400000000000000000000022701360164303200245230ustar00rootroot00000000000000 First description... /foo/bar/baz 1 phpmd-2.8.1/src/test/resources/files/rulesets/set-class-file-not-found.xml000077500000000000000000000012141360164303200266250ustar00rootroot00000000000000 First description... phpmd-2.8.1/src/test/resources/files/rulesets/set-class-not-found.xml000077500000000000000000000011771360164303200257200ustar00rootroot00000000000000 First description... phpmd-2.8.1/src/test/resources/files/rulesets/set-invalid-xml.xml000077500000000000000000000001151360164303200251170ustar00rootroot00000000000000 phpmd-2.8.1/src/test/resources/files/rulesets/set1.xml000077500000000000000000000020561360164303200227640ustar00rootroot00000000000000 First description... ... 3 testCreateRuleWithExpectedExample ... 1 phpmd-2.8.1/src/test/resources/files/rulesets/set2.xml000077500000000000000000000022141360164303200227610ustar00rootroot00000000000000 Second description... ... 1 testCreateRuleWithExpectedMultipleExamplesOne testCreateRuleWithExpectedMultipleExamplesTwo ... 5 phpmd-2.8.1/src/test/resources/files/source/000077500000000000000000000000001360164303200210125ustar00rootroot00000000000000phpmd-2.8.1/src/test/resources/files/source/ccn_function.php000077500000000000000000000025251360164303200242020ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ /** * Test function with a high cyclomatic complexity */ function ccn_function($arg) { switch ($arg) { case 1: for ($i = 0; $i < 10; ++$i) { if ($i % 2 === 0) { if ($arg - $i < 0) { echo "foo"; } } } break; case 2: while (true) { if (time() % 5 === 0 && time() % 2 === 0) { break; } else { if (time() % 7 === 0) { $x = true; for ($i = 0; $i < 42; ++$i) { $x = $x || true; } return $x; } } return 23; } break; } } phpmd-2.8.1/src/test/resources/files/source/ccn_suppress_function.php000066400000000000000000000026111360164303200261370ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ /** * Test function with a high cyclomatic complexity * * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ function ccn_function($arg) { switch ($arg) { case 1: for ($i = 0; $i < 10; ++$i) { if ($i % 2 === 0) { if ($arg - $i < 0) { echo "foo"; } } } break; case 2: while (true) { if (time() % 5 === 0 && time() % 2 === 0) { break; } else { if (time() % 7 === 0) { $x = true; for ($i = 0; $i < 42; ++$i) { $x = $x || true; } return $x; } } return 23; } break; } } phpmd-2.8.1/src/test/resources/files/source/npath_method.php4000077500000000000000000000014031360164303200242620ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ /** * Simple test class */ class NPathClass { function doSomething() { if (true) { } if (true) { } if (true) { } if (true) { } if (true && true && true && true) { } } } phpmd-2.8.1/src/test/resources/files/source/source_with_npath_violation.php000077500000000000000000000016131360164303200273400ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ /** * Simple test class */ class NPathClass { function doSomething() { if (true) {} if (true) {} if (true) {} if (true) {} if (true && true && true && true) {} if (true && true && true && true) {} if (true && true && true && true) {} if (true && true && true && true) {} if (true && true && true && true) {} } } phpmd-2.8.1/src/test/resources/files/source/source_without_violations.php000077500000000000000000000012751360164303200270650ustar00rootroot00000000000000. * All rights reserved. * * Licensed under BSD License * For full copyright and license information, please see the LICENSE file. * Redistributions of files must retain the above copyright notice. * * @author Manuel Pichler * @copyright Manuel Pichler. All rights reserved. * @license https://opensource.org/licenses/bsd-license.php BSD License * @link http://phpmd.org/ */ /** * Simple test class */ class SourceWithoutViolations { function doSomething() { if (time() % 42 === 0) { return 'foo'; } return 'bar'; } }