PHPMD configuration

PHPMD requires configuration via a codesize.xml configuration file as detailed in PHPMD's documentation.

If you don't specify your custom configuration file we use our default below. We suggest to add your own configuration file into your repository root directory to be able to specify your coding and quality standards.

codesize.xml

<ruleset name="phpmd"
         xmlns="http://pmd.sf.net/ruleset/1.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
         xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
    <description>PHPMD Rules</description>

    <rule ref="rulesets/cleancode.xml" />
    <rule ref="rulesets/codesize.xml" />
    <rule ref="rulesets/design.xml" />
    <rule ref="rulesets/controversial.xml" />
    <rule ref="rulesets/unusedcode.xml" />
    <rule ref="rulesets/naming.xml" />
</ruleset>

Ignoring files

Storing generated or third party code in your repository is in general not a good idea. However, sometimes you really need to do this and Codeac got you covered. Usually you don't want to analyze those files so you can place .codesizeignore file to the root folder of your repository. This file can contain regular expressions that are matched with paths in your project and excluded from the analysis. The syntax is identical with popular gitignore format.

Take a look on this simple example with Composer and Protocol Buffers:

.codesizeignore

# 3rd party libraries
vendor
composer.phar

# Protocol Buffers
app/protobuff

If you are dealing with any special type of project structure, please, let us know. We are happy to help you.

Cyclomatic Complexity Example

In its simplest form, Cyclomatic Complexity in PHP is a count of the number of decisions in the source code. The higher the count, the more complex the code.

PHP Cyclomatic complexity