Skip to content

Latest commit

 

History

History
26 lines (18 loc) · 1.16 KB

Control-Couple.md

File metadata and controls

26 lines (18 loc) · 1.16 KB

Control Couple

Introduction

Control coupling occurs when a method or block checks the value of a parameter in order to decide which execution path to take. The offending parameter is often called a Control Couple.

Control Coupling is a kind of duplication, because the calling method already knows which path should be taken.

Control Coupling reduces the code's flexibility by creating a dependency between the caller and callee: any change to the possible values of the controlling parameter must be reflected on both sides of the call. A Control Couple also reveals a loss of simplicity: the called method probably has more than one responsibility, because it includes at least two different code paths.

You can find a good write-up regarding this problem here.

Current Support in Reek

Reek performs the following checks that fall in this category:

  • Control-Parameter - a method parameter or block parameter is the tested value in a conditional statement
  • Boolean-Parameter - a method parameter is defaulted to true or false.