kisstkondoros / codemetrics

VSCode extension which shows the complexity information for TypeScript class members
Other
402 stars 20 forks source link

Question: Why does method reference add complexity to a method? #82

Closed vivekmore closed 3 years ago

vivekmore commented 4 years ago
    private List<String> myMethod1(String s1, String s2) {
        List<String> list = new ArrayList<>();
        if (s1 != null) list.add(s1.toLowerCase());
        if (s2 != null) list.add(s2.toLowerCase());
        return list;
    }

    private List<String> myMethod2(String s1, String s2) {
        List<String> list = new ArrayList<>();
        Optional.ofNullable(s1).map(String::toLowerCase).ifPresent(list::add);
        Optional.ofNullable(s2).map(String::toLowerCase).ifPresent(list::add);
        return list;
    }

these methods should not have same complexity score

kisstkondoros commented 3 years ago

Thanks for raising an issue, in the wrong repo though :sweat_smile:

My explanation for this (wrong behavior) would be

  1. 2 if clauses, 2 boolean conditions, no method declarations +4
  2. 4 method references +4

Whether this is good or bad is up to interpretation (and configuration), you can fine tune it in the settings.

If you have a more concrete recommendation about this, please file a new issue in the correct repo (https://github.com/kisstkondoros/codemetrics-idea)