vikiru / CodeSmell

A tool for detection and visualization of code smells for object-oriented languages.
https://vikiru.github.io/CodeSmell/jfx/module-summary.html
MIT License
4 stars 0 forks source link

Add shotgun surgery, update feature envy, add abstract class tester. #56

Closed martin509 closed 1 year ago

martin509 commented 1 year ago

This PR covers three main things. In order of importance:

Shotgun Surgery

Shotgun surgery is detected in this case by keeping track of both how many methods a given method calls, as well as how many actual classes a method calls. The reasoning behind this is that if, in order to change a method's functionality, we need to change everything that method may use, then a method that uses, say, five or six or more separate files to define itself is a method that is very difficult to modify in a centralized way. This article has more details and forms the basis for me using this method. Currently, we check for methods that call at least 5 other classes and at least ten other methods. These are more or less arbitrary figures and subject to change. Currently the method is incapable of finding calls to methods within the same class as the method.

Feature Envy

I spent some time trying to clean up the behavior of the feature envy smell. In bullet point form:

Smell Tester Class

This came while writing the test file for Shotgun Surgery. I already had a macro defined in FeatureEnvyTest for returning whether or not a given class was detected in the CPG, and expanded on that a bit and made FeatureEnvyTest and ShotgunSurgeryTest both inherit from an abstract 'SmellTester' class.