Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

configuration file #256

Closed
StephanKrauss opened this issue Jan 28, 2017 · 9 comments
Closed

configuration file #256

StephanKrauss opened this issue Jan 28, 2017 · 9 comments

Comments

@StephanKrauss
Copy link

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

@Halleck45
Copy link
Collaborator

Hi,

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

@cbastienbaron
Copy link

cbastienbaron commented Jun 20, 2017

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 👍

@FractalizeR
Copy link
Contributor

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

@voku
Copy link

voku commented Aug 13, 2018

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

@FractalizeR
Copy link
Contributor

Examples are in the commit: 7bebaba#diff-713f164f2a0941b2e1b0bff3a95b0256

@voku
Copy link

voku commented Aug 15, 2018

@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
Copy link

voku commented May 18, 2019

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

-> this is working:

if (!$config->has('exclude')) {

{
  "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"
}

@jleonardolemos
Copy link

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?

@niconoe-
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants