phpmetrics / PhpMetrics

Beautiful and understandable static analysis tool for PHP
https://phpmetrics.github.io/website/
MIT License
2.48k stars 259 forks source link

Response for a class (RFC) measure #496

Open andrii-pukhalevych opened 1 year ago

andrii-pukhalevych commented 1 year ago

Feature request

Is it possible to add Response for a class (RFC) measure?

andrii-pukhalevych commented 1 year ago

@niconoe- what is better visitor class to add RFC metric? I will do PR for it.

Response for a class (RFC) is a number of methods in class + number of unique method calls from another classes.

The metric called the response for a class (RFC) measures the number of different methods that can be executed when an object of that class receives a message (when a method is invoked for that object). Ideally, we would want to find for each method of the class, the methods that class will call, and repeat this for each called method, calculating what is called the transitive closure of the method's call graph. This process can however be both expensive and quite inaccurate. In ckjm, we calculate a rough approximation to the response set by simply inspecting method calls within the class's method bodies. The value of RFC is the sum of number of methods called within the class's method bodies and the number of class's methods. This simplification was also used in the 1994 Chidamber and Kemerer description of the metrics.

niconoe- commented 1 year ago

Well, it looks like a structural metric at class level, so I guess in Hal/Metric/Class_/Structural/ you could add a new visitor.

This metric should definitly be part of PhpMetrics, so thank you for including it :wink: .

Please start from the 3.x-dev branch as it shouldn't be part of master yet, and this metric should be availble in the next incoming version.