PhpMetrics icon indicating copy to clipboard operation
PhpMetrics copied to clipboard

configuration file

Open StephanKrauss opened this issue 8 years ago • 8 comments

Hello,

in the moment i test PhpMetrics. I use PhpStorm with the PhpMetrics - Plugin. I will write my own config file for PhpMetrics. For example i have a ' .phpmetrics.yml ' file under the document root of my project.

I will change the measure for the maintainability index. --------------------- .phpmetrics.yml ----

default: rules: cyclomaticComplexity: [ 10, 6, 2 ] maintainabilityIndex: [ 0, 95, 99 ]

failure: average.maintainabilityIndex < 50 or sum.loc > 10000

path:
    directory: src
    extensions: php
    exclude: features|tests

logging:
    report:
        xml:    ./_log/phpmetrics.xml
        html:   ./_log/phpmetrics.html
        csv:    ./_log/phpmetrics.csv
    violations:
        xml:    ./_log/violations.xml
    chart:
        bubbles: ./_log/bubbles.svg

It does not work !

Where can I find the default settings?

Your sincerly

Stephan

StephanKrauss avatar Jan 28 '17 16:01 StephanKrauss

Hi,

v2 does not support configuration files yet. Do you use PhpMetrics v2 ?

Halleck45 avatar Apr 10 '17 11:04 Halleck45

Hi Halleck,

Same problem here, i want to block a CI if class / method are too complex, and .phpmetrics respond well for this job :) did you know when we can use this feature for v2 ? :)

Thanks for all your awesome job :+1:

cbastienbaron avatar Jun 20 '17 06:06 cbastienbaron

Added support for passing configuration options via config files instead of command line for now in #303

FractalizeR avatar Sep 14 '17 14:09 FractalizeR

so the ".phpmetrics.yml" is not valid anymore? Is there a example for a ".phpmetrics.json" config?

I don't know if this config is 100% correct, but this is what I have found in the code: ".phpmetrics.json"

{
  "extensions": [
    "php"
  ],
  "exclude": [
    "infra",
    "tests",
    "composer",
    "archiv",
    "vendor",
    "thirdparty",
    "generated",
    "tmp"
  ],
  "report-xml": "./build/report/phpmetrics.xml",
  "report-html": "./build/report/phpmetrics.html",
  "report-csv": "./build/report/phpmetrics.csv"
}
phpmetrics.phar --config="build/.phpmetrics.json" src/bar,src/foo

voku avatar Aug 13 '18 18:08 voku

Examples are in the commit: https://github.com/phpmetrics/PhpMetrics/pull/303/commits/7bebaba683dad4710b720f4f63ed52c971cc06cb#diff-713f164f2a0941b2e1b0bff3a95b0256

FractalizeR avatar Aug 15 '18 05:08 FractalizeR

@FractalizeR but in this example I see "exclude" as string but in the code it will expect an array (https://github.com/phpmetrics/PhpMetrics/blob/master/src/Hal/Component/File/Finder.php#L55) ... also in the example there is only the html- and the exclude-option, are this the only valid options?

voku avatar Aug 15 '18 09:08 voku

ok, if some finds this e.g. via google (phpmetrics +exclude)

-> this is working: https://github.com/phpmetrics/PhpMetrics/blob/1a3c100891fe60e401fb0b2c136a689eecb398c3/src/Hal/Application/Config/Validator.php#L33

{
  "extensions": [
    "php"
  ],
  "exclude": "infra,tests,composer,archiv,vendor,thirdparty,generated,tmp",
  "report-xml": "./build/report/phpmetrics.xml",
  "report-html": "./build/report/phpmetrics.html",
  "report-csv": "./build/report/phpmetrics.csv"
}

voku avatar May 18 '19 00:05 voku

What about failure configuration? I want to stop jenkins when a specific metric fails, i didnt find nothing about it in .json configuration files, only in yml. It is still possible?

jleonardolemos avatar Aug 28 '20 14:08 jleonardolemos

What about failure configuration? I want to stop jenkins when a specific metric fails, i didnt find nothing about it in .json configuration files, only in yml. It is still possible?

There is now a way to to that.

For instance, this configuration makes fail PhpMetrics in case of any class having a too low Maintainability Index (60, for instance):

{
  "searches": {
    "Unacceptable Maintainability Index": {
      "type": "class",
      "mi": "<60",
      "failIfFound": true
    }
  }
}

Tested on v3.0.0-rc4 and working as expected.

I'm closing the issue as original question was irrelevant (asking for a configuration file when PhpMetrics wasn't able to manage some yet) and derivated questions are now answered. If you want to ask something new related, please open a new issue.

niconoe- avatar Sep 22 '23 06:09 niconoe-